Everglades Landscape Model (ELM) Home Page
Main Page | Data Structures | Directories | File List | Data Fields | Globals

Generic_Driver.c File Reference

The main model-driving functions. Vroom vroom. More...

#include "generic_driver.h"

Include dependency graph for Generic_Driver.c:

Include dependency graph

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.


Detailed Description

The main model-driving functions. Vroom vroom.

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

Note: documented with Doxygen, which expects specific syntax within special comments.

The Everglades Landscape Model (ELM).
last updated: Jan 2005

Definition in file Generic_Driver.c.


Function Documentation

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.

Parameters:
argc number of command line arguments
argv command line argument
Returns:
0

Variables local to function
runSeq An increasing counter of number of new simulations per program execution (sensitivity analysis)
RunNum The number of complete simulations runs during program execution (decremented w/ new simulations)
totRuns total number of simulations per program execution (sensitivity analysis)
NumSRunsPerSet number of simulation runs per set of parameter-evaluations (sensitivity analysis)
SParmNum the number of parameters to be evaluated in a sensitivity analysis
parmID The array/list identifier of the parameters to be evaluated in a sensitivity analysis
view A struct of ViewParm output command configuration
dynERRORnum counter of cumulative number of important ERRORs in dynamic calculations (used to halt sim)
begin_sim real-time beginning time of simulation
end_sim real-time ending time of simulation
local_begin_time struct holding real-time calendar time from standard time.h

Definition at line 58 of file Generic_Driver.c.

References alloc_memory(), call_cell_dyn(), simTime::da, da_end, da_in, da_R_in, debug, dynERRORnum, FMOD(), gen_output(), init_canals(), init_dynam_data(), init_eqns(), init_static_data(), init_succession(), iSector, istep, local_setup(), MAX_PTSERIES, simTime::mo, mo_end, mo_in, mo_R_in, msgStr, NSector, numRuns(), open_debug_outFile(), open_point_lists(), OS_TYPE, OutputPath, procnum, ProgExec, ProjName, pSeries, read_model_parameters(), read_output_parms(), reinitBIR(), reinitCanals(), RunList, prog_attr::S_ParmName, prog_attr::S_ParmRelVal, send_point_lists2(), SensiParm_list(), setup(), SimTime, sync_processors(), simTime::TIME, track_time(), usrErr(), usrErr0(), view, ViewParm, WriteMsg(), simTime::yr, yr_end, and yr_in.

