📄 get_global_param.c
字号:
#include <stdio.h>
#include <stdlib.h>
#include <vicNl.h>
#include <string.h>
static char vcid[] = "$Id: get_global_param.c,v 4.2.2.5 2004/05/10 20:13:06 tbohn Exp $";
/********************************************************************/
/* GLOBAL VARIABLES */
/********************************************************************/
int NR; /* array index for atmos struct that indicates
the model step avarage or sum */
int NF; /* array index loop counter limit for atmos
struct that indicates the SNOW_STEP values */
global_param_struct get_global_param(filenames_struct *names,
FILE *gp)
/**********************************************************************
get_global_param Keith Cherkauer March 1998
This routine reads the VIC model global control file, getting
values for global parameters, model options, and debugging controls.
Modifications:
7-19-96 Modified to read time step KAC
4-5-98 Modified to read model options and debugging
controls from a single file KAC
01-20-00 modified to work with new radiation estimation routines,
new simplified frozen soil moisture, and new new open
format forcing file rad routines. KAC
06-03-03 modified to handle both ASCII and BINARY state files. KAC
09-02-2003 Moved COMPUTE_TREELINE flag from user_def.h to the
options structure. Now when not set to FALSE, the
value indicates the default above treeline vegetation
if no usable vegetation types are in the grid cell
(i.e. everything has a canopy). A negative value
will cause the model to use bare soil. Make sure that
positive index value refer to a non-canopied vegetation
type in the vegetation library. KAC
10-Oct-03 Modified to understand the ARNO_PARAMS option. TJB
10-May-04 Modified to display compile-time and run-time options
if VERBOSE is set to TRUE. TJB
**********************************************************************/
{
extern option_struct options;
extern param_set_struct param_set;
#if LINK_DEBUG
extern debug_struct debug;
#endif
extern int NF, NR;
char cmdstr[MAXSTRING];
char optstr[MAXSTRING];
char flgstr[MAXSTRING];
char ErrStr[MAXSTRING];
int file_num;
int field;
int i;
global_param_struct global;
/** Initialize non-global parameters **/
global.endmonth = MISSING;
global.endday = MISSING;
global.endyear = MISSING;
global.skipyear = 0;
for(i = 0; i < 2; i++) {
global.forcemonth[i] = 1;
global.forceday[i] = 1;
global.forceyear[i] = MISSING;
global.forcehour[i] = 0;
global.forceskip[i] = 0;
}
file_num = 0;
global.nrecs = MISSING;
strcpy(names->forcing[1],"FALSE");
#if SAVE_STATE
global.stateyear = MISSING;
strcpy(global.statename, "NONE");
#endif
/** Read through global control file to find parameters **/
fgets(cmdstr,MAXSTRING,gp);
while(!feof(gp)) {
if(cmdstr[0]!='#' && cmdstr[0]!='\n' && cmdstr[0]!='\0') {
sscanf(cmdstr,"%s",optstr);
/*******************************
Get Model Global Parameters
*****************************/
if(strcasecmp("NLAYER",optstr)==0) {
sscanf(cmdstr,"%*s %i",&options.Nlayer);
}
else if(strcasecmp("TIME_STEP",optstr)==0) {
sscanf(cmdstr,"%*s %i",&global.dt);
}
else if(strcasecmp("RESOLUTION",optstr)==0) {
sscanf(cmdstr,"%*s %f",&global.resolution);
}
else if(strcasecmp("STARTYEAR",optstr)==0) {
sscanf(cmdstr,"%*s %i",&global.startyear);
}
else if(strcasecmp("STARTMONTH",optstr)==0) {
sscanf(cmdstr,"%*s %i",&global.startmonth);
}
else if(strcasecmp("STARTDAY",optstr)==0) {
sscanf(cmdstr,"%*s %i",&global.startday);
}
else if(strcasecmp("STARTHOUR",optstr)==0) {
sscanf(cmdstr,"%*s %i",&global.starthour);
}
else if(strcasecmp("ENDYEAR",optstr)==0) {
sscanf(cmdstr,"%*s %i",&global.endyear);
}
else if(strcasecmp("ENDMONTH",optstr)==0) {
sscanf(cmdstr,"%*s %i",&global.endmonth);
}
else if(strcasecmp("ENDDAY",optstr)==0) {
sscanf(cmdstr,"%*s %i",&global.endday);
}
else if(strcasecmp("SKIPYEAR",optstr)==0) {
sscanf(cmdstr,"%*s %i",&global.skipyear);
}
else if(strcasecmp("FORCEYEAR",optstr)==0) {
sscanf(cmdstr,"%*s %i",&global.forceyear[file_num]);
}
else if(strcasecmp("FORCEMONTH",optstr)==0) {
sscanf(cmdstr,"%*s %i",&global.forcemonth[file_num]);
}
else if(strcasecmp("FORCEDAY",optstr)==0) {
sscanf(cmdstr,"%*s %i",&global.forceday[file_num]);
}
else if(strcasecmp("FORCEHOUR",optstr)==0) {
sscanf(cmdstr,"%*s %i",&global.forcehour[file_num]);
}
else if(strcasecmp("NRECS",optstr)==0) {
sscanf(cmdstr,"%*s %i",&global.nrecs);
}
else if(strcasecmp("WIND_H",optstr)==0) {
sscanf(cmdstr,"%*s %lf",&global.wind_h);
}
else if(strcasecmp("MEASURE_H",optstr)==0) {
sscanf(cmdstr,"%*s %lf",&global.measure_h);
}
else if(strcasecmp("NODES",optstr)==0) {
sscanf(cmdstr,"%*s %i",&options.Nnode);
}
else if(strcasecmp("MIN_RAIN_TEMP",optstr)==0) {
sscanf(cmdstr,"%*s %lf",&global.MIN_RAIN_TEMP);
}
else if(strcasecmp("MAX_SNOW_TEMP",optstr)==0) {
sscanf(cmdstr,"%*s %lf",&global.MAX_SNOW_TEMP);
}
/********************
Get Model Options
******************/
else if(strcasecmp("FULL_ENERGY",optstr)==0) {
sscanf(cmdstr,"%*s %s",flgstr);
if(strcasecmp("TRUE",flgstr)==0) {
options.FULL_ENERGY=TRUE;
options.QUICK_FLUX=TRUE;
options.GRND_FLUX=TRUE;
}
else options.FULL_ENERGY = FALSE;
}
else if(strcasecmp("FROZEN_SOIL",optstr)==0) {
sscanf(cmdstr,"%*s %s",flgstr);
if(strcasecmp("TRUE",flgstr)==0) {
options.FROZEN_SOIL=TRUE;
options.QUICK_FLUX=FALSE;
options.GRND_FLUX=TRUE;
}
else options.FROZEN_SOIL = FALSE;
}
else if(strcasecmp("NOFLUX",optstr)==0) {
sscanf(cmdstr,"%*s %s",flgstr);
if(strcasecmp("TRUE",flgstr)==0) options.NOFLUX=TRUE;
else options.NOFLUX = FALSE;
}
else if(strcasecmp("DIST_PRCP",optstr)==0) {
sscanf(cmdstr,"%*s %s",flgstr);
if(strcasecmp("TRUE",flgstr)==0) options.DIST_PRCP=TRUE;
else options.DIST_PRCP = FALSE;
}
else if(strcasecmp("COMPRESS",optstr)==0) {
sscanf(cmdstr,"%*s %s",flgstr);
if(strcasecmp("TRUE",flgstr)==0) options.COMPRESS=TRUE;
else options.COMPRESS = FALSE;
}
else if(strcasecmp("CORRPREC",optstr)==0) {
sscanf(cmdstr,"%*s %s",flgstr);
if(strcasecmp("TRUE",flgstr)==0) options.CORRPREC=TRUE;
else options.CORRPREC = FALSE;
}
else if(strcasecmp("PRT_SNOW_BAND",optstr)==0) {
sscanf(cmdstr,"%*s %s",flgstr);
if(strcasecmp("TRUE",flgstr)==0) options.PRT_SNOW_BAND=TRUE;
else options.PRT_SNOW_BAND = FALSE;
}
else if(strcasecmp("GRID_DECIMAL",optstr)==0) {
sscanf(cmdstr,"%*s %i",&options.GRID_DECIMAL);
}
else if(strcasecmp("SNOW_BAND",optstr)==0) {
sscanf(cmdstr,"%*s %i %s",&options.SNOW_BAND,names->snow_band);
}
else if(strcasecmp("BINARY_OUTPUT",optstr)==0) {
sscanf(cmdstr,"%*s %s",flgstr);
if(strcasecmp("TRUE",flgstr)==0) options.BINARY_OUTPUT=TRUE;
else options.BINARY_OUTPUT = FALSE;
}
else if(strcasecmp("ARC_SOIL",optstr)==0) {
sscanf(cmdstr,"%*s %s",flgstr);
if(strcasecmp("TRUE",flgstr)==0) options.ARC_SOIL=TRUE;
else options.ARC_SOIL = FALSE;
}
else if(strcasecmp("SNOW_STEP",optstr)==0) {
sscanf(cmdstr,"%*s %i",&options.SNOW_STEP);
}
else if(strcasecmp("ROOT_ZONES",optstr)==0) {
sscanf(cmdstr,"%*s %i",&options.ROOT_ZONES);
}
else if(strcasecmp("PREC_EXPT",optstr)==0) {
sscanf(cmdstr,"%*s %f",&options.PREC_EXPT);
}
else if(strcasecmp("MIN_WIND_SPEED",optstr)==0) {
sscanf(cmdstr,"%*s %f",&options.MIN_WIND_SPEED);
}
else if(strcasecmp("GRND_FLUX",optstr)==0) {
sscanf(cmdstr,"%*s %s",flgstr);
if(strcasecmp("TRUE",flgstr)==0) options.GRND_FLUX=TRUE;
else options.GRND_FLUX = FALSE;
}
else if(strcasecmp("QUICK_FLUX",optstr)==0) {
sscanf(cmdstr,"%*s %s",flgstr);
if(strcasecmp("TRUE",flgstr)==0) options.QUICK_FLUX=TRUE;
else options.QUICK_FLUX = FALSE;
}
else if(strcasecmp("MOISTFRACT",optstr)==0) {
sscanf(cmdstr,"%*s %s",flgstr);
if(strcasecmp("TRUE",flgstr)==0) options.MOISTFRACT=TRUE;
else options.MOISTFRACT = FALSE;
}
else if(strcasecmp("ARNO_PARAMS",optstr)==0) {
sscanf(cmdstr,"%*s %s",flgstr);
if(strcasecmp("TRUE",flgstr)==0) options.ARNO_PARAMS=TRUE;
else options.ARNO_PARAMS = FALSE;
}
#if SAVE_STATE
else if(strcasecmp("INIT_STATE",optstr)==0) {
sscanf(cmdstr,"%*s %s",flgstr);
if(strcasecmp("FALSE",flgstr)==0) options.INIT_STATE=FALSE;
else {
options.INIT_STATE = TRUE;
strcpy(names->init_state,flgstr);
}
}
else if(strcasecmp("BINARY_STATE_FILE",optstr)==0) {
sscanf(cmdstr,"%*s %s",flgstr);
if(strcasecmp("FALSE",flgstr)==0) options.BINARY_STATE_FILE=FALSE;
else options.BINARY_STATE_FILE=TRUE;
}
else if(strcasecmp("STATENAME",optstr)==0) {
sscanf(cmdstr,"%*s %s",global.statename);
}
else if(strcasecmp("STATEYEAR",optstr)==0) {
sscanf(cmdstr,"%*s %i",&global.stateyear);
}
else if(strcasecmp("STATEMONTH",optstr)==0) {
sscanf(cmdstr,"%*s %i",&global.statemonth);
}
else if(strcasecmp("STATEDAY",optstr)==0) {
sscanf(cmdstr,"%*s %i",&global.stateday);
}
#endif
else if(strcasecmp("COMPUTE_TREELINE",optstr)==0) {
sscanf(cmdstr,"%*s %s",flgstr);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -