/*************************************************************************
  Program:     readconf.c
  --------
  Description:
  -----------
  Reads control file for NPP calculations.  The control file
  defines the area in which NPP will be calulated and the data
  files used in the calculations.

***************************************************************************
  CCRS (EMS/Applications Division)
  Written by:	D. Fraser/J. Liu  
  Modified for application to China  by:  Gang Mo
  Last update:	Spet. 2008
*****************************************************************************/
#include <stdio.h>
#include "beps.h"

void readconf(conf,rcode)
char *conf;		/* control file name */
int *rcode;		/* Return code */
{

	char field_descr[255];	/* Field description in control file */
	FILE *fcon;		/* Control file pointer */

/*      If can not open control parameter file */
        if ((fcon = fopen(conf,"r")) == NULL) {
          printf("Can not open parameter file <%s>, exitting program ...\n",
                                                                conf);
          *rcode = ERROR;
	  return;
        }

/*	Read control file parameters */
    field_descr[0]='\0';
    fscanf(fcon,"%s %d", field_descr, &jday_start);
    field_descr[0]='\0';
    fscanf(fcon,"%s %d", field_descr, &jday_end);
    field_descr[0]='\0';
	fscanf(fcon,"%s %d", field_descr, &nlines);
    field_descr[0]='\0';
	fscanf(fcon,"%s %d", field_descr, &npixels);
	field_descr[0]=awcf[0]='\0';
	fscanf(fcon,"%s %s", field_descr, awcf);
	field_descr[0]=biomassf[0]='\0';
	fscanf(fcon,"%s %s", field_descr, biomassf);
	field_descr[0]=landcoverf[0]='\0';
	fscanf(fcon,"%s %s", field_descr, landcoverf);
	field_descr[0]=leafareaf[0]='\0';
	fscanf(fcon,"%s %s", field_descr, leafareaf);
	field_descr[0]=snowpackf[0]='\0';
	fscanf(fcon,"%s %s", field_descr, snowpackf);
	field_descr[0]=lonf[0]='\0';
	fscanf(fcon,"%s %s", field_descr, lonf);
	field_descr[0]=latf[0]='\0';
	fscanf(fcon,"%s %s", field_descr, latf);
	field_descr[0]=radf[0]='\0';
	fscanf(fcon,"%s %s", field_descr, radf);
	field_descr[0]=tmxf[0]='\0';
	fscanf(fcon,"%s %s", field_descr, tmxf);
	field_descr[0]=tmif[0]='\0';
	fscanf(fcon,"%s %s", field_descr, tmif);
	field_descr[0]=humf[0]='\0';
	fscanf(fcon,"%s %s", field_descr, humf);
	field_descr[0]=prcf[0]='\0';
	fscanf(fcon,"%s %s", field_descr, prcf);
	field_descr[0]=outp_path[0]='\0';
	fscanf(fcon,"%s %s", field_descr, outp_path);

	field_descr[0]='\0'; 
	fscanf(fcon,"%s %c", field_descr, &output_GPP);	
	field_descr[0]='\0'; 
	fscanf(fcon,"%s %c", field_descr, &output_NPP);
	field_descr[0]='\0';
	fscanf(fcon,"%s %c", field_descr, &output_NEP);	
	field_descr[0]='\0';
	fscanf(fcon,"%s %c", field_descr, &output_ET);
	field_descr[0]='\0';
	fscanf(fcon,"%s %c", field_descr, &output_site);

	
/*	Output control parameters */
printf("\n Control Parameters\n\n");
printf(" Julian day_start [1,365]: %d\n",jday_start);
printf(" Julian day_end [1,365]: %d\n",jday_end);
printf(" Number of Line: %d\n",nlines);
printf(" Number of pixel: %d\n",npixels);
printf(" Available Water Capacity file:  %s\n",awcf);
printf(" Biomass data file:  %s\n",biomassf);
printf(" Land cover data file:  %s\n",landcoverf);
printf(" LAI data file:  %s\n",leafareaf);
printf(" Snowpack data file:  %s\n",snowpackf);
printf(" longitude data file:  %s\n",lonf);
printf(" latitude file:  %s\n",latf);
printf(" radiation data file:  %s\n",radf);
printf(" max.temperature data file:  %s\n",tmxf);
printf(" min.temperature data file:  %s\n",tmif);
printf(" Humidity data file:  %s\n",humf);
printf(" Precipitation data file:  %s\n",prcf);

printf(" Output path:  %s\n",outp_path);
printf(" Output GPP?  %c\n",output_GPP);
printf(" Output NPP?  %c\n",output_NPP);
printf(" Output NEP?  %c\n",output_NEP);
printf(" Output evp-transpiration?  %c\n",output_ET); 
printf(" Output site file?  %c\n",output_site); 

fclose(fcon);

}