00059 {
00074     int i;
00075     int runSeq;
00076     int RunNum;
00077     int totRuns;
00078     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 */
00079     int SParmNum=0; 
00080     int parmID;
00081 
00082     ViewParm  *view;
00083     dynERRORnum = 0;
00084     time_t begin_sim, end_sim;
00085     struct tm *local_begin_time; /* struct holding real-time calendar time from standard time.h */
00086     
00087     /* a couple of items that use the standard time.h to clock the simulation runtime*/
00088     begin_sim = time(NULL); 
00089     local_begin_time = localtime(&begin_sim);
00090 
00091     local_setup(argc, argv); /* not much here for serial implementation; establish processor attributes (parallel)*/
00092     setup();    
00093     alloc_memory(); 
00094 
00095     read_model_parameters( ProgExec->S_ParmName, ProgExec->S_ParmRelVal );
00096     if (SensiOn) SParmNum = SensiParm_list(ProgExec->S_ParmName);
00097     RunNum = numRuns(SParmNum, NumSRunsPerSet);
00098 
00099     init_static_data(); 
00100 
00101     totRuns = RunNum;
00102     
00103     /* new simulations can be started within this while ( ) (for sensitivity analyses, Position Analysis, other in future) */
00104     while (RunNum) {
00105       RunNum--; /* decrement the number of complete simulations runs during program execution (pertinent to multiple sensitivity analysis runs) */
00106       runSeq= totRuns - RunNum;
00107 
00108       sync_processors(); /* parallel only */
00109 
00110       open_debug_outFile(runSeq); /* the file Driver1.out (and DriverX.out for X'th subsequent sensitivity run) is opened for writing general messages
00111                                 (warnings, errors, and data depending on debug level) */
00112 
00113       if (runSeq == 1) {
00114          usrErr0("Reading output requests...");
00115          view = read_output_parms();  /* reading model.outlist */
00116          usrErr("Done output requests.");
00117       }
00118 
00119           if (SensiOn) { 
00120              parmID = (int) (runSeq)/NumSRunsPerSet;
00121          ProgExec = RunList[parmID]; 
00122 
00123          if (runSeq > 1) {
00124             ProgExec->S_ParmRelVal = ProgExec->S_ParmRelVal+1 ;
00125             read_model_parameters( ProgExec->S_ParmName, ProgExec->S_ParmRelVal );
00126             reinitBIR(); /* re-init the Basin/Ind. Region datav */
00127          }
00128              sprintf(msgStr,"\nSENSITIVITY ANALYSIS: Run %d of %d, relative-value parm ID= %d in %s set.", 
00129                 runSeq, totRuns, ProgExec->S_ParmRelVal,  ProgExec->S_ParmName ); 
00130              usrErr(msgStr); 
00131              WriteMsg(msgStr,1); 
00132              
00133            }
00134 
00135       init_dynam_data();
00136       init_eqns();
00137       if (WatMgmtOn) init_canals(runSeq);
00138       if (HabSwitchOn) init_succession();
00139 
00140       usrErr0("Calling dynamic ecological modules:\n\t");
00141       for (i=0; i<NSector; i++) {
00142           sprintf(msgStr, "%d, ", iSector[i]);
00143               usrErr0(msgStr);
00144       }
00145        
00146       /* for Position Analysis, where the model is re-initialized at a recurring interval */
00147       if(PositAnalOn)  { 
00148           sprintf(msgStr, "\n\t***running %2d/%2d Position Analysis*** ",mo_R_in,da_R_in); 
00149               usrErr0(msgStr);
00150       }
00151 
00152           /*  ESP (Everglades Settling-of Phosphorus, i.e., EWQModel emulation) mode.  */
00153       if (ESPmodeON)  usrErr0("\n\t***running ESP*** ");
00154       
00155       if (WatMgmtOn)  usrErr0("\n\twith spatial water managment 'on' ");
00156       else usrErr0("\n\twith spatial water managment 'off' ");
00157 
00158       if (HabSwitchOn)  usrErr("and succession 'on'.");
00159       else usrErr("and succession 'off'.");
00160                 
00161       sprintf(msgStr,"\n*** Running simulation from %d/%d/%d to %d/%d/%d ***",
00162              yr_in,mo_in,da_in, yr_end,mo_end,da_end ); 
00163       usrErr(msgStr);
00164       
00165                 /***************/
00166                 /* temporal loop for driving model */
00167       for(istep=0; istep<N_iter; istep++) {
00168 
00169         track_time(istep);
00170         
00171         /* when testing/debugging new code/data, allow critical ERRORs to accumulate to aid in identifying problem - then get out.
00172                 This exit is particularly important with new users, who may configure data sets improperly, resulting in a model
00173                 that runs merrily along, but accumulates a massive DriverX.out (for X'th simulation run) file w/ errors (exceeding file size limit of OS) */
00174         if (dynERRORnum > 500) {
00175                 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);
00176                 usrErr(msgStr);
00177                 exit(-1);
00178                 }
00179         
00180         if (PositAnalOn)  { /* for Position Analysis, where the model is re-initialized at a recurring interval */
00181           if ( (SimTime.mo[0] == mo_R_in) && (SimTime.da[0] == da_R_in) ) {
00182             usrErr0("\nPOSITION ANALYSIS: Re-initializing...");
00183             init_dynam_data(); 
00184             init_eqns(); 
00185             reinitCanals();
00186             reinitBIR(); /* missing init_succession */
00187             usrErr("Done re-initializing.");
00188           }
00189         }    
00190         if(debug >3) { /* long console output at this high debug level */
00191             sprintf(msgStr,"---------------------------------------Iteration = %d\n",istep);
00192             WriteMsg(msgStr,1); usrErr(msgStr); 
00193         }
00194         else
00195           {  /* print the year/month/day to console - this will be appended with horizontal iteration info later */
00196             sprintf(msgStr,"\r%d/%2d/%2d:   ",SimTime.yr[0],SimTime.mo[0],SimTime.da[0] ); 
00197                   usrErr0(msgStr); /* calendar date */
00198         }
00199 
00200         /* call dynamic calculations */
00201         for(i=0; i<NSector; i++) { /* for each dynamic ecological (including hydrology) sector(module) */
00202           
00203           if(debug >3) { /* long console output at this high debug level */
00204               sprintf(msgStr,"Running cell dyn %d of %d\n",iSector[i],NSector); 
00205               WriteMsg(msgStr,1); 
00206               usrErr(msgStr); 
00207           }
00208           call_cell_dyn(iSector[i],istep); /* invoke the UnitMod.c calling function for dynamic ecological modules */
00209         }
00210         
00211         /* generate output (incl. point time series) */
00212         if((istep >= 0 && istep <= N_iter) ) {
00213             if(debug >3) { /* long console output at this high debug level */
00214               usrErr(""); /* carriage return following hydstep iterations */
00215               sprintf(msgStr,"(%d)Generating Output",procnum); WriteMsg(msgStr,1); usrErr(msgStr); 
00216             }
00217           gen_output(istep, view);  /* the generates all spatial output */
00218         }
00219             
00220         /* send point time series output to disk at this interval */
00221         if ( FMOD(SimTime.TIME, 180.0) == 0 ) { 
00222                 if (istep == 0) open_point_lists(pSeries,MAX_PTSERIES);  /* at start of sim, open point timeseries files */
00223                     send_point_lists2(pSeries,MAX_PTSERIES); 
00224         }
00225       }  /* end of temporal loop for driving model */
00226                 /***************/
00227 
00228                 /* send the remaining time accumulated of point time series output to disk at end of simulation */
00229       send_point_lists2(pSeries,MAX_PTSERIES); 
00230       
00231       end_sim = time(NULL);
00232       /* print the simulation start date:time, and the elapsed cpu time, to DriverX.out (for X'th simulation run) file (& elapsed to console) */
00233       sprintf(msgStr,"########\nThe simulation(s) started on: %s", asctime(local_begin_time) ); WriteMsg(msgStr,1);
00234       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);
00235 
00236     } /* end of the while (RunNum) and thus end of simulation(s) (plural if running sensitivity) */
00237     
00238 return 0;
00239 } /* end of main and thus program execution */

Here is the call graph for this function:

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 246 of file Generic_Driver.c.

References seriesParm::data, get_map_dims(), get_parmf(), pSeries, set_env_vars(), setup_grid(), and setup_platform().

Referenced by main().

00247 {
00248   int i;
00249   for(i=0; i<MAX_PTSERIES; i++)  pSeries[i].data = NULL; /* initialize Point Time Series arrays */
00250   setup_platform(); /* effectively unused in serial (non-parallel) implementation */
00251   set_env_vars();   /* get necessary enviroment variables */ 
00252   get_parmf();      /* get the run-time parameters  */ 
00253   get_map_dims();   /* get the row-column dimensions of the global model array size */
00254   setup_grid();     /* set up a grid size used in memory allocations (other stuff for parallel) */
00255 }

Here is the call graph for this function:

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.

Variables local to function

stop boolean flag to stop reading sector (celldyn module) numbers
ch character used in delineating the reading of sector (celldyn module) numbers/syntax
infile an input file pointer representing the Driver.parm file
filename the filename, including path, of the Driver.parm file
ss a string being parsed to read model configuration information from the Driver.parm file
Re_initDateRead data of simulation re-initialization (Position Analysis mode)
endDateRead date of end of simulation

Definition at line 265 of file Generic_Driver.c.

References alloc_mem_runs(), avg_Intvl, avgCalendar, broadcastInt(), budg_Intvl, budgCalendar, can_Intvl, canalCalendar, canstep, CELL_SIZE, celWid, da_end, da_in, da_R_in, seriesParm::data, dbgPt, debug, dt, ESPmodeON, getFloat(), getInt(), getString(), gwstep, HabSwitchOn, hr_in, hyd_iter, initDateRead, iSector, Jdate_end, Jdate_init, julday(), 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, seed, SensiOn, sfstep, SimAlt, SimModif, skip_white(), sq_celWid, step_Cell, usrErr(), WatMgmtOn, WriteMsg(), point2D::x, point2D::y, yr_end, and yr_in.

Referenced by setup().

00266 {
00277     int i=0, stop=0;
00278     unsigned char ch;
00279     FILE *infile;
00280     char filename[120], ss[120]; 
00281         char Re_initDateRead[15], endDateRead[15]; 
00282         int SParmNum_TEMP = 150; /* TODO: will get this from reading the senitivity-parameter list */
00283         
00284     sprintf(filename,"%s/%s/RunParms/Driver.parm",ModelPath,ProjName);
00285     infile = fopen(filename,"r");
00286     if(infile==NULL) { fprintf(stderr,"Error, can't open file %s",filename); exit(0); }
00287 
00288      
00289     fgets(ss,120,infile);
00290     sscanf(ss,"%s",outpath);    
00291     OutputPath = (char*)&outpath; /* path for all output */
00292     open_debug_outFile(0); /* opens the Driver0.out debug file */
00293 
00294     /* start date  */
00295     fgets(ss,120,infile);
00296     sscanf(ss,"%s",initDateRead); /* read in as yyyy/mm/dd format */
00297 
00298     sprintf(msgStr,"initDateRead=%s\n",initDateRead); WriteMsg(msgStr,1); 
00299     sscanf(initDateRead, "%4d/%2d/%2d,",&yr_in,&mo_in,&da_in); /* starting date of sim */
00300 
00301     /* julian day, returns a double (args = month, day, year, hour, minute, second) */
00302     Jdate_init = julday(mo_in, da_in, yr_in, hr_in, mi_in, se_in); 
00303 
00304 
00305      /* end date  */
00306     fgets(ss,120,infile);
00307     sscanf(ss,"%s",endDateRead); /* read in as yyyy/mm/dd format */
00308 
00309     sprintf(msgStr,"endDateRead=%s\n",endDateRead); WriteMsg(msgStr,1); 
00310     sscanf(endDateRead, "%4d/%2d/%2d,",&yr_end,&mo_end,&da_end); /* ending date of sim */
00311  
00312         /* julian day, returns a double (args = month, day, year, hour, minute, second) */
00313     Jdate_end = julday(mo_end, da_end, yr_end, hr_in, mi_in, se_in); 
00314 
00315     /* re-initialization date  */
00316     fgets(ss,120,infile);
00317     sscanf(ss,"%s",Re_initDateRead); /* read in as mm/dd format */
00318 
00319     sprintf(msgStr,"Re_initDateRead=%s\n",Re_initDateRead); WriteMsg(msgStr,1); 
00320     sscanf(Re_initDateRead, "%2d/%2d,",&mo_R_in,&da_R_in); /* re-initialize month/day */
00321 
00322     if (mo_R_in>0) {
00323         PositAnalOn=True;   /* in position analysis mode, we re-initialize every year on same month/day */
00324         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"); 
00325         WriteMsg(msgStr,1); 
00326         usrErr(msgStr); 
00327         }       /* TODO: fix the budget/stats re-inits for Position Analysis mode */ 
00328 
00329     fgets(ss,120,infile);
00330     sscanf(ss,"%s",modelName);    
00331     sprintf(msgStr, "Model Name= %s", modelName); usrErr(msgStr); WriteMsg(msgStr,1);
00332     getString(infile,"Model version=",modelVers); /* model version number (eg., v.2.1) */
00333     sprintf(msgStr,"Model version=%s\n",modelVers); WriteMsg(msgStr,1);  
00334 
00335     getFloat(infile,"CellArea=",&CELL_SIZE);
00336     sprintf(msgStr,"CellArea=%f\n",CELL_SIZE); WriteMsg(msgStr,1); 
00337     celWid = sqrt(CELL_SIZE); /* cell width, used in number of hydro calcs */
00338     sq_celWid = sqrt(celWid); /* square root of cell width, used in number of hydro calcs */
00339     
00340 
00341     getFloat(infile,"budg_Intvl=",&budg_Intvl);
00342     sprintf(msgStr,"budg_Intvl=%f\n",budg_Intvl); WriteMsg(msgStr,1); 
00343     budgCalendar = ( budg_Intvl == 0.0 ) ? (True) : (False); /* true/false flag signifying use of gregorian calendar for budget calcs
00344                                                                                 a budg_Intvl of 0 days defaults to gregorian calendar-month
00345                                                                                 intervals ( = #days/month, diff among months/years) 
00346                                                                                 In this case, the true/false budgCalendar flag is set to True */
00347 
00348     getFloat(infile,"avg_Intvl=",&avg_Intvl);
00349     sprintf(msgStr,"avg_Intvl=%f\n",avg_Intvl); WriteMsg(msgStr,1); 
00350     if ( avg_Intvl == 0 ) avgCalendar = True; /* true/false flag signifying use of gregorian calendar for recurring averaging calcs
00351                                                                                 an avg_Intvl of 0 days defaults to gregorian calendar-month
00352                                                                                 intervals ( = #days/month, diff among months/years) 
00353                                                                                 In this case, the true/false avgCalendar flag is set to True */
00354 
00355     getFloat(infile,"can_Intvl=",&can_Intvl);
00356     sprintf(msgStr,"can_Intvl=%f\n",can_Intvl); WriteMsg(msgStr,1); 
00357     if ( can_Intvl == 0 ) canalCalendar = True; /* true/false flag signifying use of gregorian calendar for recurring canal (watmanage) calcs
00358                                                                                 a can_Intvl of 0 days defaults to gregorian calendar-month
00359                                                                                 intervals ( = #days/month, diff among months/years) 
00360                                                                                 In this case, the true/false can_Intvl flag is set to True */
00361 
00362     getInt(infile,"seed=",&seed);
00363     sprintf(msgStr,"seed=%d\n",seed); WriteMsg(msgStr,1);  
00364     getFloat(infile,"dt=",&dt);
00365     sprintf(msgStr,"dt=%f\n",(double)dt); WriteMsg(msgStr,1);  
00366     getInt(infile,"hyd_iter=",&hyd_iter); 
00367     sprintf(msgStr,"hyd_iter=%d\n",hyd_iter); WriteMsg(msgStr,1); 
00368 
00369     sfstep = dt/hyd_iter;     /* time step for cell-cell overland flows */
00370     gwstep = dt/(hyd_iter/2); /* time step for cell-cell ground water flows (twice as long as surface water)*/
00371     canstep = dt/hyd_iter;             /* time step for canal flows */
00372     step_Cell = sq_celWid * sfstep/CELL_SIZE * sec_per_day; /* constant used in horizontal surface water raster flux equations */
00373 
00374     N_iter= (Jdate_end - Jdate_init + 1)/dt;
00375         sprintf(msgStr,"N_iter=%d\n",N_iter); WriteMsg(msgStr,1); 
00376     PORnumday = (int)(Jdate_end - Jdate_init + 1);   /* number of days of simulation Period Of Record */
00377 
00378     getInt(infile,"debug=",&debug);
00379     sprintf(msgStr,"debug=%d\n",debug); WriteMsg(msgStr,1);  
00380     getInt(infile,"debug_point=",&dbgPt.x);
00381     getInt(infile,NULL,&dbgPt.y);
00382     sprintf(msgStr,"debug point= (%d,%d)\n",dbgPt.x,dbgPt.y); WriteMsg(msgStr,1);  
00383         
00384         alloc_mem_runs(SParmNum_TEMP);
00385         RunList[0] = ProgExec; /* nominal parameter set */
00386         
00387     getString(infile,"S_ParmName=",ProgExec->S_ParmName); /* value can be: 
00388                                         1) "NONE", for no sensitivity analysis (nominal parameter set);
00389                                         2) the name of a global or habitat-specific parameter for a single-parm sensitivity analysis; 
00390                                         3) "ALL", leading to multi-parameter sensitivity analyses on 
00391                                            all parameters, to be read from an input list */
00392     sprintf(msgStr,"S_ParmName=%s\n",ProgExec->S_ParmName); WriteMsg(msgStr,1); 
00393 
00394     SensiOn = (strcmp(ProgExec->S_ParmName,"NONE")!=0) ? (True) : (False);
00395     ProgExec->S_ParmRelVal = 0; /* first run of program is ALWAYS the nominal (no parameter-changes) run */
00396 
00397         getInt(infile,"HabSwitchOn=",&HabSwitchOn); /* flag to turn on habitat switching */
00398     sprintf(msgStr,"HabSwitchOn=%d\n",HabSwitchOn); WriteMsg(msgStr,1); 
00399     getInt(infile,"WatMgmtOn=",&WatMgmtOn); /* flag to turn on canal/water management */
00400     sprintf(msgStr,"WatMgmtOn=%d\n",WatMgmtOn); WriteMsg(msgStr,1); 
00401 
00402     getString(infile,"Scenario=",SimAlt); /* simulation's scenario/alternative */
00403     sprintf(msgStr,"SimAlt=%s\n",SimAlt); WriteMsg(msgStr,1);  
00404     getString(infile,"Scenario modifier=",SimModif); /* simulation's scenario/alternative & modifier */
00405     sprintf(msgStr,"SimModif=%s\n",SimModif); WriteMsg(msgStr,1); 
00406 
00407         scan_forward(infile,"Sectors="); i=0; stop=0;
00408         while(1) {
00409             skip_white(infile);
00410             ch=fgetc(infile);
00411             if( isdigit(ch) ) ungetc(ch,infile);
00412             else {
00413                 switch (ch) {
00414                     case ';':  NSector = i; stop=1; break;
00415                     case ',':  skip_white(infile); break;
00416                 }
00417             }
00418             if(stop) break;
00419             else fscanf(infile,"%d",&iSector[i++]);
00420                 /* sector 13 is the ESP (Everglades Settling-of Phosphorus, i.e., EWQModel emulation) mode - this sets the ESPmodeON flag*/
00421             if (iSector[i-1] == 13) ESPmodeON=1;
00422             
00423         }
00424         fclose(infile);  
00425     broadcastInt(&NSector);
00426     sprintf(msgStr,"\n(%d) NSector = %d: Sectors=",procnum,NSector); WriteMsg(msgStr,1); 
00427     for(i=0; i<NSector; i++) {
00428         broadcastInt(&iSector[i]);
00429         sprintf(msgStr,"(%d:%d)",i,iSector[i]); WriteMsg(msgStr,1);  
00430     }
00431 
00432     for(i=0; i<MAX_PTSERIES; i++) if(pSeries[i].data) { free((char*)pSeries[i].data);  pSeries[i].data = NULL; }
00433 }

