Ecological Landscape Modeling: Models Pages |
#include "generic_driver.h"
Go to the source code of this file.
Functions | |
int | main (int argc, char *argv[]) |
Main program loop. | |
void | setup () |
Controller to call functions to set up & initialize the model. | |
void | get_parmf () |
Get user's run-time parameters from configuration file. | |
void | track_time (int istep) |
Keep track of simulation time. | |
int | PTSL_test () |
Test for presence of point-time series meteorological data. | |
int | ModExperim_test () |
Test for presence of special parameter file for model experiments. |
This source file contains the main calling function to drive the model, including initial set-up:
main: Main program loop
setup: Controller to call functions to set up & initialize the model
get_parmf: Get user's run-time parameters from configuration file
track_time: Keep track of simulation time
PTSL_test: Determine method of input of meteorological data
Note: documented with Doxygen, which expects specific syntax within special comments.
The Everglades Landscape Model (ELM).
last updated: Mar 2008
Definition in file Generic_Driver.c.
int main | ( | int | argc, | |
char * | argv[] | |||
) |
Main program loop.
The main controlling function used by model, which sets up the program and executes the driving temporal loop.
argc | number of command line arguments | |
argv | command line argument |
Definition at line 65 of file Generic_Driver.c.
References alloc_memory(), call_cell_dyn(), simTime::da, da_end, da_in, da_R_in, debug, dynERRORnum, ESPmodeON, FMOD(), gen_output(), HabSwitchOn, init_canals(), init_dynam_data(), init_eqns(), init_static_data(), init_succession(), iSector, isModExperim, isPTSL, IsSubstituteModel, istep, local_setup(), MAX_PTSERIES, simTime::mo, mo_end, mo_in, mo_R_in, ModExperim_test(), msgStr, N_iter, NSector, numRuns(), open_debug_outFile(), open_point_lists(), OS_TYPE, OutputPath, PositAnalOn, procnum, ProgExec, ProjName, pSeries, PtInterp_read(), PTSL_test(), read_model_parameters(), read_output_parms(), reinitBIR(), reinitCanals(), RunList, prog_attr::S_ParmName, prog_attr::S_ParmRelVal, send_point_lists2(), SensiOn, SensiParm_list(), setup(), SimTime, sync_processors(), simTime::TIME, track_time(), usrErr(), usrErr0(), view, WatMgmtOn, WriteMsg(), simTime::yr, yr_end, and yr_in.
00066 { 00081 int i; 00082 int runSeq; 00083 int RunNum; 00084 int totRuns; 00085 int NumSRunsPerSet = 2; /* TODO: for now its always 2 (a low and a high value of parm(s)... code not set up for diff value, though */ 00086 int SParmNum=0; 00087 int parmID; 00088 00089 ViewParm *view; 00090 dynERRORnum = 0; 00091 time_t begin_sim, end_sim; 00092 struct tm *local_begin_time; /* struct holding real-time calendar time from standard time.h */ 00093 00094 /* a couple of items that use the standard time.h to clock the simulation runtime*/ 00095 begin_sim = time(NULL); 00096 local_begin_time = localtime(&begin_sim); 00097 00098 local_setup(argc, argv); /* not much here for serial implementation; establish processor attributes (parallel)*/ 00099 setup(); 00100 alloc_memory(); 00101 00102 isPTSL = PTSL_test(); /* v2.6 test for presence of data file (isPTSL=true) indicating use of on-the-fly interpolaters 00103 for point time series meteorological data, instead of SFWMM gridIO spatial time series data */ 00104 00105 isModExperim = ModExperim_test(); /* v2.6 test for presence of data file (isModExperim=true) indicating use of 00106 special parameters used in model experiments (not used for normal applications) */ 00107 00108 00109 if (isPTSL) PtInterp_read(); /* v2.6 PTSL TODO: ensure this is compatible with sensi analysis within this sequence (does it use the correct data-interpolations?) */ 00110 00111 read_model_parameters( ProgExec->S_ParmName, ProgExec->S_ParmRelVal ); 00112 00113 if (SensiOn) SParmNum = SensiParm_list(ProgExec->S_ParmName); 00114 RunNum = numRuns(SParmNum, NumSRunsPerSet); 00115 00116 init_static_data(); 00117 00118 totRuns = RunNum; 00119 00120 /* new simulations can be started within this while ( ) (for sensitivity analyses, Position Analysis, other in future) */ 00121 while (RunNum) { 00122 RunNum--; /* decrement the number of complete simulations runs during program execution (pertinent to multiple sensitivity analysis runs) */ 00123 runSeq= totRuns - RunNum; 00124 00125 sync_processors(); /* parallel only */ 00126 00127 open_debug_outFile(runSeq); /* the file Driver1.out (and DriverX.out for X'th subsequent sensitivity run) is opened for writing general messages 00128 (warnings, errors, and data depending on debug level) */ 00129 00130 if (runSeq == 1) { 00131 usrErr0("Reading output requests..."); 00132 view = read_output_parms(); /* reading model.outlist */ 00133 usrErr("Done output requests."); 00134 } 00135 00136 if (SensiOn) { 00137 parmID = (int) (runSeq)/NumSRunsPerSet; 00138 ProgExec = RunList[parmID]; 00139 00140 if (runSeq > 1) { 00141 ProgExec->S_ParmRelVal = ProgExec->S_ParmRelVal+1 ; 00142 read_model_parameters( ProgExec->S_ParmName, ProgExec->S_ParmRelVal ); 00143 reinitBIR(); /* re-init the Basin/Ind. Region datav */ 00144 } 00145 sprintf(msgStr,"\nSENSITIVITY ANALYSIS: Run %d of %d, relative-value parm ID= %d in %s set.", 00146 runSeq, totRuns, ProgExec->S_ParmRelVal, ProgExec->S_ParmName ); 00147 usrErr(msgStr); 00148 WriteMsg(msgStr,1); 00149 00150 } 00151 00152 init_dynam_data(); 00153 init_eqns(); 00154 if (WatMgmtOn) init_canals(runSeq); 00155 if (HabSwitchOn) init_succession(); 00156 00157 usrErr0("Calling dynamic ecological modules:\n\t"); 00158 for (i=0; i<NSector; i++) { 00159 sprintf(msgStr, "%d, ", iSector[i]); 00160 usrErr0(msgStr); 00161 } 00162 00163 /* v2.8 - added feature to replace all ELM hydrologic calcs, substituting the Boundary Condition Model's 00164 "stage_minus_landElevation" variable into ELM hydro variables. 00165 This was done in order to post-process the SFWMM or NSM using the same procedures as ELM 00166 The below true/false flag tests for that condition, where user is requesting to only run cell_dyn1 (and stats, case #99) in UnitMod.c */ 00167 IsSubstituteModel = ( (NSector == 2) && (iSector[0] == 1) && (iSector[1] == 99) ) ? (1) : (0); 00168 00169 /* for Position Analysis, where the model is re-initialized at a recurring interval */ 00170 if(PositAnalOn) { 00171 sprintf(msgStr, "\n\t***running %2d/%2d Position Analysis*** ",mo_R_in,da_R_in); 00172 usrErr0(msgStr); 00173 } 00174 00175 /* ESP (Everglades Settling-of Phosphorus, i.e., EWQModel emulation) mode. */ 00176 if (ESPmodeON) usrErr0("\n\t***running ESP*** "); 00177 00178 if (WatMgmtOn) usrErr0("\n\twith spatial water managment 'on' "); 00179 else usrErr0("\n\twith spatial water managment 'off' "); 00180 00181 if (HabSwitchOn) usrErr("and succession 'on'."); 00182 else usrErr("and succession 'off'."); 00183 00184 sprintf(msgStr,"\n*** Running simulation from %d/%d/%d to %d/%d/%d ***", 00185 yr_in,mo_in,da_in, yr_end,mo_end,da_end ); 00186 usrErr(msgStr); 00187 00188 /***************/ 00189 /* temporal loop for driving model */ 00190 for(istep=0; istep<N_iter; istep++) { 00191 00192 track_time(istep); 00193 00194 /* when testing/debugging new code/data, allow critical ERRORs to accumulate to aid in identifying problem - then get out. 00195 This exit is particularly important with new users, who may configure data sets improperly, resulting in a model 00196 that runs merrily along, but accumulates a massive DriverX.out (for X'th simulation run) file w/ errors (exceeding file size limit of OS) */ 00197 if (dynERRORnum > 500) { 00198 sprintf(msgStr,"\n\n***Sorry! Exiting because of many (%d) ERROR and/or capacityERR messages.\n***See the %s/%s/Debug/DriverX.out (for X'th simulation run) file to determine how to fix things.",dynERRORnum, OutputPath, ProjName); 00199 usrErr(msgStr); 00200 exit(-1); 00201 } 00202 00203 if (PositAnalOn) { /* for Position Analysis, where the model is re-initialized at a recurring interval */ 00204 if ( (SimTime.mo[0] == mo_R_in) && (SimTime.da[0] == da_R_in) ) { 00205 usrErr0("\nPOSITION ANALYSIS: Re-initializing..."); 00206 init_dynam_data(); 00207 init_eqns(); 00208 reinitCanals(); 00209 reinitBIR(); /* missing init_succession */ 00210 usrErr("Done re-initializing."); 00211 } 00212 } 00213 if(debug >3) { /* long console output at this high debug level */ 00214 sprintf(msgStr,"---------------------------------------Iteration = %d\n",istep); 00215 WriteMsg(msgStr,1); usrErr(msgStr); 00216 } 00217 else 00218 { /* print the year/month/day to console - this will be appended with horizontal iteration info later */ 00219 sprintf(msgStr,"\r%d/%2d/%2d: ",SimTime.yr[0],SimTime.mo[0],SimTime.da[0] ); 00220 usrErr0(msgStr); /* calendar date */ 00221 } 00222 00223 /* call dynamic calculations */ 00224 for(i=0; i<NSector; i++) { /* for each dynamic ecological (including hydrology) sector(module) */ 00225 00226 if(debug >3) { /* long console output at this high debug level */ 00227 sprintf(msgStr,"Running cell dyn %d of %d\n",iSector[i],NSector); 00228 WriteMsg(msgStr,1); 00229 usrErr(msgStr); 00230 } 00231 call_cell_dyn(iSector[i],istep); /* invoke the UnitMod.c calling function for dynamic ecological modules */ 00232 } 00233 00234 /* generate output (incl. point time series) */ 00235 if((istep >= 0 && istep <= N_iter) ) { 00236 if(debug >3) { /* long console output at this high debug level */ 00237 usrErr(""); /* carriage return following hydstep iterations */ 00238 sprintf(msgStr,"(%d)Generating Output",procnum); WriteMsg(msgStr,1); usrErr(msgStr); 00239 } 00240 gen_output(istep, view); /* the generates all spatial output */ 00241 } 00242 00243 /* send point time series output to disk at this interval */ 00244 if ( FMOD(SimTime.TIME, 180.0) == 0 ) { 00245 if (istep == 0) open_point_lists(pSeries,MAX_PTSERIES); /* at start of sim, open point timeseries files */ 00246 send_point_lists2(pSeries,MAX_PTSERIES); 00247 } 00248 } /* end of temporal loop for driving model */ 00249 /***************/ 00250 00251 /* send the remaining time accumulated of point time series output to disk at end of simulation */ 00252 send_point_lists2(pSeries,MAX_PTSERIES); 00253 00254 end_sim = time(NULL); 00255 /* print the simulation start date:time, and the elapsed cpu time, to DriverX.out (for X'th simulation run) file (& elapsed to console) */ 00256 sprintf(msgStr,"########\nThe simulation(s) started on: %s", asctime(local_begin_time) ); WriteMsg(msgStr,1); 00257 sprintf(msgStr,"\nEND. The simulation(s) took %8.3f minutes to run using your %s OS box.\n########",( (end_sim-begin_sim)/60.0), OS_TYPE ); WriteMsg(msgStr,1); usrErr(msgStr); 00258 00259 } /* end of the while (RunNum) and thus end of simulation(s) (plural if running sensitivity) */ 00260 00261 return 0; 00262 } /* end of main and thus program execution */
void setup | ( | ) |
Controller to call functions to set up & initialize the model.
Several function calls here effectively do nothing in serial (i.e., non-parallel) implementations.
Definition at line 269 of file Generic_Driver.c.
References get_map_dims(), get_parmf(), MAX_PTSERIES, pSeries, set_env_vars(), setup_grid(), and setup_platform().
Referenced by main().
00270 { 00271 int i; 00272 for(i=0; i<MAX_PTSERIES; i++) pSeries[i].data = NULL; /* initialize Point Time Series arrays */ 00273 setup_platform(); /* effectively unused in serial (non-parallel) implementation */ 00274 set_env_vars(); /* get necessary enviroment variables */ 00275 get_parmf(); /* get the run-time parameters */ 00276 get_map_dims(); /* get the row-column dimensions of the global model array size */ 00277 setup_grid(); /* set up a grid size used in memory allocations (other stuff for parallel) */ 00278 }
void get_parmf | ( | ) |
Get user's run-time parameters from configuration file.
This is where the application is set up by the user's edits to the Driver.parm text configuration file, providing the simulation start and end dates, grid cell size, debug level, model scenario name, etc.
Definition at line 288 of file Generic_Driver.c.
References alloc_mem_runs(), avg_Intvl, avgCalendar, BIRhyd_avg_Intvl, BIRhydCalendar, broadcastInt(), budg_Intvl, budgCalendar, can_Intvl, canalCalendar, canstep, CELL_SIZE, celWid, da_end, da_in, da_R_in, seriesParm::data, dbgPt, debug, dt, ESPmodeON, False, getFloat(), getInt(), getString(), gwstep, HabSwitchOn, hr_in, hyd_iter, initDateRead, iSector, Jdate_end, Jdate_init, julday(), MAX_PTSERIES, mi_in, mo_end, mo_in, mo_R_in, modelName, ModelPath, modelVers, msgStr, N_iter, NSector, open_debug_outFile(), outpath, OutputPath, PORnumday, PositAnalOn, procnum, ProgExec, ProjName, pSeries, RunList, prog_attr::S_ParmName, prog_attr::S_ParmRelVal, scan_forward(), se_in, sec_per_day, seed, SensiOn, sfstep, SimAlt, SimModif, skip_white(), sq_celWid, step_Cell, True, usrErr(), WatMgmtOn, WriteMsg(), point2D::x, point2D::y, yr_end, and yr_in.
Referenced by setup().
00289 { 00300 int i=0, stop=0; 00301 unsigned char ch; 00302 FILE *infile; 00303 char filename[120], ss[120]; 00304 char Re_initDateRead[15], endDateRead[15]; 00305 int SParmNum_TEMP = 150; /* TODO: will get this from reading the senitivity-parameter list */ 00306 00307 sprintf(filename,"%s/%s/RunParms/Driver.parm",ModelPath,ProjName); 00308 infile = fopen(filename,"r"); 00309 if(infile==NULL) { fprintf(stderr,"Error, can't open file %s",filename); exit(0); } 00310 00311 00312 fgets(ss,120,infile); 00313 sscanf(ss,"%s",outpath); 00314 OutputPath = (char*)&outpath; /* path for all output */ 00315 open_debug_outFile(0); /* opens the Driver0.out debug file */ 00316 00317 /* start date */ 00318 fgets(ss,120,infile); 00319 sscanf(ss,"%s",initDateRead); /* read in as yyyy/mm/dd format */ 00320 00321 sprintf(msgStr,"initDateRead=%s\n",initDateRead); WriteMsg(msgStr,1); 00322 sscanf(initDateRead, "%4d/%2d/%2d,",&yr_in,&mo_in,&da_in); /* starting date of sim */ 00323 00324 /* julian day, returns a double (args = month, day, year, hour, minute, second) */ 00325 Jdate_init = julday(mo_in, da_in, yr_in, hr_in, mi_in, se_in); 00326 00327 00328 /* end date */ 00329 fgets(ss,120,infile); 00330 sscanf(ss,"%s",endDateRead); /* read in as yyyy/mm/dd format */ 00331 00332 sprintf(msgStr,"endDateRead=%s\n",endDateRead); WriteMsg(msgStr,1); 00333 sscanf(endDateRead, "%4d/%2d/%2d,",&yr_end,&mo_end,&da_end); /* ending date of sim */ 00334 00335 /* julian day, returns a double (args = month, day, year, hour, minute, second) */ 00336 Jdate_end = julday(mo_end, da_end, yr_end, hr_in, mi_in, se_in); 00337 00338 /* re-initialization date */ 00339 fgets(ss,120,infile); 00340 sscanf(ss,"%s",Re_initDateRead); /* read in as mm/dd format */ 00341 00342 sprintf(msgStr,"Re_initDateRead=%s\n",Re_initDateRead); WriteMsg(msgStr,1); 00343 sscanf(Re_initDateRead, "%2d/%2d,",&mo_R_in,&da_R_in); /* re-initialize month/day */ 00344 00345 if (mo_R_in>0) { 00346 PositAnalOn=True; /* in position analysis mode, we re-initialize every year on same month/day */ 00347 sprintf(msgStr,"\n *** WARNING: Position Analysis capabilities are NOT VERIFIED FOR accuracy/consistency in ELMv2.3 - the Avg's, Basin/Indicator-Region output may not be reliable ***\n"); 00348 WriteMsg(msgStr,1); 00349 usrErr(msgStr); 00350 } /* TODO: fix the budget/stats re-inits for Position Analysis mode */ 00351 00352 fgets(ss,120,infile); 00353 sscanf(ss,"%s",modelName); 00354 sprintf(msgStr, "Model Name= %s", modelName); usrErr(msgStr); WriteMsg(msgStr,1); 00355 getString(infile,"Model version=",modelVers); /* model version number (eg., v.2.1) */ 00356 sprintf(msgStr,"Model version=%s\n",modelVers); WriteMsg(msgStr,1); 00357 00358 getFloat(infile,"CellArea=",&CELL_SIZE); 00359 sprintf(msgStr,"CellArea=%f\n",CELL_SIZE); WriteMsg(msgStr,1); 00360 celWid = sqrt(CELL_SIZE); /* cell width, used in number of hydro calcs */ 00361 sq_celWid = sqrt(celWid); /* square root of cell width, used in number of hydro calcs */ 00362 00363 00364 getFloat(infile,"budg_Intvl=",&budg_Intvl); 00365 sprintf(msgStr,"budg_Intvl=%f\n",budg_Intvl); WriteMsg(msgStr,1); 00366 budgCalendar = ( budg_Intvl == 0.0 ) ? (True) : (False); /* true/false flag signifying use of gregorian calendar for budget calcs 00367 a budg_Intvl of 0 days defaults to gregorian calendar-month 00368 intervals ( = #days/month, diff among months/years) 00369 In this case, the true/false budgCalendar flag is set to True */ 00370 00371 getFloat(infile,"BIRhyd_avg_Intvl=",&BIRhyd_avg_Intvl); 00372 sprintf(msgStr,"BIRhyd_avg_Intvl=%f\n",BIRhyd_avg_Intvl); WriteMsg(msgStr,1); 00373 BIRhydCalendar = ( BIRhyd_avg_Intvl == 0.0 ) ? (True) : (False); /* true/false flag signifying use of gregorian calendar for BIR hydro calcs 00374 a BIRhyd_avg_Intvl of 0 days defaults to gregorian calendar-month 00375 intervals ( = #days/month, diff among months/years) 00376 In this case, the true/false budgCalendar flag is set to True */ 00377 00378 getFloat(infile,"avg_Intvl=",&avg_Intvl); 00379 sprintf(msgStr,"avg_Intvl=%f\n",avg_Intvl); WriteMsg(msgStr,1); 00380 if ( avg_Intvl == 0 ) avgCalendar = True; /* true/false flag signifying use of gregorian calendar for recurring averaging calcs 00381 an avg_Intvl of 0 days defaults to gregorian calendar-month 00382 intervals ( = #days/month, diff among months/years) 00383 In this case, the true/false avgCalendar flag is set to True */ 00384 00385 getFloat(infile,"can_Intvl=",&can_Intvl); 00386 sprintf(msgStr,"can_Intvl=%f\n",can_Intvl); WriteMsg(msgStr,1); 00387 if ( can_Intvl == 0 ) canalCalendar = True; /* true/false flag signifying use of gregorian calendar for recurring canal (watmanage) calcs 00388 a can_Intvl of 0 days defaults to gregorian calendar-month 00389 intervals ( = #days/month, diff among months/years) 00390 In this case, the true/false can_Intvl flag is set to True */ 00391 00392 getInt(infile,"seed=",&seed); 00393 sprintf(msgStr,"seed=%d\n",seed); WriteMsg(msgStr,1); 00394 getFloat(infile,"dt=",&dt); 00395 sprintf(msgStr,"dt=%f\n",(double)dt); WriteMsg(msgStr,1); 00396 getInt(infile,"hyd_iter=",&hyd_iter); 00397 sprintf(msgStr,"hyd_iter=%d\n",hyd_iter); WriteMsg(msgStr,1); 00398 00399 sfstep = dt/hyd_iter; /* time step for cell-cell overland flows */ 00400 gwstep = dt/(hyd_iter/2); /* time step for cell-cell ground water flows (twice as long as surface water)*/ 00401 canstep = dt/hyd_iter; /* time step for canal flows */ 00402 step_Cell = sq_celWid * sfstep/CELL_SIZE * sec_per_day; /* constant used in horizontal surface water raster flux equations */ 00403 00404 N_iter= (Jdate_end - Jdate_init + 1)/dt; 00405 sprintf(msgStr,"N_iter=%d\n",N_iter); WriteMsg(msgStr,1); 00406 PORnumday = (int)(Jdate_end - Jdate_init + 1); /* number of days of simulation Period Of Record */ 00407 00408 getInt(infile,"debug=",&debug); 00409 sprintf(msgStr,"debug=%d\n",debug); WriteMsg(msgStr,1); 00410 getInt(infile,"debug_point=",&dbgPt.x); 00411 getInt(infile,NULL,&dbgPt.y); 00412 sprintf(msgStr,"debug point= (%d,%d)\n",dbgPt.x,dbgPt.y); WriteMsg(msgStr,1); 00413 00414 alloc_mem_runs(SParmNum_TEMP); 00415 RunList[0] = ProgExec; /* nominal parameter set */ 00416 00417 getString(infile,"S_ParmName=",ProgExec->S_ParmName); /* value can be: 00418 1) "NONE", for no sensitivity analysis (nominal parameter set); 00419 2) the name of a global or habitat-specific parameter for a single-parm sensitivity analysis; 00420 3) "ALL", leading to multi-parameter sensitivity analyses on 00421 all parameters, to be read from an input list */ 00422 sprintf(msgStr,"S_ParmName=%s\n",ProgExec->S_ParmName); WriteMsg(msgStr,1); 00423 00424 SensiOn = (strcmp(ProgExec->S_ParmName,"NONE")!=0) ? (True) : (False); 00425 ProgExec->S_ParmRelVal = 0; /* first run of program is ALWAYS the nominal (no parameter-changes) run */ 00426 00427 getInt(infile,"HabSwitchOn=",&HabSwitchOn); /* flag to turn on habitat switching */ 00428 sprintf(msgStr,"HabSwitchOn=%d\n",HabSwitchOn); WriteMsg(msgStr,1); 00429 getInt(infile,"WatMgmtOn=",&WatMgmtOn); /* flag to turn on canal/water management */ 00430 sprintf(msgStr,"WatMgmtOn=%d\n",WatMgmtOn); WriteMsg(msgStr,1); 00431 00432 getString(infile,"Scenario=",SimAlt); /* simulation's scenario/alternative */ 00433 sprintf(msgStr,"SimAlt=%s\n",SimAlt); WriteMsg(msgStr,1); 00434 getString(infile,"Scenario modifier=",SimModif); /* simulation's scenario/alternative & modifier */ 00435 sprintf(msgStr,"SimModif=%s\n",SimModif); WriteMsg(msgStr,1); 00436 00437 scan_forward(infile,"Sectors="); i=0; stop=0; 00438 while(1) { 00439 skip_white(infile); 00440 ch=fgetc(infile); 00441 if( isdigit(ch) ) ungetc(ch,infile); 00442 else { 00443 switch (ch) { 00444 case ';': NSector = i; stop=1; break; 00445 case ',': skip_white(infile); break; 00446 } 00447 } 00448 if(stop) break; 00449 else fscanf(infile,"%d",&iSector[i++]); 00450 /* sector 13 is the ESP (Everglades Settling-of Phosphorus, i.e., EWQModel emulation) mode - this sets the ESPmodeON flag*/ 00451 if (iSector[i-1] == 13) ESPmodeON=1; 00452 00453 } 00454 fclose(infile); 00455 broadcastInt(&NSector); 00456 sprintf(msgStr,"\n(%d) NSector = %d: Sectors=",procnum,NSector); WriteMsg(msgStr,1); 00457 for(i=0; i<NSector; i++) { 00458 broadcastInt(&iSector[i]); 00459 sprintf(msgStr,"(%d:%d)",i,iSector[i]); WriteMsg(msgStr,1); 00460 } 00461 00462 for(i=0; i<MAX_PTSERIES; i++) if(pSeries[i].data) { free((char*)pSeries[i].data); pSeries[i].data = NULL; } 00463 }
void track_time | ( | int | istep | ) |
Keep track of simulation time.
The elapsed days, the gregorian and julian calendars, and several end-of calendar- month, year etc flags are updated with each iteration.
istep | counter for number of model time iterations |
Definition at line 473 of file Generic_Driver.c.
References avg_Intvl, avgCalendar, avgPrint, BIRavg_Intvl, BIRhyd_avg_Intvl, BIRhydCalendar, budg_Intvl, budgCalendar, calcdate(), can_Intvl, canalCalendar, canPrint, simTime::da, dryEndDay, dryEndMon, dt, False, simTime::hr, simTime::IsBIRavgEnd, simTime::IsBIRhydEnd, simTime::IsBudgEnd, simTime::IsBudgFirst, simTime::IsDay0, simTime::IsDrySeasEnd, simTime::IsMonthEnd, simTime::IsSimulationEnd, simTime::IsWetSeasEnd, simTime::IsYearEnd, simTime::Jdate, Jdate_init, simTime::mi, simTime::mo, N_iter, PORnumday, simTime::se, SensiOn, SimTime, simTime::TIME, True, wetEndDay, wetEndMon, and simTime::yr.
Referenced by main().
00474 { 00475 int yr_tom[2]; /* calendar year of tomorrow's model time */ 00476 int mo_tom[2]; /* calendar month of tomorrow's model time */ 00477 int da_tom[2]; /* calendar day of tomorrow's model time */ 00478 int hr_tom[2]; /* calendar hour of tomorrow's model time (unused in model calcs) */ 00479 int mi_tom[2]; /* calendar minute of tomorrow's model time (unused in model calcs) */ 00480 double se_tom[2]; /* calendar second of tomorrow's model time (unused in model calcs) */ 00481 00482 SimTime.TIME = istep*dt; 00483 SimTime.Jdate = Jdate_init+SimTime.TIME; /* increment the julian day counter */ 00484 00485 /* use calendar functions to determine the end-of status of today's date */ 00486 calcdate( (SimTime.Jdate+1), mo_tom, da_tom, yr_tom, hr_tom, mi_tom, se_tom); /* for TOMORROW, get the calendar date info from the julian date */ 00487 calcdate( SimTime.Jdate, SimTime.mo, SimTime.da, SimTime.yr, SimTime.hr, SimTime.mi, SimTime.se); /* for TODAY, get the calendar date info from the julian date */ 00488 00489 SimTime.IsMonthEnd = ( SimTime.mo[0] != mo_tom[0] ) ? (True) : (False); /* true/false flag signifying end of a gregorian calendar month */ 00490 SimTime.IsYearEnd = ( SimTime.yr[0] != yr_tom[0] ) ? (True) : (False); /* true/false flag signifying end of a gregorian calendar year */ 00491 SimTime.IsWetSeasEnd = (( SimTime.mo[0] == wetEndMon ) && (SimTime.da[0] == wetEndDay)) ? (True) : (False); /* true/false flag signifying end of a gregorian calendar-based wet season */ 00492 SimTime.IsDrySeasEnd = (( SimTime.mo[0] == dryEndMon ) && (SimTime.da[0] == dryEndDay)) ? (True) : (False); /* true/false flag signifying end of a gregorian calendar-based dry season */ 00493 SimTime.IsSimulationEnd = ((PORnumday-1)==istep) ? (True) : (False); 00494 00495 /* determine status of budget calc/printing flag (interval based on gregorian calendar or constant julian-day) */ 00496 if (!budgCalendar) { 00497 if ( fmod(SimTime.TIME, budg_Intvl) ==0) { 00498 /* not using gregorian calendar: at end of (constant) number of days, model time is end of budget interval */ 00499 SimTime.IsBudgEnd = True; 00500 } 00501 else { SimTime.IsBudgEnd = False; } 00502 } 00503 else { 00504 if ( SimTime.IsMonthEnd ) { 00505 /* using gregorian calendar: at calendar-month's end, model time is end of budget interval */ 00506 SimTime.IsBudgEnd = True; 00507 budg_Intvl= (float)SimTime.da[0]; /* dynamic interval becomes number of days in current gregorian-calendar month */ 00508 } 00509 else { SimTime.IsBudgEnd = False; } 00510 } 00511 00512 /* v2.8 determine status of BIR hydro calc/printing flag (interval based on gregorian calendar or constant julian-day) */ 00513 if (!BIRhydCalendar) { 00514 if ( fmod(SimTime.TIME, BIRhyd_avg_Intvl) ==0) { 00515 /* not using gregorian calendar: at end of (constant) number of days, model time is end of budget interval */ 00516 SimTime.IsBIRhydEnd = True; 00517 } 00518 else { SimTime.IsBIRhydEnd = False; } 00519 } 00520 else { 00521 if ( SimTime.IsMonthEnd ) { 00522 /* using gregorian calendar: at calendar-month's end, model time is end of budget interval */ 00523 SimTime.IsBIRhydEnd = True; 00524 BIRhyd_avg_Intvl = (float)SimTime.da[0]; /* dynamic interval becomes number of days in current gregorian-calendar month */ 00525 } 00526 else { SimTime.IsBIRhydEnd = False; } 00527 } 00528 00529 /* determine status of cell-specific averages calc/printing flag (interval based on gregorian calendar or constant julian-day) */ 00530 if (!avgCalendar) { 00531 if ( fmod(SimTime.TIME, avg_Intvl) ==0) { 00532 /* not using gregorian calendar: check for time (day) to finalize and print budgets for current interval */ 00533 avgPrint = True; } 00534 else { avgPrint = False; } 00535 } 00536 else { 00537 if ( SimTime.IsMonthEnd ) { 00538 /* using gregorian calendar: at month's end, it is time (day) to finalize and print budgets for current interval */ 00539 avgPrint = True; 00540 avg_Intvl= (float)SimTime.da[0]; /* interval becomes number of days in current gregorian-calendar month */ 00541 } 00542 else { avgPrint = False; } 00543 } 00544 00545 /* determine status of canal data calc/printing flag (interval based on gregorian calendar or constant julian-day) */ 00546 if (!canalCalendar) { 00547 if ( fmod(SimTime.TIME, can_Intvl) ==0) { 00548 /* not using gregorian calendar: check for time (day) to finalize and print canal data for current interval */ 00549 canPrint = True; } 00550 else { canPrint = False; } 00551 } 00552 else { 00553 if ( SimTime.IsMonthEnd ) { 00554 /* using gregorian calendar: at month's end, it is time (day) to finalize and print canal data for current interval */ 00555 canPrint = True; 00556 can_Intvl= (float)SimTime.da[0]; /* interval becomes number of days in current gregorian-calendar month */ 00557 } 00558 else { canPrint = False; } 00559 } 00560 00561 SimTime.IsBudgFirst = ( (SimTime.TIME/budg_Intvl) > 1 ) ? (False) : (True); 00562 SimTime.IsDay0 = (SimTime.TIME==0) ? (True) : (False); 00563 00564 /* TODO: this is to be generalized in MultiRun.c */ 00565 if (SensiOn) { 00566 BIRavg_Intvl = N_iter - 1; 00567 SimTime.IsBIRavgEnd = ( fmod(SimTime.TIME, BIRavg_Intvl) ==0) ? (True) : (False); 00568 00569 BIRhyd_avg_Intvl = N_iter - 1; 00570 SimTime.IsBIRhydEnd = ( fmod(SimTime.TIME, BIRhyd_avg_Intvl) ==0) ? (True) : (False); 00571 00572 budg_Intvl = N_iter - 1; 00573 SimTime.IsBudgEnd = ( fmod(SimTime.TIME, budg_Intvl) ==0) ? (True) : (False); 00574 } 00575 else { 00576 BIRavg_Intvl = budg_Intvl; 00577 SimTime.IsBIRavgEnd = SimTime.IsBudgEnd; 00578 } 00579 00580 }
int PTSL_test | ( | ) |
Test for presence of point-time series meteorological data.
Most ELM applications, and particularly the regional applications, input the binary "gridIO" spatial time series data for rain and potential ET. For some fine- scaled applications, the gridIO data may be too coarse, or there may be a desire for longer simulation periods than available in the gridIO data. In those cases, if the data file named "rain.pts" (which defines the grid locations of associated time series data) exists in the application's Data directory, the simulation will attempt to use those point data for generating rainfall maps on the fly. If that is true, the "pET.pts" will also be assumed to exist (to generate potential ET maps on the fly). Finally, for these applications that generate interpolated meteorological maps on the fly, we currently (v2.6) do not use the gridIO data output from the SFWMM for depths along the ELM domain border. A more flexible data-approach may be encoded if/when needed in the future.
New function in v2.6
Definition at line 599 of file Generic_Driver.c.
References ModelPath, and ProjName.
Referenced by main().
00600 { 00601 FILE *testfile; 00602 char filename[120], ss[120]; 00603 00604 sprintf(filename,"%s/%s/Data/rain.pts",ModelPath,ProjName); 00605 testfile = fopen(filename,"r"); 00606 if(testfile==NULL) 00607 return 0; /* the point data file does not exist, will use gridIO data */ 00608 else 00609 { fclose(testfile); return 1; } /* the point data file exists, will use on-the-fly interpolations of point data */ 00610 }
int ModExperim_test | ( | ) |
Test for presence of special parameter file for model experiments.
Most ELM applications, and particularly the regional applications, use the standard (GlobalParms and HabParms) parameter files. In special model research experiments, another parameter file may be used for specific questions. In v2.6, this is only used to modify stage/depth boundary conditions for fine-scale, long-term subregional applications.
New function in v2.6
Definition at line 622 of file Generic_Driver.c.
References ModelPath, and ProjName.
Referenced by main().
00623 { 00624 FILE *testfile; 00625 char filename[120], ss[120]; 00626 00627 sprintf(filename,"%s/%s/Data/ModExperimParms_NOM",ModelPath,ProjName); 00628 testfile = fopen(filename,"r"); 00629 if(testfile==NULL) 00630 return 0; /* the point data file does not exist, will not use any special parameters */ 00631 else 00632 { fclose(testfile); return 1; } /* the model experiment parameter file exists, will use special parameters */ 00633 }