/*************************************************************************
  program: 	beps.h
  Description:  Header file for defining constants and global variables
  ----------    for BEPS program

***************************************************************************
  CCRS (EMS/Applications Division)
  Wrintten by: 	J. Liu
  Last update:  December 2000
*****************************************************************************/

#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<malloc.h>

/* Define Constants */
#define NOERROR		0
#define ERROR		1
#define PI		3.1415926
//#define max(a,b) 	(a>b)?a:b
//#define min(a,b)	(a<b)?a:b

//#define NPIX_CAN	120
//#define NLIN_CAN	100

#define SIZEB		101
#define SIZEG 		101
#define SIZEX 		20
#define SIZEZ 		50

#define RTIMES 		1
#define RPERIOD 	3600	/* in sec */

void readconf();
void readb_init();
void readlonlat();
void readindex();
void readlc();
void readawc();
void readsnow();
void readbm();
void readlai();
void readclim();
void readb();
void model();

void setx();

void zeroxx();
void readxx();
void writexx();

void zcomp();
void doflux();

void inter();
void melt();
void ra();
void rs();
void rsoil();
void carbon();
void soilresp();
 
int net_longwave();
int net_shortwave();
int farq_psn();
int rad_ssl();

double penman();

void display();

/* Declare structures */
struct climatedata
	{
	int long pix;
	double tmax;
	double tmin;
	double dewp;
	double srad;
	double frad;
	double precip;
	};

struct xvalue
	{
	int long pix;
	double x1;		/* snow pack */
	double x2;		/* soil water */
	double x3;		/* out flow */
	double x4;		/* transpiration */
	double x5;		/* evaporation */
	double x6;		/* photosynthesis */
	double x7;		/* Rm */
	double x8;		/* leaf C */
	double x9;		/* stem C */
	double x10;		/* root C */
	double x11;		/* GPP */	
	double x12;		/* ResSoil */
	double x13;		/* NEP */
	double x14;		/* M Res leaf */
	double x15;		/* M Res stem */
	double x16;		/* M Res root */
	double x17;		/* Number of days with rain */
	double x18;		/* understory Trans */
	};

/*	Declare global variables */
char awcf[255];         /* Available water holding capacity file */
char biomassf[255];     /* Biomass data file */
char landcoverf[255];   /* Land cover file */
char leafareaf[255];    /* Leaf area index file */
char snowpackf[255];    /* Snow pack data file */
char lonf[255];         /* longitude file */
char latf[255];         /* latitude file */
char radf[255];    /* radiation data file */
char tmxf[255];    /* max. temperature data file */
char tmif[255];    /* min. temperature data file */
char humf[255];      /* Humidity data file */
char prcf[255];     /* prencipitation data file */
int long cycle_display;
int long jday_start;    /* Julian day start */
int long jday_end;      /* Julian day end */
int long lin_offset;    /* Line offset (pci coord. system) */
int long nlines;        /* Number of lines in study area */
int long npixels;       /* Number of pixels in study area */
//int long pix_offset;    /* Pixel offset (pci coord. system) */
 
float factor;
char outp_path[90];
char outf_name[255];
char output_NPP;
char output_GPP;
char output_NEP;
char output_ET;
char output_site;

double *z;