Here is the call graph for this function:

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.

Parameters:
istep counter for number of model time iterations

Definition at line 443 of file Generic_Driver.c.

References avg_Intvl, avgPrint, BIRavg_Intvl, budg_Intvl, calcdate(), can_Intvl, canPrint, simTime::da, simTime::hr, simTime::IsBIRavgEnd, simTime::IsBudgEnd, simTime::IsBudgFirst, simTime::IsDay0, simTime::IsDrySeasEnd, simTime::IsMonthEnd, simTime::IsSimulationEnd, istep, simTime::IsWetSeasEnd, simTime::IsYearEnd, simTime::Jdate, Jdate_init, simTime::mi, simTime::mo, N_iter, PORnumday, simTime::se, SimTime, simTime::TIME, and simTime::yr.

Referenced by main().

00444 {
00445     int yr_tom[2];                      /* calendar year of tomorrow's model time */
00446     int mo_tom[2];                              /* calendar month of tomorrow's  model time */
00447     int da_tom[2];                              /* calendar day of tomorrow's  model time */
00448     int hr_tom[2];                              /* calendar hour of tomorrow's  model time (unused in model calcs) */
00449     int mi_tom[2];                              /* calendar minute of tomorrow's  model time (unused in model calcs) */
00450     double se_tom[2];                   /* calendar second of tomorrow's  model time (unused in model calcs) */
00451      
00452     SimTime.TIME = istep*dt;
00453     SimTime.Jdate = Jdate_init+SimTime.TIME; /*  increment the julian day counter */
00454         
00455         /* use calendar functions to determine the end-of status of today's date */
00456         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 */
00457         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 */
00458 
00459                 SimTime.IsMonthEnd = ( SimTime.mo[0] != mo_tom[0] ) ? (True) : (False); /* true/false flag signifying end of a gregorian calendar month */
00460                 SimTime.IsYearEnd =  ( SimTime.yr[0] != yr_tom[0] ) ? (True)  : (False); /* true/false flag signifying end of a gregorian calendar year */
00461                 SimTime.IsWetSeasEnd = (( SimTime.mo[0] == wetEndMon ) && (SimTime.da[0] == wetEndDay))  ? (True) : (False); /* true/false flag signifying end of a gregorian calendar-based wet season */
00462                 SimTime.IsDrySeasEnd = (( SimTime.mo[0] == dryEndMon ) && (SimTime.da[0] == dryEndDay))  ? (True) : (False); /* true/false flag signifying end of a gregorian calendar-based dry season */
00463                 SimTime.IsSimulationEnd = ((PORnumday-1)==istep) ? (True) : (False);
00464 
00465         /* determine status of budget calc/printing flag (interval based on gregorian calendar or constant julian-day) */
00466         if (!budgCalendar) { 
00467                 if ( fmod(SimTime.TIME, budg_Intvl) ==0) {
00468                 /* not using gregorian calendar: at end of (constant) number of days, model time is end of budget interval */
00469                         SimTime.IsBudgEnd = True; 
00470                 } 
00471                 else { SimTime.IsBudgEnd = False; }
00472         }
00473         else {
00474                 if ( SimTime.IsMonthEnd ) {
00475                 /* using gregorian calendar: at calendar-month's end, model time is end of budget interval */
00476                         SimTime.IsBudgEnd = True; 
00477                         budg_Intvl= (float)SimTime.da[0]; /* dynamic interval becomes number of days in current gregorian-calendar month */
00478                 } 
00479                 else { SimTime.IsBudgEnd = False; }
00480         }
00481 
00482         /* determine status of cell-specific averages calc/printing flag (interval based on gregorian calendar or constant julian-day) */
00483         if (!avgCalendar) {
00484                 if ( fmod(SimTime.TIME, avg_Intvl) ==0) {
00485                 /* not using gregorian calendar: check for time (day) to finalize and print budgets for current interval */
00486                         avgPrint = True; }
00487                 else { avgPrint = False; }
00488         }
00489         else { 
00490                 if ( SimTime.IsMonthEnd ) {
00491                 /* using gregorian calendar: at month's end, it is time (day) to finalize and print budgets for current interval */
00492                         avgPrint = True;
00493                         avg_Intvl= (float)SimTime.da[0]; /* interval becomes number of days in current gregorian-calendar month */
00494                 }
00495                 else { avgPrint = False; }
00496         }
00497 
00498         /* determine status of canal data calc/printing flag (interval based on gregorian calendar or constant julian-day) */
00499         if (!canalCalendar) {
00500                 if ( fmod(SimTime.TIME, can_Intvl) ==0) {
00501                 /* not using gregorian calendar: check for time (day) to finalize and print canal data for current interval */
00502                         canPrint = True; }
00503                 else { canPrint = False; }
00504         }
00505         else { 
00506                 if ( SimTime.IsMonthEnd ) {
00507                 /* using gregorian calendar: at month's end, it is time (day) to finalize and print canal data for current interval */
00508                         canPrint = True;
00509                         can_Intvl= (float)SimTime.da[0]; /* interval becomes number of days in current gregorian-calendar month */
00510                 }
00511                 else { canPrint = False; }
00512         }
00513         
00514         SimTime.IsBudgFirst = ( (SimTime.TIME/budg_Intvl) > 1 ) ? (False) : (True);
00515         SimTime.IsDay0 = (SimTime.TIME==0) ? (True) : (False);
00516         
00517         /* TODO: this is to be generalized in MultiRun.c */
00518         if (SensiOn) {
00519            BIRavg_Intvl = N_iter - 1;
00520            SimTime.IsBIRavgEnd = ( fmod(SimTime.TIME, BIRavg_Intvl) ==0) ? (True) : (False);
00521            
00522            budg_Intvl = N_iter - 1;
00523            SimTime.IsBudgEnd = ( fmod(SimTime.TIME, budg_Intvl) ==0) ? (True) : (False);
00524         }
00525         else {
00526            BIRavg_Intvl = budg_Intvl;
00527            SimTime.IsBIRavgEnd = SimTime.IsBudgEnd;
00528         }
00529 
00530 }

Here is the call graph for this function:


Generated on Thu Jul 6 11:19:02 2006 for ELM source code by  doxygen 1.3.9.1