/****************************************************************************** * @brief Set the output_stream and out_data structures to default values. These can be overridden by the user in the global control file. *****************************************************************************/ void set_output_defaults(stream_struct **streams, dmy_struct *dmy_current, unsigned short default_file_format) { extern option_struct options; size_t streamnum; size_t varnum; alarm_struct default_alarm; int default_freq_n = 1; set_alarm(dmy_current, FREQ_NDAYS, &default_freq_n, &default_alarm); for (streamnum = 0; streamnum < options.Noutstreams; streamnum++) { (*streams)[streamnum].agg_alarm = default_alarm; (*streams)[streamnum].file_format = default_file_format; } // Variables in first file streamnum = 0; varnum = 0; strcpy((*streams)[streamnum].prefix, "fluxes"); set_output_var(&((*streams)[streamnum]), "OUT_PREC", varnum++, "%.4f", OUT_TYPE_FLOAT, 1, AGG_TYPE_DEFAULT); set_output_var(&((*streams)[streamnum]), "OUT_EVAP", varnum++, "%.4f", OUT_TYPE_FLOAT, 1, AGG_TYPE_DEFAULT); set_output_var(&((*streams)[streamnum]), "OUT_RUNOFF", varnum++, "%.4f", OUT_TYPE_FLOAT, 1, AGG_TYPE_DEFAULT); set_output_var(&((*streams)[streamnum]), "OUT_BASEFLOW", varnum++, "%.4f", OUT_TYPE_FLOAT, 1, AGG_TYPE_DEFAULT); set_output_var(&((*streams)[streamnum]), "OUT_WDEW", varnum++, "%.4f", OUT_TYPE_FLOAT, 1, AGG_TYPE_DEFAULT); set_output_var(&((*streams)[streamnum]), "OUT_SOIL_LIQ", varnum++, "%.4f", OUT_TYPE_FLOAT, 1, AGG_TYPE_DEFAULT); if (options.FULL_ENERGY || options.FROZEN_SOIL) { set_output_var(&((*streams)[streamnum]), "OUT_RAD_TEMP", varnum++, "%.4f", OUT_TYPE_FLOAT, 1, AGG_TYPE_DEFAULT); } set_output_var(&((*streams)[streamnum]), "OUT_SWNET", varnum++, "%.4f", OUT_TYPE_FLOAT, 1, AGG_TYPE_DEFAULT); set_output_var(&((*streams)[streamnum]), "OUT_R_NET", varnum++, "%.4f", OUT_TYPE_FLOAT, 1, AGG_TYPE_DEFAULT); if (options.FULL_ENERGY || options.FROZEN_SOIL) { set_output_var(&((*streams)[streamnum]), "OUT_LATENT", varnum++, "%.4f", OUT_TYPE_FLOAT, 1, AGG_TYPE_DEFAULT); } set_output_var(&((*streams)[streamnum]), "OUT_EVAP_CANOP", varnum++, "%.4f", OUT_TYPE_FLOAT, 1, AGG_TYPE_DEFAULT); set_output_var(&((*streams)[streamnum]), "OUT_TRANSP_VEG", varnum++, "%.4f", OUT_TYPE_FLOAT, 1, AGG_TYPE_DEFAULT); set_output_var(&((*streams)[streamnum]), "OUT_EVAP_BARE", varnum++, "%.4f", OUT_TYPE_FLOAT, 1, AGG_TYPE_DEFAULT); set_output_var(&((*streams)[streamnum]), "OUT_SUB_CANOP", varnum++, "%.4f", OUT_TYPE_FLOAT, 1, AGG_TYPE_DEFAULT); set_output_var(&((*streams)[streamnum]), "OUT_SUB_SNOW", varnum++, "%.4f", OUT_TYPE_FLOAT, 1, AGG_TYPE_DEFAULT); if (options.FULL_ENERGY || options.FROZEN_SOIL) { set_output_var(&((*streams)[streamnum]), "OUT_SENSIBLE", varnum++, "%.4f", OUT_TYPE_FLOAT, 1, AGG_TYPE_DEFAULT); set_output_var(&((*streams)[streamnum]), "OUT_GRND_FLUX", varnum++, "%.4f", OUT_TYPE_FLOAT, 1, AGG_TYPE_DEFAULT); set_output_var(&((*streams)[streamnum]), "OUT_DELTAH", varnum++, "%.4f", OUT_TYPE_FLOAT, 1, AGG_TYPE_DEFAULT); set_output_var(&((*streams)[streamnum]), "OUT_FUSION", varnum++, "%.4f", OUT_TYPE_FLOAT, 1, AGG_TYPE_DEFAULT); } set_output_var(&((*streams)[streamnum]), "OUT_AERO_RESIST", varnum++, "%.4f", OUT_TYPE_FLOAT, 1, AGG_TYPE_DEFAULT); set_output_var(&((*streams)[streamnum]), "OUT_SURF_TEMP", varnum++, "%.4f", OUT_TYPE_FLOAT, 1, AGG_TYPE_DEFAULT); set_output_var(&((*streams)[streamnum]), "OUT_ALBEDO", varnum++, "%.4f", OUT_TYPE_FLOAT, 1, AGG_TYPE_DEFAULT); set_output_var(&((*streams)[streamnum]), "OUT_REL_HUMID", varnum++, "%.4f", OUT_TYPE_FLOAT, 1, AGG_TYPE_DEFAULT); set_output_var(&((*streams)[streamnum]), "OUT_IN_LONG", varnum++, "%.4f", OUT_TYPE_FLOAT, 1, AGG_TYPE_DEFAULT); set_output_var(&((*streams)[streamnum]), "OUT_AIR_TEMP", varnum++, "%.4f", OUT_TYPE_FLOAT, 1, AGG_TYPE_DEFAULT); set_output_var(&((*streams)[streamnum]), "OUT_WIND", varnum++, "%.4f", OUT_TYPE_FLOAT, 1, AGG_TYPE_DEFAULT); // Variables in second file streamnum++; varnum = 0; strcpy((*streams)[streamnum].prefix, "snow"); set_output_var(&((*streams)[streamnum]), "OUT_SWE", varnum++, "%.4f", OUT_TYPE_FLOAT, 1, AGG_TYPE_DEFAULT); set_output_var(&((*streams)[streamnum]), "OUT_SNOW_DEPTH", varnum++, "%.4f", OUT_TYPE_FLOAT, 1, AGG_TYPE_DEFAULT); set_output_var(&((*streams)[streamnum]), "OUT_SNOW_CANOPY", varnum++, "%.4f", OUT_TYPE_FLOAT, 1, AGG_TYPE_DEFAULT); set_output_var(&((*streams)[streamnum]), "OUT_SNOW_COVER", varnum++, "%.4f", OUT_TYPE_FLOAT, 1, AGG_TYPE_DEFAULT); if (options.FULL_ENERGY || options.FROZEN_SOIL) { set_output_var(&((*streams)[streamnum]), "OUT_ADVECTION", varnum++, "%.4f", OUT_TYPE_FLOAT, 1, AGG_TYPE_DEFAULT); set_output_var(&((*streams)[streamnum]), "OUT_DELTACC", varnum++, "%.4f", OUT_TYPE_FLOAT, 1, AGG_TYPE_DEFAULT); set_output_var(&((*streams)[streamnum]), "OUT_SNOW_FLUX", varnum++, "%.4f", OUT_TYPE_FLOAT, 1, AGG_TYPE_DEFAULT); set_output_var(&((*streams)[streamnum]), "OUT_RFRZ_ENERGY", varnum++, "%.4f", OUT_TYPE_FLOAT, 1, AGG_TYPE_DEFAULT); set_output_var(&((*streams)[streamnum]), "OUT_MELT_ENERGY", varnum++, "%.4f", OUT_TYPE_FLOAT, 1, AGG_TYPE_DEFAULT); set_output_var(&((*streams)[streamnum]), "OUT_ADV_SENS", varnum++, "%.4f", OUT_TYPE_FLOAT, 1, AGG_TYPE_DEFAULT); set_output_var(&((*streams)[streamnum]), "OUT_LATENT_SUB", varnum++, "%.4f", OUT_TYPE_FLOAT, 1, AGG_TYPE_DEFAULT); set_output_var(&((*streams)[streamnum]), "OUT_SNOW_SURF_TEMP", varnum++, "%.4f", OUT_TYPE_FLOAT, 1, AGG_TYPE_DEFAULT); set_output_var(&((*streams)[streamnum]), "OUT_SNOW_PACK_TEMP", varnum++, "%.4f", OUT_TYPE_FLOAT, 1, AGG_TYPE_DEFAULT); set_output_var(&((*streams)[streamnum]), "OUT_SNOW_MELT", varnum++, "%.4f", OUT_TYPE_FLOAT, 1, AGG_TYPE_DEFAULT); } if (options.BLOWING) { set_output_var(&((*streams)[streamnum]), "OUT_SUB_BLOWING", varnum++, "%.4f", OUT_TYPE_FLOAT, 1, AGG_TYPE_DEFAULT); set_output_var(&((*streams)[streamnum]), "OUT_SUB_SURFACE", varnum++, "%.4f", OUT_TYPE_FLOAT, 1, AGG_TYPE_DEFAULT); set_output_var(&((*streams)[streamnum]), "OUT_SUB_SNOW", varnum++, "%.4f", OUT_TYPE_FLOAT, 1, AGG_TYPE_DEFAULT); } // Variables in other files if (options.FROZEN_SOIL) { streamnum++; varnum = 0; strcpy((*streams)[streamnum].prefix, "fdepth"); set_output_var(&((*streams)[streamnum]), "OUT_FDEPTH", varnum++, "%.4f", OUT_TYPE_FLOAT, 1, AGG_TYPE_DEFAULT); set_output_var(&((*streams)[streamnum]), "OUT_TDEPTH", varnum++, "%.4f", OUT_TYPE_FLOAT, 1, AGG_TYPE_DEFAULT); set_output_var(&((*streams)[streamnum]), "OUT_SOIL_MOIST", varnum++, "%.4f", OUT_TYPE_FLOAT, 1, AGG_TYPE_DEFAULT); set_output_var(&((*streams)[streamnum]), "OUT_SURF_FROST_FRAC", varnum++, "%.4f", OUT_TYPE_FLOAT, 1, AGG_TYPE_DEFAULT); } if (options.SNOW_BAND) { streamnum++; varnum = 0; strcpy((*streams)[streamnum].prefix, "snowband"); set_output_var(&((*streams)[streamnum]), "OUT_SWE_BAND", varnum++, "%.4f", OUT_TYPE_FLOAT, 1, AGG_TYPE_DEFAULT); set_output_var(&((*streams)[streamnum]), "OUT_SNOW_DEPTH_BAND", varnum++, "%.4f", OUT_TYPE_FLOAT, 1, AGG_TYPE_DEFAULT); set_output_var(&((*streams)[streamnum]), "OUT_SNOW_CANOPY_BAND", varnum++, "%.4f", OUT_TYPE_FLOAT, 1, AGG_TYPE_DEFAULT); if (options.FULL_ENERGY) { set_output_var(&((*streams)[streamnum]), "OUT_ADVECTION_BAND", varnum++, "%.4f", OUT_TYPE_FLOAT, 1, AGG_TYPE_DEFAULT); set_output_var(&((*streams)[streamnum]), "OUT_DELTACC_BAND", varnum++, "%.4f", OUT_TYPE_FLOAT, 1, AGG_TYPE_DEFAULT); set_output_var(&((*streams)[streamnum]), "OUT_SNOW_FLUX_BAND", varnum++, "%.4f", OUT_TYPE_FLOAT, 1, AGG_TYPE_DEFAULT); set_output_var(&((*streams)[streamnum]), "OUT_RFRZ_ENERGY_BAND", varnum++, "%.4f", OUT_TYPE_FLOAT, 1, AGG_TYPE_DEFAULT); } set_output_var(&((*streams)[streamnum]), "OUT_SWNET_BAND", varnum++, "%.4f", OUT_TYPE_FLOAT, 1, AGG_TYPE_DEFAULT); set_output_var(&((*streams)[streamnum]), "OUT_LWNET_BAND", varnum++, "%.4f", OUT_TYPE_FLOAT, 1, AGG_TYPE_DEFAULT); set_output_var(&((*streams)[streamnum]), "OUT_ALBEDO_BAND", varnum++, "%.4f", OUT_TYPE_FLOAT, 1, AGG_TYPE_DEFAULT); set_output_var(&((*streams)[streamnum]), "OUT_LATENT_BAND", varnum++, "%.4f", OUT_TYPE_FLOAT, 1, AGG_TYPE_DEFAULT); set_output_var(&((*streams)[streamnum]), "OUT_SENSIBLE_BAND", varnum++, "%.4f", OUT_TYPE_FLOAT, 1, AGG_TYPE_DEFAULT); set_output_var(&((*streams)[streamnum]), "OUT_GRND_FLUX_BAND", varnum++, "%.4f", OUT_TYPE_FLOAT, 1, AGG_TYPE_DEFAULT); } if (options.LAKES) { streamnum++; varnum = 0; strcpy((*streams)[streamnum].prefix, "lake"); set_output_var(&((*streams)[streamnum]), "OUT_LAKE_ICE_TEMP", varnum++, "%.4f", OUT_TYPE_FLOAT, 1, AGG_TYPE_DEFAULT); set_output_var(&((*streams)[streamnum]), "OUT_LAKE_ICE_HEIGHT", varnum++, "%.4f", OUT_TYPE_FLOAT, 1, AGG_TYPE_DEFAULT); set_output_var(&((*streams)[streamnum]), "OUT_LAKE_ICE_FRACT", varnum++, "%.4f", OUT_TYPE_FLOAT, 1, AGG_TYPE_DEFAULT); set_output_var(&((*streams)[streamnum]), "OUT_LAKE_DEPTH", varnum++, "%.4f", OUT_TYPE_FLOAT, 1, AGG_TYPE_DEFAULT); set_output_var(&((*streams)[streamnum]), "OUT_LAKE_SURF_AREA", varnum++, "%.4f", OUT_TYPE_FLOAT, 1, AGG_TYPE_DEFAULT); set_output_var(&((*streams)[streamnum]), "OUT_LAKE_VOLUME", varnum++, "%.4f", OUT_TYPE_FLOAT, 1, AGG_TYPE_DEFAULT); set_output_var(&((*streams)[streamnum]), "OUT_LAKE_SURF_TEMP", varnum++, "%.4f", OUT_TYPE_FLOAT, 1, AGG_TYPE_DEFAULT); set_output_var(&((*streams)[streamnum]), "OUT_LAKE_EVAP", varnum++, "%.4f", OUT_TYPE_FLOAT, 1, AGG_TYPE_DEFAULT); } }
void parse_output_info(const char* input_file_name, out_data_file_struct *out_data_files, OutputData *out_data, ProgramState *state) /********************************************************************** parse_output_info Ted Bohn September 10 2006 This routine reads the VIC model global control file, getting information for output variables list (if any). Modifications: 2006-Nov-07 Changed default precision from %.1f to %.4f. TJB 2007-Jan-15 Modified to expect "OUT_TYPE_" at beginning of output data type strings. TJB 2007-Apr-21 Added initialization for format, outfilenum, and outvarnum. TJB 2008-Feb-15 Added check on number of output files defined vs. N_OUTFILES. TJB 2009-Feb-09 Sets PRT_SNOW_BAND to FALSE if N_OUTFILES has been specified. TJB 2009-Mar-15 Added default values for format, typestr, and multstr, so that they can be omitted from global param file. TJB **********************************************************************/ { char cmdstr[MAXSTRING]; char optstr[MAXSTRING]; int i; int outfilenum; int fn; char varname[30]; int outvarnum; char format[10]; char output_varname[30]; int type; char multstr[20]; float mult; int tmp_noutfiles; char ErrStr[MAXSTRING]; strcpy(format,"*"); FILE* gp = open_file(input_file_name, "r"); /** Read through global control file to find output info **/ fgets(cmdstr,MAXSTRING,gp); outfilenum = -1; outvarnum = 0; while(!feof(gp)) { if(cmdstr[0]!='#' && cmdstr[0]!='\n' && cmdstr[0]!='\0') { sscanf(cmdstr,"%s",optstr); if(strcasecmp("N_OUTFILES",optstr)==0) { sscanf(cmdstr,"%*s %d",&tmp_noutfiles); delete [] out_data_files; state->options.Noutfiles = tmp_noutfiles; out_data_files = new out_data_file_struct [state->options.Noutfiles]; outfilenum = -1; init_output_list(out_data, FALSE, "%.4f", OUT_TYPE_FLOAT, 1); // PRT_SNOW_BAND is ignored if N_OUTFILES has been specified state->options.PRT_SNOW_BAND = FALSE; } else if(strcasecmp("OUTFILE",optstr)==0) { outfilenum++; if (!state->options.Noutfiles) { nrerror("Error in global param file: \"N_OUTFILES\" must be specified before you can specify \"OUTFILE\"."); } if (outfilenum >= state->options.Noutfiles) { sprintf(ErrStr, "Error in global param file: number of output files specified in N_OUTFILES (%d) is less than actual number of output files defined in the global param file.",state->options.Noutfiles); nrerror(ErrStr); } sscanf(cmdstr,"%*s %s %d",out_data_files[outfilenum].prefix,&(out_data_files[outfilenum].nvars)); out_data_files[outfilenum].varid = (int *)calloc(out_data_files[outfilenum].nvars, sizeof(int)); outvarnum = 0; } else if(strcasecmp("OUTVAR",optstr)==0) { if (outfilenum < 0) { nrerror("Error in global param file: \"OUTFILE\" must be specified before you can specify \"OUTVAR\"."); } /* The next 3 lines are just to avoid breaking stuff from legacy VIC output formatting, but in actuality only float data is written now */ strcpy(format,"*"); type = OUT_TYPE_FLOAT; mult = 0; // 0 means default multiplier /* Now using additional parameters to the right of OUTVAR to designate the variable name to appear in the NetCDF/ASCII file: * OUTVAR <vic varname> <output_varname> * e.g. OUTVAR OUT_SNOW_DEPTH snd <--mapping OUT_SNOW_DEPTH to snd * If no 2nd parameter is provided, the vic varname will be used in the output file */ int numvars = sscanf(cmdstr,"%*s %s %s", varname, output_varname); if (numvars == 2) { // an output_varname was provided, so change the mapping of this variable in state->output_mapping to the new output_varname state->set_output_variable_name(std::string(varname), std::string(output_varname)); } if (set_output_var(out_data_files, TRUE, outfilenum, out_data, varname, outvarnum, format, type, mult) != 0) { nrerror("Error in global param file: Invalid output variable specification."); } strcpy(format,""); outvarnum++; } } fgets(cmdstr,MAXSTRING,gp); } fclose(gp); }
void parse_output_info(filenames_struct *names, FILE *gp, out_data_file_struct **out_data_files, out_data_struct *out_data) /********************************************************************** parse_output_info Ted Bohn September 10 2006 This routine reads the VIC model global control file, getting information for output variables list (if any). Modifications: 2006-Nov-07 Changed default precision from %.1f to %.4f. TJB 2007-Jan-15 Modified to expect "OUT_TYPE_" at beginning of output data type strings. TJB 2007-Apr-21 Added initialization for format, outfilenum, and outvarnum. TJB **********************************************************************/ { extern option_struct options; char cmdstr[MAXSTRING]; char optstr[MAXSTRING]; int i; int outfilenum; int fn; char varname[20]; int outvarnum; char format[10]; char typestr[20]; int type; char multstr[20]; float mult; int tmp_noutfiles; strcpy(format,"*"); /** Read through global control file to find output info **/ fgets(cmdstr,MAXSTRING,gp); outfilenum = -1; outvarnum = 0; while(!feof(gp)) { if(cmdstr[0]!='#' && cmdstr[0]!='\n' && cmdstr[0]!='\0') { sscanf(cmdstr,"%s",optstr); if(strcasecmp("N_OUTFILES",optstr)==0) { sscanf(cmdstr,"%*s %d",&tmp_noutfiles); free_out_data_files(out_data_files); options.Noutfiles = tmp_noutfiles; *out_data_files = (out_data_file_struct *)calloc(options.Noutfiles, sizeof(out_data_file_struct)); outfilenum = -1; init_output_list(out_data, FALSE, "%.4f", OUT_TYPE_FLOAT, 1); } else if(strcasecmp("OUTFILE",optstr)==0) { outfilenum++; if (!options.Noutfiles) { nrerror("Error in global param file: \"N_OUTFILES\" must be specified before you can specify \"OUTFILE\"."); } sscanf(cmdstr,"%*s %s %d",(*out_data_files)[outfilenum].prefix,&((*out_data_files)[outfilenum].nvars)); (*out_data_files)[outfilenum].varid = (int *)calloc((*out_data_files)[outfilenum].nvars, sizeof(int)); outvarnum = 0; } else if(strcasecmp("OUTVAR",optstr)==0) { if (outfilenum < 0) { nrerror("Error in global param file: \"OUTFILE\" must be specified before you can specify \"OUTVAR\"."); } sscanf(cmdstr,"%*s %s %s %s %s",varname, format, typestr, multstr); if (strcasecmp("",format) == 0) { strcpy(format,"*"); type = OUT_TYPE_DEFAULT; mult = 0; // 0 means default multiplier } else { if (strcasecmp("OUT_TYPE_USINT", typestr)==0) type = OUT_TYPE_USINT; else if (strcasecmp("OUT_TYPE_SINT", typestr)==0) type = OUT_TYPE_SINT; else if (strcasecmp("OUT_TYPE_FLOAT", typestr)==0) type = OUT_TYPE_FLOAT; else if (strcasecmp("OUT_TYPE_DOUBLE", typestr)==0) type = OUT_TYPE_DOUBLE; else type = OUT_TYPE_DEFAULT; if (strcmp("*", multstr)==0) mult = 0; // 0 means use default multiplier else mult = (float)atof(multstr); } if (set_output_var((*out_data_files), TRUE, outfilenum, out_data, varname, outvarnum, format, type, mult) != 0) { nrerror("Error in global param file: Invalid output variable specification."); } strcpy(format,""); outvarnum++; } } fgets(cmdstr,MAXSTRING,gp); } fclose(gp); }
out_data_file_struct *set_output_defaults(out_data_struct *out_data) { /************************************************************* set_output_defaults.c Ted Bohn September 08, 2006 This routine sets the out_data_files and out_data structures to default values. These can be overridden by the user in the global control file. Modifications: 2006-Oct-10 Shortened the names of output variables whose names were too long. TJB 2007-Oct-09 Updated to reflect variables present in traditional 4.1.0 output files. Previously the defaults matched the traditional 4.0.6 output files. TJB 2008-Apr-11 Added OUT_SUB_BLOWING, OUT_SUB_SURFACE, and OUT_SUB_SNOW to default snow output file for case of options.BLOWING == TRUE. This makes it almost the same as previous versions of 4.1.0, (r3 and earlier) with the exception that previous versions of 4.1.0 multiplied these terms by 100 when saving to the snow file. TJB *************************************************************/ extern option_struct options; out_data_file_struct *out_data_files; int v, i; int filenum; int varnum; #if OUTPUT_FORCE // Output files options.Noutfiles = 1; out_data_files = (out_data_file_struct *)calloc(options.Noutfiles,sizeof(out_data_file_struct)); strcpy(out_data_files[0].prefix,"full_data"); out_data_files[0].nvars = 8; out_data_files[0].varid = (int *)calloc(out_data_files[0].nvars, sizeof(int)); // Variables in first file filenum = 0; varnum = 0; set_output_var(out_data_files, TRUE, filenum, out_data, "OUT_PREC", varnum++, "%.4f", OUT_TYPE_USINT, 40); set_output_var(out_data_files, TRUE, filenum, out_data, "OUT_AIR_TEMP", varnum++, "%.4f", OUT_TYPE_SINT, 100); set_output_var(out_data_files, TRUE, filenum, out_data, "OUT_SHORTWAVE", varnum++, "%.4f", OUT_TYPE_USINT, 50); set_output_var(out_data_files, TRUE, filenum, out_data, "OUT_LONGWAVE", varnum++, "%.4f", OUT_TYPE_USINT, 80); set_output_var(out_data_files, TRUE, filenum, out_data, "OUT_DENSITY", varnum++, "%.4f", OUT_TYPE_USINT, 100); set_output_var(out_data_files, TRUE, filenum, out_data, "OUT_PRESSURE", varnum++, "%.4f", OUT_TYPE_USINT, 100); set_output_var(out_data_files, TRUE, filenum, out_data, "OUT_VP", varnum++, "%.4f", OUT_TYPE_SINT, 100); set_output_var(out_data_files, TRUE, filenum, out_data, "OUT_WIND", varnum++, "%.4f", OUT_TYPE_USINT, 100); #else // Output files options.Noutfiles = 2; if (options.FROZEN_SOIL) { options.Noutfiles++; } if (options.PRT_SNOW_BAND) { options.Noutfiles++; } if (options.LAKES) { options.Noutfiles++; } out_data_files = (out_data_file_struct *)calloc(options.Noutfiles,sizeof(out_data_file_struct)); filenum = 0; strcpy(out_data_files[filenum].prefix,"fluxes"); if (options.FULL_ENERGY || options.FROZEN_SOIL) { out_data_files[filenum].nvars = 26; } else { out_data_files[filenum].nvars = 20; } filenum++; strcpy(out_data_files[filenum].prefix,"snow"); if (options.FULL_ENERGY || options.FROZEN_SOIL) { out_data_files[filenum].nvars = 14; } else { out_data_files[filenum].nvars = 4; } if (options.BLOWING) { out_data_files[filenum].nvars+= 3; } if (options.FROZEN_SOIL) { filenum++; strcpy(out_data_files[filenum].prefix,"fdepth"); out_data_files[filenum].nvars = 4; } if (options.PRT_SNOW_BAND) { filenum++; strcpy(out_data_files[filenum].prefix,"snowband"); if (options.FULL_ENERGY) { out_data_files[filenum].nvars = 13; } else { out_data_files[filenum].nvars = 9; } } if (options.LAKES) { filenum++; strcpy(out_data_files[filenum].prefix,"lake"); out_data_files[filenum].nvars = 8; } for (filenum=0; filenum<options.Noutfiles; filenum++) { out_data_files[filenum].varid = (int *)calloc(out_data_files[filenum].nvars, sizeof(int)); } // Variables in first file filenum = 0; varnum = 0; set_output_var(out_data_files, TRUE, filenum, out_data, "OUT_PREC", varnum++, "%.4f", OUT_TYPE_FLOAT, 1); set_output_var(out_data_files, TRUE, filenum, out_data, "OUT_EVAP", varnum++, "%.4f", OUT_TYPE_FLOAT, 1); set_output_var(out_data_files, TRUE, filenum, out_data, "OUT_RUNOFF", varnum++, "%.4f", OUT_TYPE_FLOAT, 1); set_output_var(out_data_files, TRUE, filenum, out_data, "OUT_BASEFLOW", varnum++, "%.4f", OUT_TYPE_FLOAT, 1); set_output_var(out_data_files, TRUE, filenum, out_data, "OUT_WDEW", varnum++, "%.4f", OUT_TYPE_FLOAT, 1); set_output_var(out_data_files, TRUE, filenum, out_data, "OUT_SOIL_LIQ", varnum++, "%.4f", OUT_TYPE_FLOAT, 1); if (options.FULL_ENERGY || options.FROZEN_SOIL) { set_output_var(out_data_files, TRUE, filenum, out_data, "OUT_RAD_TEMP", varnum++, "%.4f", OUT_TYPE_FLOAT, 1); } set_output_var(out_data_files, TRUE, filenum, out_data, "OUT_NET_SHORT", varnum++, "%.4f", OUT_TYPE_FLOAT, 1); set_output_var(out_data_files, TRUE, filenum, out_data, "OUT_R_NET", varnum++, "%.4f", OUT_TYPE_FLOAT, 1); if (options.FULL_ENERGY || options.FROZEN_SOIL) { set_output_var(out_data_files, TRUE, filenum, out_data, "OUT_LATENT", varnum++, "%.4f", OUT_TYPE_FLOAT, 1); } set_output_var(out_data_files, TRUE, filenum, out_data, "OUT_EVAP_CANOP", varnum++, "%.4f", OUT_TYPE_FLOAT, 1); set_output_var(out_data_files, TRUE, filenum, out_data, "OUT_TRANSP_VEG", varnum++, "%.4f", OUT_TYPE_FLOAT, 1); set_output_var(out_data_files, TRUE, filenum, out_data, "OUT_EVAP_BARE", varnum++, "%.4f", OUT_TYPE_FLOAT, 1); set_output_var(out_data_files, TRUE, filenum, out_data, "OUT_SUB_CANOP", varnum++, "%.4f", OUT_TYPE_FLOAT, 1); set_output_var(out_data_files, TRUE, filenum, out_data, "OUT_SUB_SNOW", varnum++, "%.4f", OUT_TYPE_FLOAT, 1); if (options.FULL_ENERGY || options.FROZEN_SOIL) { set_output_var(out_data_files, TRUE, filenum, out_data, "OUT_SENSIBLE", varnum++, "%.4f", OUT_TYPE_FLOAT, 1); set_output_var(out_data_files, TRUE, filenum, out_data, "OUT_GRND_FLUX", varnum++, "%.4f", OUT_TYPE_FLOAT, 1); set_output_var(out_data_files, TRUE, filenum, out_data, "OUT_DELTAH", varnum++, "%.4f", OUT_TYPE_FLOAT, 1); set_output_var(out_data_files, TRUE, filenum, out_data, "OUT_FUSION", varnum++, "%.4f", OUT_TYPE_FLOAT, 1); } set_output_var(out_data_files, TRUE, filenum, out_data, "OUT_AERO_RESIST", varnum++, "%.4f", OUT_TYPE_FLOAT, 1); set_output_var(out_data_files, TRUE, filenum, out_data, "OUT_SURF_TEMP", varnum++, "%.4f", OUT_TYPE_FLOAT, 1); set_output_var(out_data_files, TRUE, filenum, out_data, "OUT_ALBEDO", varnum++, "%.4f", OUT_TYPE_FLOAT, 1); set_output_var(out_data_files, TRUE, filenum, out_data, "OUT_REL_HUMID", varnum++, "%.4f", OUT_TYPE_FLOAT, 1); set_output_var(out_data_files, TRUE, filenum, out_data, "OUT_IN_LONG", varnum++, "%.4f", OUT_TYPE_FLOAT, 1); set_output_var(out_data_files, TRUE, filenum, out_data, "OUT_AIR_TEMP", varnum++, "%.4f", OUT_TYPE_FLOAT, 1); set_output_var(out_data_files, TRUE, filenum, out_data, "OUT_WIND", varnum++, "%.4f", OUT_TYPE_FLOAT, 1); // Variables in second file filenum++; varnum = 0; set_output_var(out_data_files, TRUE, filenum, out_data, "OUT_SWE", varnum++, "%.4f", OUT_TYPE_FLOAT, 1); set_output_var(out_data_files, TRUE, filenum, out_data, "OUT_SNOW_DEPTH", varnum++, "%.4f", OUT_TYPE_FLOAT, 1); set_output_var(out_data_files, TRUE, filenum, out_data, "OUT_SNOW_CANOPY", varnum++, "%.4f", OUT_TYPE_FLOAT, 1); set_output_var(out_data_files, TRUE, filenum, out_data, "OUT_SNOW_COVER", varnum++, "%.4f", OUT_TYPE_FLOAT, 1); if (options.FULL_ENERGY || options.FROZEN_SOIL) { set_output_var(out_data_files, TRUE, filenum, out_data, "OUT_ADVECTION", varnum++, "%.4f", OUT_TYPE_FLOAT, 1); set_output_var(out_data_files, TRUE, filenum, out_data, "OUT_DELTACC", varnum++, "%.4f", OUT_TYPE_FLOAT, 1); set_output_var(out_data_files, TRUE, filenum, out_data, "OUT_SNOW_FLUX", varnum++, "%.4f", OUT_TYPE_FLOAT, 1); set_output_var(out_data_files, TRUE, filenum, out_data, "OUT_RFRZ_ENERGY", varnum++, "%.4f", OUT_TYPE_FLOAT, 1); set_output_var(out_data_files, TRUE, filenum, out_data, "OUT_MELT_ENERGY", varnum++, "%.4f", OUT_TYPE_FLOAT, 1); set_output_var(out_data_files, TRUE, filenum, out_data, "OUT_ADV_SENS", varnum++, "%.4f", OUT_TYPE_FLOAT, 1); set_output_var(out_data_files, TRUE, filenum, out_data, "OUT_LATENT_SUB", varnum++, "%.4f", OUT_TYPE_FLOAT, 1); set_output_var(out_data_files, TRUE, filenum, out_data, "OUT_SNOW_SURF_TEMP", varnum++, "%.4f", OUT_TYPE_FLOAT, 1); set_output_var(out_data_files, TRUE, filenum, out_data, "OUT_SNOW_PACK_TEMP", varnum++, "%.4f", OUT_TYPE_FLOAT, 1); set_output_var(out_data_files, TRUE, filenum, out_data, "OUT_SNOW_MELT", varnum++, "%.4f", OUT_TYPE_FLOAT, 1); } if (options.BLOWING) { set_output_var(out_data_files, TRUE, filenum, out_data, "OUT_SUB_BLOWING", varnum++, "%.4f", OUT_TYPE_FLOAT, 1); set_output_var(out_data_files, TRUE, filenum, out_data, "OUT_SUB_SURFACE", varnum++, "%.4f", OUT_TYPE_FLOAT, 1); set_output_var(out_data_files, TRUE, filenum, out_data, "OUT_SUB_SNOW", varnum++, "%.4f", OUT_TYPE_FLOAT, 1); } // Variables in other files if (options.FROZEN_SOIL) { filenum++; varnum = 0; set_output_var(out_data_files, TRUE, filenum, out_data, "OUT_FDEPTH", varnum++, "%.4f", OUT_TYPE_FLOAT, 1); set_output_var(out_data_files, TRUE, filenum, out_data, "OUT_TDEPTH", varnum++, "%.4f", OUT_TYPE_FLOAT, 1); set_output_var(out_data_files, TRUE, filenum, out_data, "OUT_SOIL_MOIST", varnum++, "%.4f", OUT_TYPE_FLOAT, 1); set_output_var(out_data_files, TRUE, filenum, out_data, "OUT_SURF_FROST_FRAC", varnum++, "%.4f", OUT_TYPE_FLOAT, 1); } if (options.PRT_SNOW_BAND) { filenum++; varnum = 0; set_output_var(out_data_files, TRUE, filenum, out_data, "OUT_SWE_BAND", varnum++, "%.4f", OUT_TYPE_FLOAT, 1); set_output_var(out_data_files, TRUE, filenum, out_data, "OUT_SNOW_DEPTH_BAND", varnum++, "%.4f", OUT_TYPE_FLOAT, 1); set_output_var(out_data_files, TRUE, filenum, out_data, "OUT_SNOW_CANOPY_BAND", varnum++, "%.4f", OUT_TYPE_FLOAT, 1); if (options.FULL_ENERGY) { set_output_var(out_data_files, TRUE, filenum, out_data, "OUT_ADVECTION_BAND", varnum++, "%.4f", OUT_TYPE_FLOAT, 1); set_output_var(out_data_files, TRUE, filenum, out_data, "OUT_DELTACC_BAND", varnum++, "%.4f", OUT_TYPE_FLOAT, 1); set_output_var(out_data_files, TRUE, filenum, out_data, "OUT_SNOW_FLUX_BAND", varnum++, "%.4f", OUT_TYPE_FLOAT, 1); set_output_var(out_data_files, TRUE, filenum, out_data, "OUT_RFRZ_ENERGY_BAND", varnum++, "%.4f", OUT_TYPE_FLOAT, 1); } set_output_var(out_data_files, TRUE, filenum, out_data, "OUT_NET_SHORT_BAND", varnum++, "%.4f", OUT_TYPE_FLOAT, 1); set_output_var(out_data_files, TRUE, filenum, out_data, "OUT_NET_LONG_BAND", varnum++, "%.4f", OUT_TYPE_FLOAT, 1); set_output_var(out_data_files, TRUE, filenum, out_data, "OUT_ALBEDO_BAND", varnum++, "%.4f", OUT_TYPE_FLOAT, 1); set_output_var(out_data_files, TRUE, filenum, out_data, "OUT_LATENT_BAND", varnum++, "%.4f", OUT_TYPE_FLOAT, 1); set_output_var(out_data_files, TRUE, filenum, out_data, "OUT_SENSIBLE_BAND", varnum++, "%.4f", OUT_TYPE_FLOAT, 1); set_output_var(out_data_files, TRUE, filenum, out_data, "OUT_GRND_FLUX_BAND", varnum++, "%.4f", OUT_TYPE_FLOAT, 1); } if (options.LAKES) { filenum++; varnum = 0; set_output_var(out_data_files, TRUE, filenum, out_data, "OUT_LAKE_ICE_TEMP", varnum++, "%.4f", OUT_TYPE_FLOAT, 1); set_output_var(out_data_files, TRUE, filenum, out_data, "OUT_LAKE_ICE_HEIGHT", varnum++, "%.4f", OUT_TYPE_FLOAT, 1); set_output_var(out_data_files, TRUE, filenum, out_data, "OUT_LAKE_ICE_FRACT", varnum++, "%.4f", OUT_TYPE_FLOAT, 1); set_output_var(out_data_files, TRUE, filenum, out_data, "OUT_LAKE_DEPTH", varnum++, "%.4f", OUT_TYPE_FLOAT, 1); set_output_var(out_data_files, TRUE, filenum, out_data, "OUT_LAKE_SURF_AREA", varnum++, "%.4f", OUT_TYPE_FLOAT, 1); set_output_var(out_data_files, TRUE, filenum, out_data, "OUT_LAKE_VOLUME", varnum++, "%.4f", OUT_TYPE_FLOAT, 1); set_output_var(out_data_files, TRUE, filenum, out_data, "OUT_LAKE_SURF_TEMP", varnum++, "%.4f", OUT_TYPE_FLOAT, 1); set_output_var(out_data_files, TRUE, filenum, out_data, "OUT_EVAP_LAKE", varnum++, "%.4f", OUT_TYPE_FLOAT, 1); } #endif //OUTPUT_FORCE return out_data_files; }
/****************************************************************************** * @brief Get output info from global parameter file. *****************************************************************************/ void parse_output_info(FILE *gp, stream_struct **streams, dmy_struct *dmy_current) { extern option_struct options; char cmdstr[MAXSTRING]; char optstr[MAXSTRING]; char flgstr[MAXSTRING]; short int streamnum; char varname[MAXSTRING]; int outvarnum; char freq_type_str[MAXSTRING]; char freq_value_str[MAXSTRING]; char format[MAXSTRING]; char typestr[MAXSTRING]; int type; char multstr[MAXSTRING]; char aggstr[MAXSTRING]; double mult; unsigned short int freq; int freq_n; dmy_struct freq_dmy; unsigned short int agg_type; int found; streamnum = -1; // rewind the global parameter file to the begining and parse only the // output file info. rewind(gp); fgets(cmdstr, MAXSTRING, gp); /** Read through global control file to find output info **/ while (!feof(gp)) { if (cmdstr[0] != '#' && cmdstr[0] != '\n' && cmdstr[0] != '\0') { sscanf(cmdstr, "%s", optstr); if (strcasecmp("OUTFILE", optstr) == 0) { streamnum++; if (streamnum >= (short int) options.Noutstreams) { log_err("Found too many output files, was expecting " "%zu but found %hu", options.Noutstreams, streamnum); } if (sscanf(cmdstr, "%*s %s", (*streams)[streamnum].prefix) != 1) { log_err("Invalid specification for OUTFILE"); } // set default file format (*streams)[streamnum].file_format = NETCDF4_CLASSIC; outvarnum = 0; } else if (strcasecmp("AGGFREQ", optstr) == 0) { if (streamnum < 0) { log_err("Error in global param file: \"OUTFILE\" must be " "specified before you can specify \"AGGFREQ\"."); } found = sscanf(cmdstr, "%*s %s %s", freq_type_str, freq_value_str); if (!found) { log_err("No arguments found after AGGFREQ"); } // parse the frequency string to an enum value freq = str_to_freq_flag(freq_type_str); if (freq == FREQ_DATE) { // Make sure we have a datestring if (found != 2) { log_err( "AGGFREQ was set to DATE but no date string was found"); } // parse date from freq_value_str strpdmy(freq_value_str, "%Y-%m-%d", &freq_dmy); // set the alarm set_alarm(dmy_current, freq, &freq_dmy, (&(*streams)[streamnum].agg_alarm)); } else { if (found != 2) { // Default frequency is 1 freq_n = 1; } else { // get the frequency value as an integer freq_n = atoi(freq_value_str); } // set the alarm set_alarm(dmy_current, freq, &freq_n, (&(*streams)[streamnum].agg_alarm)); } } else if (strcasecmp("HISTFREQ", optstr) == 0) { if (streamnum < 0) { log_err("Error in global param file: \"OUTFILE\" must be " "specified before you can specify \"HISTFREQ\"."); } found = sscanf(cmdstr, "%*s %s %s", freq_type_str, freq_value_str); if (!found) { log_err("No arguments found after HISTFREQ"); } // parse the frequency string to an enum value freq = str_to_freq_flag(freq_type_str); if (freq == FREQ_DATE) { // Make sure we have a datestring if (found != 2) { log_err( "HISTFREQ was set to DATE but no date string was found"); } // parse date from freq_value_str strpdmy(freq_value_str, "%Y-%m-%d", &freq_dmy); // set the alarm set_alarm(dmy_current, freq, &freq_dmy, (&(*streams)[streamnum].write_alarm)); } else { if (found != 2) { // Default frequency is 1 freq_n = 1; } else { // get the frequency value as an integer freq_n = atoi(freq_value_str); } // set the alarm set_alarm(dmy_current, freq, &freq_n, (&(*streams)[streamnum].write_alarm)); } } else if (strcasecmp("COMPRESS", optstr) == 0) { if (streamnum < 0) { log_err("Error in global param file: \"OUTFILE\" must be " "specified before you can specify \"COMPRESS\"."); } sscanf(cmdstr, "%*s %s", flgstr); if (strcasecmp("TRUE", flgstr) == 0) { (*streams)[streamnum].compress = COMPRESSION_LVL_DEFAULT; } else if (strcasecmp("FALSE", flgstr) == 0) { (*streams)[streamnum].compress = 0; } else { (*streams)[streamnum].compress = atoi(flgstr); } } else if (strcasecmp("OUT_FORMAT", optstr) == 0) { if (streamnum < 0) { log_err("Error in global param file: \"OUTFILE\" must be " "specified before you can specify \"OUT_FORMAT\"."); } sscanf(cmdstr, "%*s %s", flgstr); if (strcasecmp("NETCDF3_CLASSIC", flgstr) == 0) { (*streams)[streamnum].file_format = NETCDF3_CLASSIC; } else if (strcasecmp("NETCDF3_64BIT_OFFSET", flgstr) == 0) { (*streams)[streamnum].file_format = NETCDF3_64BIT_OFFSET; } else if (strcasecmp("NETCDF4_CLASSIC", flgstr) == 0) { (*streams)[streamnum].file_format = NETCDF4_CLASSIC; } else if (strcasecmp("NETCDF4", flgstr) == 0) { (*streams)[streamnum].file_format = NETCDF4; } else { log_err( "Image driver file format must be a valid NETCDF format"); } } else if (strcasecmp("OUTVAR", optstr) == 0) { if (streamnum < 0) { log_err("Error in global param file: \"OUTFILE\" must be " "specified before you can specify \"OUTVAR\"."); } // parse outvar options strcpy(varname, ""); strcpy(format, ""); strcpy(typestr, ""); strcpy(multstr, ""); strcpy(aggstr, ""); found = sscanf(cmdstr, "%*s %s %s %s %s %s", varname, format, typestr, multstr, aggstr); if (!found) { log_err("OUTVAR specified but no variable was listed"); } // interpret string options, set defaults if necessary str_to_ascii_format(format); agg_type = str_to_agg_type(aggstr); type = str_to_out_type(typestr); mult = str_to_out_mult(multstr); // Add OUTVAR to stream set_output_var(&((*streams)[streamnum]), varname, outvarnum, format, type, mult, agg_type); outvarnum++; } } fgets(cmdstr, MAXSTRING, gp); } }