Ecological Landscape Modeling: Models Pages

Driver_Utilities.c File Reference

Most Input/Output utility & related functions. More...

#include "driver_utilities.h"

Include dependency graph for Driver_Utilities.c:

Go to the source code of this file.

Functions

void read_model_parameters (char *s_parm_name, int s_parm_relval)
 Call functions to read model parameters from datafiles.
ViewParmread_output_parms ()
 Call the read_output_parms function.
ViewParmreadOutlist (int size)
 Get the file to configure model output.
int readViewParms (FILE *vpFile, int size, ViewParm **ppview)
 Read/process the command-parameters to configure model output.
void make_more_points (ViewParm *vp, int ptIncr)
 Allocate memory & set up another set of point-locations for output.
void calc_maxmin (ViewParm *vp, void *Map, char Mtype, char *mName, int step)
 Calculate maximum & minimum values in model output arrays.
void setup_grid ()
 Provide the 2D array size for the model domain.
void write_output (int index, ViewParm *vp, void *Map, const char *filename, char Mtype, int step)
 Determine which functions to call for model output.
int write_map_file (const char *filename, VOIDP Map, char Mtype, int index, float scale_value, float offset_value, int bSize, unsigned char type, const char *thisvarUnits, int outstep, char *ncFileName)
 Prepare the file and the data for writing output of map (array).
int read_map_file (const char *filename, VOIDP Map, unsigned char Mtype, float scale_value, float offset_value)
 Get the file and read/convert the data of map (array).
void enc_Nb (UCHAR **sptr, SLONG value, int bytes)
 Place data in bytes into a buffer to assemble a binary array.
void quick_look (void *Map, char *name, unsigned char Mtype, int xc, int yc, int range, unsigned char format)
 Prepare data and write heading for writing a data window in debug file.
void writeWindow (void *fValue, char *vName, char *desc, int x0, int y0, int N0, int N1, int index, UCHAR Mtype, UCHAR format)
 Prepare a local data set for writing a local data window in debug file.
int iclip (int x0, int min, int max)
 Constrain x0 value within a min and a max.
void Copy (void *src, void *dst, int w, int n, int sw, int dw)
 Memory-copy data from large (global) domain to local domain.
void set_env_vars (void)
 Acquire necessary environment variables.
void print_point (ViewParm *vp, void *Map, char Mtype, char *mName, int tIndex, int vpindex)
 Print data at point locations to memory (not to file/disk yet).
void read_map_dims (const char *filename)
 Establish the number of rows and columns of the model.
void init_pvar (VOIDP Map, UCHAR *mask, unsigned char Mtype, float iv)
 Initialize a variable to a value.
void print_loc_ave (Point3D *vt, void *Map, char Mtype, char *mName, int tIndex)
 Calculate summary statistics to determine local average.
void PTS_SetFields (PTSeries *thisStruct, int ix, int iy, int index, int format, int col)
 Point Time Series interpolation (unused): set up the fields.
void PTS_Free (PTSeries *thisStruct)
 Point Time Series interpolation (unused): free up memory.
void PTS_CopyFields (PTSeries *thisStruct, PTSeries pV)
 Point Time Series interpolation (unused): copy fields.
PTSeriesListPTSL_Init (int nSlots, int format)
 Point Time Series interpolation (unused): initialize structure.
void PTSL_AddpTSeries (PTSeriesList *thisStruct, int x, int y, int index, int seriesNum, int col)
 Point Time Series interpolation (unused): add to the series.
void PTSL_Free (PTSeriesList *thisStruct)
 Point Time Series interpolation (unused): free up memory.
float PTSL_GetInterpolatedValue0 (PTSeriesList *thisStruct, int x, int y, int step)
 Point Time Series interpolation (unused): at point, calculate inverse distance squared interpolation (restricted, not using pow() function).
void PTSL_ReadLists (PTSeriesList *thisStruct, const char *ptsFileName, int index, float *timeStep, int *nPtTS, int col)
 Point Time Series interpolation (unused): read raw point data.
void PTSL_CreatePointMap (PTSeriesList *pList, void *Map, unsigned char Mtype, int step, float scale)
 Point Time Series interpolation (unused): generate interpolated spatial (map) data.
float PTSL_GetInterpolatedValue1 (PTSeriesList *thisStruct, int x, int y, int step)
 Point Time Series interpolation (unused): at point, calculate inverse distance interpolation (unrestricted power of distance).
void RP_SetFields (RPoint *thisStruct, int ix, int iy, float r, float value)
 Point Time Series interpolation (unused):.
void RP_CopyFields (RPoint *thisStruct, RPoint *that)
 Point Time Series interpolation (unused):.
void RP_SwapFields (RPoint *thisStruct, RPoint *that)
 Point Time Series interpolation (unused):.
RPointListRPL_Init (int nPoints)
 Point Time Series interpolation (unused):.
void RPL_AddrPoint (RPointList *thisStruct, int x, int y, float r, float value)
 Point Time Series interpolation (unused):.
void RPL_Sort (RPointList *thisStruct)
 Point Time Series interpolation (unused):.
void RPL_Free (RPointList *thisStruct)
 Point Time Series interpolation (unused):.
void setFlag (ViewParm *vp, UINT mask, int value)
 (Effectively unused). From Model.outList data, set a flag indicating array or not
int getFlag (ViewParm *vp, UINT mask)
 Unused (never called) function.
void setPrecision (ViewParm *vp, int value)
 (Effectively unused).
int getPrecision (ViewParm *vp)
 (Effectively unused).
int check_for (char *s0, const char *s1, int start, int cs, int rp)
 Check for occurrences of string s1 in string s0 after position start.
int isInteger (char *target_str)
 Determine if an integer is present in string.
int isFloat (char *target_str)
 Determine if a float is present in string.
void WriteMsg (const char *msg, int wh)
 Send a message to a debug file or to the console.
void usrErr0 (const char *dString)
 Send a message to the console.
void usrErr (const char *dString)
 Send a message to the console.
void Exit (int code)
 Standard exit from program.
void fatal (const char *msg)
 Exit (code=9) from program after sending a message.
double julday (int mon, int day, int year, int h, int mi, double se)
 Determine the Julian calendar day from a Gregorian date.
void calcdate (double jd, int *m, int *d, int *y, int *h, int *mi, double *sec)
 Determine the Gregorian date from a Julian calendar day.
float FMOD (float x, float y)
 Modulus of a pair of (double) arguments.
void getFloat (FILE *inFile, const char *lString, float *fValPtr)
 Get a float value following a specific string.
void getChar (FILE *inFile, const char *lString, char *cValPtr)
 Get a character following a specific string.
void getString (FILE *inFile, const char *lString, char *inString)
 Get a string following a specific string.
void getInt (FILE *inFile, const char *lString, int *iValPtr)
 Get an integer following a specific string.
int find_char (FILE *infile, char tchar)
 Find a character.
int Round (float x)
 truncate (not rounding) to an integer
char * Scip (char *s, char SYM)
 Skip ahead in a string until next field.
int skip_white (FILE *infile)
 Skip white space(s) in a file.
int scan_forward (FILE *infile, const char *tstring)
 Scan forward until a particular string is found.
char * name_from_path (char *name)
 Get the var name from a longer path/filename.
VOIDP nalloc (unsigned mem_size, const char var_name[])
 Allocate memory for a variable.
float Normal (float mean, float sd)
 Unused, never called. Normal distribution.
int Poisson (float mu)
 Unused, never called. Poisson distribution.
void link_edges (VOIDP Map, unsigned char Mtype)
 Effectively unused in serial (non-parallel) implementation.
void setup_platform ()
 Effectively unused in serial (non-parallel) implementation.


Detailed Description

Most Input/Output utility & related functions.

This source file contains a large number of functions used in "utility" tasks that generally relate to I/O, set-up of the simulation environment, etc.

Major categories of functions are (roughly) grouped in this order:
1) Output
2) Parameter and other data input
3) Spatial interpolation
4) Routine tasks (parsing text, values, error conditions, etc)
5) [effectively unused] Calls/definitions for parallel (not serial) implementation

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

The Everglades Landscape Model (ELM).
last updated: June 2008

Definition in file Driver_Utilities.c.


Function Documentation

void read_model_parameters ( char *  s_parm_name,
int  s_parm_relval 
)

Call functions to read model parameters from datafiles.

Parameters:
s_parm_name Name of the sensitivity parameter being varied for this run
s_parm_relval Indicator of current value of relative range in sensitivity parm values: nominal (0), low (1), or high (2)

Definition at line 39 of file Driver_Utilities.c.

References msgStr, ReadGlobalParms(), ReadHabParms(), ReadModExperimParms(), usrErr(), usrErr0(), and WriteMsg().

Referenced by main().

00039                                                                   {
00040 
00041     sprintf(msgStr,"Reading global parameters..."); 
00042     WriteMsg(msgStr,1); 
00043     usrErr0(msgStr);
00044 
00045         ReadGlobalParms(s_parm_name, s_parm_relval);
00046     sprintf(msgStr,"done."); 
00047     WriteMsg(msgStr,1); 
00048     usrErr(msgStr);
00049         
00050     sprintf(msgStr,"Reading habitat-specific parameters..."); 
00051     WriteMsg(msgStr,1); 
00052     usrErr0(msgStr);
00053 
00054         ReadHabParms(s_parm_name, s_parm_relval);
00055     sprintf(msgStr,"done."); 
00056     WriteMsg(msgStr,1); 
00057     usrErr(msgStr);
00058   
00059     /* v2.6 - don't write message to console until later (when determine if parm file is used or not) */
00060         ReadModExperimParms(s_parm_name, s_parm_relval);
00061         
00062 }

Here is the call graph for this function:

ViewParm* read_output_parms ( void   ) 

Call the read_output_parms function.

Returns:
pointer to struct of ViewParm

Definition at line 66 of file Driver_Utilities.c.

References Outlist_size, and readOutlist().

Referenced by main().

00066                               {
00067 /* need to change the Outlist_size (#defined in header) if adding outlist variables to the data struct in gen_output of UnitMod.c */
00068     ViewParm* v = readOutlist(Outlist_size);
00069     return v;
00070 } 

Here is the call graph for this function:

ViewParm* readOutlist ( int  size  ) 

Get the file to configure model output.

Parameters:
size Outlist_size, the number of variables in model outlist
Returns:
pointer to struct of ViewParm

Definition at line 75 of file Driver_Utilities.c.

References cnfgFile, H_OPSYS, modelFileName, ModelPath, msgStr, ProjName, readViewParms(), UNIX, and WriteMsg().

Referenced by read_output_parms().

00076 {
00077   int Npt;
00078   ViewParm* vp;
00079   FILE   *cnfgFile;
00080   
00081   if(H_OPSYS==UNIX) sprintf(modelFileName,"%s/%s/RunParms/Model.outList",ModelPath,ProjName);
00082   else sprintf(modelFileName,"%s%s:RunParms:Model.outList",ModelPath,ProjName);
00083   cnfgFile = fopen(modelFileName, "r");
00084   if (cnfgFile == NULL) {
00085       sprintf(msgStr, "Error, can't open file %s", modelFileName);
00086       WriteMsg(msgStr, 1); exit(-1);}
00087   
00088   Npt = readViewParms(cnfgFile,size, &vp);
00089   return vp;
00090 
00091 }

Here is the call graph for this function:

int readViewParms ( FILE *  vpFile,
int  size,
ViewParm **  ppview 
)

Read/process the command-parameters to configure model output.

The configuration file (Model.outList) is read to process the type (e.g., spatial maps, point time series, debug windows) and frequency (constant intervals of time) of model output.

Parameters:
vpFile Pointer to the Model.outList configuration file
size Outlist_size, the number of variables in model outlist
ppview Struct of ViewParm output configuration data
Returns:
value of Outlist_size

Definition at line 105 of file Driver_Utilities.c.

References avg_Intvl, viewParm::bounds, CalMonOut, debug, viewParm::fileName, point3D::format, gCArg, init_config_file(), ISARRAY, isFloat(), isInteger(), make_more_points(), viewParm::mapType, viewParm::maxPoints, msgStr, nalloc(), viewParm::nPoints, scale1::o, parse_packet(), viewParm::points, scale1::s, viewParm::scale, setFlag(), setPrecision(), viewParm::step, point3D::type, usrErr(), viewParm::varUnits, view, scale2::Vmax, scale2::Vmin, WriteMsg(), point3D::x, point3D::y, and point3D::z.

Referenced by readOutlist().

00106 {
00107   char test;
00108   char cmd;
00109   int index=0, ix, iy, iz, i, nArgs, precision, format=0, Ocmd;
00110   float x,y;
00111   ViewParm *vp, *view;
00112 
00113   format = init_config_file(vpFile, '#', '*', '@', '~');
00114   view = (ViewParm *)nalloc(size * sizeof(ViewParm), "view");
00115   *ppview = view;
00116   
00117   for (i = 0; i < size; i++) {
00118     vp = view+i;
00119     vp->scale.s = 1.0;
00120     vp->scale.o = 0.0;
00121     vp->step = 0;
00122     Ocmd=0;
00123     vp->nPoints = 0;
00124     vp->points = NULL;
00125     vp->maxPoints = 0;
00126     vp->mapType = 'N';
00127     precision = 1;
00128     setPrecision(vp,precision);
00129   }
00130 
00131   while(1) {
00132     index = parse_packet(vpFile, &nArgs, &test);/*fix*/
00133     if( index == -1)  break; 
00134     if( index == -3)  break; 
00135     if(index >= size) { 
00136       fprintf(stderr,"\n Read index Error in configuration: index out of range: %d ", index); 
00137       break; 
00138     }
00139     if( index == -2) break;
00140     else {
00141       vp = view+index;
00142       strncpy(vp->fileName,gCArg[0],23);
00143       vp->fileName[23]='\0';
00144       if( test == '*' ) setFlag(vp,ISARRAY,1); 
00145       else if (test == '@') setFlag(vp,ISARRAY,0);
00146       else { 
00147         sprintf(msgStr," %s: Syntax Error in configuration, test char = %c ",gCArg[0],test); 
00148         usrErr(msgStr);  
00149         break; 
00150       }
00151       if(debug && gCArg[1][0] != 'U') { 
00152         sprintf(msgStr,"\nReading Output Config for %s: Nargs = %d, CMD0 = %c index = %d",
00153                 gCArg[0],nArgs,gCArg[1][0],index);      
00154         WriteMsg(msgStr,1);  
00155       }                         
00156       cmd = gCArg[1][0]; 
00157       switch (cmd) {    
00158           case 'U': /* v2.8.2 - new "command" for variables' units; this is actually not a "command" for requesting output, but simply uses the command syntax to encapsulate the string of units */
00159               strncpy(vp->varUnits,gCArg[2],23);
00160               vp->varUnits[23]='\0';
00161               if(debug > 3) { 
00162                   sprintf(msgStr,"\n%s Output Config: Units= %s",gCArg[0],gCArg[2]);    
00163                   WriteMsg(msgStr,1); 
00164               }                         
00165               
00166               break;
00167           case 'O':
00168               if( isInteger(gCArg[2])  ) { ix = atoi(gCArg[2]);  }
00169               else  fprintf(stderr," %s: Syntax Error in configuration ",gCArg[0]);     
00170               if(debug) { 
00171                   sprintf(msgStr,"\n%s Output Config: O(%d)",gCArg[0],ix);      
00172                   WriteMsg(msgStr,1); 
00173               }                         
00174               vp->step = ix; Ocmd=1;
00175               /* TODO: develop flexible output of calendar-based and julian-based outsteps (jan 11, 2005) */
00176               /* kluge here in checking use of Model.outList outstep relative to Driver.parm avg_Intvl */
00177               if (vp->step == CalMonOut && avg_Intvl != 0) {
00178                   sprintf(msgStr,"\n***ERROR in Model.outList & Driver.parm integration: Driver.parm's avg_Intvl must be 0 for calendar-based Outstep of %s.",gCArg[0]);        
00179                   usrErr(msgStr); 
00180                   exit(-1);
00181               }
00182               
00183               break;
00184           case 'A':
00185               if( isInteger(gCArg[2]) && nArgs > 2 ) { ix = atoi(gCArg[2]);  }
00186               else  { 
00187                   fprintf(stderr," %s: Syntax Error in configuration ",gCArg[0]);  
00188                   WriteMsg(msgStr,1); 
00189               } 
00190               if(debug) { 
00191                   sprintf(msgStr,"\n%s Output Config: A()",gCArg[0]); 
00192                   WriteMsg(msgStr,1); 
00193               }                                 
00194               vp->mapType = 'H';
00195               if( Ocmd == 0 ) vp->step = 1;
00196               break;
00197           case 'G':
00198               if ( nArgs > 2 )  { 
00199                   if( isInteger(gCArg[2])  ) { 
00200                       vp->mapType = atoi(gCArg[2]); 
00201                   } 
00202                   else { vp->mapType =gCArg[2][0]; } 
00203               }
00204               if ( nArgs > 3 ) 
00205                   if( isInteger(gCArg[3])  ) { 
00206                       precision = atoi(gCArg[3]); 
00207                   }
00208               if ( nArgs > 4 ) strcpy(vp->fileName,gCArg[4]);
00209               if( precision > 1 && precision < 5 ) setPrecision(vp,precision);
00210               if( Ocmd == 0 ) vp->step = 1;
00211               break;
00212           case 'B':
00213               if( isFloat(gCArg[2]) && isFloat(gCArg[3])  && nArgs > 3 ) { 
00214                   vp->bounds.Vmax = atof(gCArg[2]); 
00215                   vp->bounds.Vmin = atof(gCArg[3]); 
00216               }
00217               if(debug) { 
00218                   sprintf(msgStr,"\n Output Config: G(%.1f,%.1f)",
00219                           vp->bounds.Vmax, vp->bounds.Vmin); 
00220                   WriteMsg(msgStr,1); 
00221               } 
00222               break;
00223           case 'P':
00224               if( isInteger(gCArg[2]) &&  isInteger(gCArg[3]) && nArgs > 3 )  {         
00225                   if( (i = (++(vp->nPoints)-1)) >= (vp->maxPoints)) make_more_points(vp,7);
00226                   ix = atoi(gCArg[2]); iy = atoi(gCArg[3]);  
00227               }
00228               else  fprintf(stderr," %s: Syntax Error in configuration ",gCArg[0]);
00229               if(debug) { 
00230                   sprintf(msgStr,"\n%s Output Config: P(%d,%d), index = %d",gCArg[0],ix,iy,i); 
00231                   WriteMsg(msgStr,1);  
00232               }                         
00233               vp->points[i].x = ix; 
00234               vp->points[i].y = iy;
00235               vp->points[i].type = 'p';
00236               /* TODO: develop flexible output of calendar-based and julian-based outsteps (jan 11, 2005) */
00237               /* kluge here in preventing use of point time series output using calendar-based outstep  */
00238               if (vp->step == CalMonOut) {
00239                   sprintf(msgStr,"\n***ERROR in Model.outList: sorry, but you can't have point-time series output with calendar-based Outstep of %s.  Go yell at Carl!",gCArg[0]);      
00240                   usrErr(msgStr); 
00241                   exit(-1);
00242               }
00243               break;
00244           case 'W':
00245               if( isInteger(gCArg[2]) &&  isInteger(gCArg[3]) &&  isInteger(gCArg[4]) && nArgs > 4 ) {
00246                   if( (i = (++(vp->nPoints)-1)) >= (vp->maxPoints)) make_more_points(vp,7);
00247                   ix = atoi(gCArg[2]); iy = atoi(gCArg[3]); iz = atoi(gCArg[4]);  
00248               }
00249               else  fprintf(stderr," %s: Syntax Error in configuration ",gCArg[0]);
00250               if( nArgs > 5 )  vp->points[i].format = gCArg[5][0];
00251               vp->points[i].type = 'w';
00252               vp->points[i].x = ix;     
00253               vp->points[i].y = iy;     
00254               vp->points[i].z = iz;
00255               if(debug) { 
00256                   sprintf(msgStr,"\n%s Output Config: W(%d,%d,%d,%c), index = %d",
00257                           gCArg[0],ix,iy,iz,vp->points[i].format,i);    
00258                   WriteMsg(msgStr,1);  
00259               }                         
00260               if( Ocmd == 0 ) vp->step = 1;
00261               break;
00262           case 'S': case 'C':
00263               if( gCArg[1][1] == 'm' || gCArg[1][0] == 'C' ) {     
00264                   if( isInteger(gCArg[2]) &&  isInteger(gCArg[3]) &&  isInteger(gCArg[4]) && nArgs > 5 ) {
00265                       if( (i = (++(vp->nPoints)-1)) >= (vp->maxPoints)) make_more_points(vp,7);
00266                       ix = atoi(gCArg[2]); iy = atoi(gCArg[3]); iz = atoi(gCArg[4]); 
00267                       vp->points[i].type =  gCArg[5][0];
00268                   }
00269                   else  fprintf(stderr," %s: Syntax Error in configuration ",gCArg[0]);
00270                   vp->points[i].x = ix;         
00271                   vp->points[i].y = iy;         
00272                   vp->points[i].z = iz;
00273                   if(debug) { 
00274                       sprintf(msgStr,"\n%s Output Config: Sm(%d,%d,%d,%c), index = %d",
00275                               gCArg[0],ix,iy,iz,gCArg[4][0],i);  
00276                       WriteMsg(msgStr,1); 
00277                   }                             
00278                   if( Ocmd == 0 ) vp->step = 1; 
00279               } 
00280               else {                                                            
00281                   if( nArgs > 2 ) {
00282                       if( isFloat(gCArg[2]) ) { x = atof(gCArg[2]); }
00283                       else  fprintf(stderr," %s: Syntax Error in configuration ",gCArg[0]);
00284                   }
00285                   if( nArgs > 3 ) {
00286                       if( isFloat(gCArg[3]) ) { y = atof(gCArg[3]); }
00287                       else  fprintf(stderr," %s: Syntax Error in configuration ",gCArg[0]);
00288                   }
00289                   if(debug) { 
00290                       sprintf(msgStr,"\n%s Output Config: S(%f,%f)",gCArg[0],x,y); 
00291                       WriteMsg(msgStr,1); 
00292                   }                             
00293                   vp->scale.s = x; 
00294                   vp->scale.o = y;
00295               }
00296               break;
00297       } /* end of switch */
00298     } /* end of else */
00299   } /* end of while */
00300   return size;
00301 }

Here is the call graph for this function:

void make_more_points ( ViewParm vp,
int  ptIncr 
)

Allocate memory & set up another set of point-locations for output.

For each model variable to be output (info in ViewParm struct), increment the number of point-locations (cells) based on the number requested in the model output configuration file.

Parameters:
vp Pointer to struct of ViewParm
ptIncr number of points to increment

Definition at line 312 of file Driver_Utilities.c.

References debug, viewParm::fileName, viewParm::maxPoints, msgStr, viewParm::points, point3D::type, WriteMsg(), point3D::x, point3D::y, and point3D::z.

Referenced by readViewParms().

00313 {
00314         Point3D *new_pts;
00315         int i;
00316         
00317         new_pts = (Point3D *) malloc( (vp->maxPoints+ptIncr) * sizeof(Point3D) );
00318         for(i=0; i < vp->maxPoints; i++) {
00319                 new_pts[i].x = vp->points[i].x;
00320                 new_pts[i].y = vp->points[i].y;
00321                 new_pts[i].z = vp->points[i].z;
00322                 new_pts[i].type = vp->points[i].type;
00323         }
00324         if( vp->points != NULL ) { free((char*)vp->points); }
00325         vp->points = new_pts;
00326         vp->maxPoints += ptIncr;
00327         if(debug) {
00328                 sprintf(msgStr,"Made %d more points for %s for %d total points",ptIncr,vp->fileName,vp->maxPoints); 
00329                 WriteMsg(msgStr,1);
00330         }
00331 }

Here is the call graph for this function:

void calc_maxmin ( ViewParm vp,
void *  Map,
char  Mtype,
char *  mName,
int  step 
)

Calculate maximum & minimum values in model output arrays.

For each model variable to be output (info in ViewParm struct), calculate the maximum and minimum values across the variable's spatial array.

Parameters:
vp struct of ViewParm data
Map Model variable array data
Mtype General output format type
mName Variable name
step The current iteration number

Definition at line 344 of file Driver_Utilities.c.

References Combine(), viewParm::gScale, kMAXMIN, ON_MAP, s0, s1, T, scale2::Vmax, and scale2::Vmin.

Referenced by write_output().

00345 {
00346   int ix, iy;
00347   float vout[4], ftmp, fmax = -1000, fmin = 1000;
00348   
00349   switch(Mtype) {
00350   case 'f' :    
00351     for(ix=1; ix<=s0; ix++) 
00352       for(iy=1; iy<=s1; iy++) {
00353         if( ON_MAP[T(ix,iy)] ) {
00354           if( (ftmp = ((float*)Map)[T(ix,iy)]) > fmax ) {
00355             fmax = ftmp; 
00356           }
00357           if( ftmp < fmin ) fmin = ftmp;
00358         }
00359       }
00360     break;
00361   case 'i' :    case 'd' :      
00362     for(ix=1; ix<=s0; ix++) 
00363       for(iy=1; iy<=s1; iy++) {
00364         if( ON_MAP[T(ix,iy)] ) {
00365           if((ftmp = ((int*)Map)[T(ix,iy)]) > fmax ) fmax = ftmp;
00366           if( ftmp < fmin ) fmin = ftmp;
00367         }
00368       }
00369     break;
00370   case 'c' :    
00371     for(ix=1; ix<=s0; ix++) 
00372       for(iy=1; iy<=s1; iy++) {
00373         if( ON_MAP[T(ix,iy)] ) {
00374           if( (ftmp = (float)((unsigned char*)Map)[T(ix,iy)]) > fmax ) fmax = ftmp;
00375           if( ftmp < fmin ) fmin = ftmp;
00376         }
00377       } 
00378     break;
00379   }
00380   if(step==0) {
00381     vp->gScale.Vmax = fmax;
00382     vp->gScale.Vmin = fmin;
00383   } else {
00384     if( fmax > vp->gScale.Vmax ) vp->gScale.Vmax = fmax;
00385     if( fmin < vp->gScale.Vmin ) vp->gScale.Vmin = fmin;
00386   }
00387   vout[0] = fmax; vout[1] = vp->gScale.Vmax; vout[2] = fmin; vout[3] = vp->gScale.Vmin;
00388   Combine(vout,mName,4,kMAXMIN,step); /* Iterative and cumulative, maximum and minimum values for all window cells at outstep iterations */
00389 }

Here is the call graph for this function:

void setup_grid (  ) 

Provide the 2D array size for the model domain.

Definition at line 392 of file Driver_Utilities.c.

References exgridsize(), floatOut, gbl_size, gridSize, gTemp, gTempSize, init_pvar(), lcl_size, lcl_start, msgStr, nalloc(), nc_dataRowRev, procnum, s0, s1, and WriteMsg().

Referenced by setup().

00392                   {
00393   
00394   exgridsize(procnum,gbl_size,lcl_size,lcl_start); /* effectively unused in serial (non-parallel) implementation */
00395 
00396   /*  s0 and s1 remain unchanged in serial (non-parallel) implementation */
00397   s0 = lcl_size[0];
00398   s1 = lcl_size[1];
00399   
00400   gridSize = (s0+2)*(s1+2); /* the gridSize is increased by 2 in each dimension for buffer strips around processor domain(s) (functional mainly to parallel implementation) */
00401   
00402   sprintf(msgStr,"\nGRID DATA::[ gsize: (%d, %d), lstart: (%d, %d), lend: (%d, %d), lsize: (%d, %d) ]\n",
00403           gbl_size[0], gbl_size[1], lcl_start[0], 
00404           lcl_start[1], lcl_start[0]+lcl_size[0]-1, 
00405           lcl_start[1]+lcl_size[1]-1, lcl_size[0], lcl_size[1] );
00406   WriteMsg(msgStr,1);  
00407   sprintf(msgStr,"\nVP DATA:: size: (%d), Variable sizes: float: %d, int: %d, long: %d,  double: %d\n", 
00408             sizeof(ViewParm), sizeof(float),sizeof(int) ,sizeof(long) ,sizeof(double)   );
00409   WriteMsg(msgStr,1);
00410 
00411   gTempSize = gridSize*8;
00412   gTemp = (UCHAR*) nalloc(gTempSize,"gTemp");  
00413 
00414 /* v2.8.2 new temp array for output - all variables' arrays are 2 rows and 2 cols larger than the actual data 
00415         this is used to hold only the size of s0, s1 */
00416   floatOut = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"floatOut");
00417 //  init_pvar(floatOut,NULL,'f',0.0);
00418 
00419 /* v2.8.2 new temp array for output - netCDF output files now have origin at lower (not upper) left */
00420   nc_dataRowRev = (float *) nalloc(sizeof(float)*(s0+2)*(s1+2),"nc_dataRowRev");
00421   init_pvar(nc_dataRowRev,NULL,'f',0.0);
00422     
00423 
00424 }

Here is the call graph for this function:

void write_output ( int  index,
ViewParm vp,
void *  Map,
const char *  filename,
char  Mtype,
int  step 
)

Determine which functions to call for model output.

Parameters:
index Count index of the output iteration for this variable (may be > step)
vp A struct of ViewParm, outlist configuration
Map Model variable array data
filename Output file name
Mtype General output format type
step The current output step

Definition at line 435 of file Driver_Utilities.c.

References calc_maxmin(), debug, viewParm::fileName, point3D::format, getPrecision(), viewParm::mapType, msgStr, viewParm::nPoints, scale1::o, viewParm::points, print_loc_ave(), print_point(), quick_look(), scale1::s, viewParm::scale, viewParm::step, point3D::type, viewParm::varUnits, write_map_file(), WriteMsg(), point3D::x, point3D::y, and point3D::z.

Referenced by gen_output().

00437 {
00438         int i; Point3D point;
00439         
00440 
00441         if(vp->mapType != 'N' ) { 
00442                         write_map_file((char*)filename,Map,Mtype,index,vp->scale.s,vp->scale.o,getPrecision(vp),vp->mapType,vp->varUnits,vp->step,vp->fileName); /* v2.8.2 added varUnits, vp->step (which is outstep interval), and fileName for netCDF use */
00443                         if (debug > 3) calc_maxmin(vp,Map,Mtype,(char*)filename,step);
00444         }
00445         for(i=0; i< (vp->nPoints); i++ ) {
00446                 point = vp->points[i];
00447             if (debug > 3) { sprintf(msgStr,"\nwriting Out: %s(%d): %c(), index = %d, step=%d\n", filename, i, point.type, index, step ); 
00448             WriteMsg(msgStr,1); 
00449             }
00450             
00451                 switch( point.type ) {  
00452                     case 'm': case 'M': calc_maxmin( vp,Map,Mtype,(char*)filename,step); break; 
00453                     case 'w': quick_look( Map,(char*) filename, Mtype, point.x, point.y, point.z, point.format ); break;
00454                     case 'a': case 's': case 'A': case 'S': print_loc_ave( &point, Map, Mtype, (char*)filename, step ); break;
00455                     case 'p': print_point( vp, Map, Mtype, (char*)filename, step, i ); break;
00456                 }
00457         }
00458 }

Here is the call graph for this function:

int write_map_file ( const char *  filename,
VOIDP  Map,
char  Mtype,
int  index,
float  scale_value,
float  offset_value,
int  bSize,
unsigned char  type,
const char *  thisvarUnits,
int  outstep,
char *  ncFileName 
)

Prepare the file and the data for writing output of map (array).

Parameters:
filename Output file name
Map Model variable array data
Mtype General output format type
index Count index of the output iteration for this variable (may be > step)
scale_value Variable-scaling multiplier
offset_value Variable-scaling offset
bSize The byte size of the output array
type The output map storage type
thisvarUnits Units of the output variable
outstep The output interval time step
ncFileName The filename for netCDF output

Definition at line 473 of file Driver_Utilities.c.

References CASE, check_for(), simTime::da, dbgPt, debug, enc_Nb(), END, floatOut, gridSize, gTemp, gTempSize, H_OPSYS, HDF4, simTime::mo, modelFileName, msgStr, nalloc(), NCDF3, offMap_float, ON_MAP, OutputPath, ProjName, quick_look(), s0, s1, SimTime, T, UNIX, writeFloatMap(), writeMap(), WriteMsg(), point2D::x, point2D::y, and simTime::yr.

Referenced by write_output().

00476 {       
00477   int i, j, pathType=0;
00478   char ftype[10], gSize;
00479   float ftmp; 
00480   SLONG itmp, imax, imin;
00481   UCHAR *mPtr;
00482   char s_mo[3], s_da[3];
00483   FILE* bFile; 
00484    
00485 /* below provides old (v1.0) increasing integer, non-date, appendage to filenames */
00486 /*   ftype[0] = '0' + (index / 100); */
00487 /*   ftype[1] = '0' + ((index%100) / 10); */
00488 /*   ftype[2] = '0' + (index % 10); */
00489  /*  ftype[8] = '\0'; */
00490 
00491 /*  append the date (yyyymmdd) to the root filename*/
00492   if (SimTime.mo[0]<10) sprintf(s_mo,"0%d", SimTime.mo[0]);
00493   else sprintf(s_mo,"%d", SimTime.mo[0]);
00494   if (SimTime.da[0]<10) sprintf(s_da,"0%d", SimTime.da[0]);
00495   else sprintf(s_da,"%d", SimTime.da[0]);
00496   sprintf(ftype,"%d%s%s\0",SimTime.yr[0],s_mo,s_da);
00497   
00498   if( HDF4 && type=='H' ) sprintf(ftype,".hdf");
00499    
00500   if( NCDF3 && type=='C' ) sprintf(ftype,".nc");
00501    
00502   gSize = gridSize*bSize + 1;
00503   if( gSize > gTempSize ) { 
00504     if(gTempSize) free((char*)gTemp); 
00505     gTemp = (UCHAR*) nalloc( gSize, "gTemp" );  
00506     gTempSize = gSize; 
00507   }
00508   
00509   if( H_OPSYS == UNIX ){ 
00510     if(check_for((char*)filename, "/", 0, CASE, END ) >= 0 ) { 
00511       if(filename[0] != '/' ) pathType = 1; 
00512       else pathType = 2; 
00513     }
00514   }
00515   else { if(check_for ((char*)filename, ":", 0, CASE, END ) >= 0 ) { if( filename[0] == ':' ) pathType = 1; else pathType = 2; }}
00516   
00517   if(type=='H') {                         /* HDF format */
00518     switch(pathType) {
00519     case 0:     /* No Path */
00520       if(H_OPSYS==UNIX) sprintf(modelFileName,"%s/%s/Output/HDF/%s%s\0",OutputPath,ProjName,filename,ftype);
00521       else sprintf(modelFileName,"%s%s:Output:HDF:%s%s\0",OutputPath,ProjName,filename,ftype);
00522       break;
00523     case 1:     /* Relative Path */
00524       if(H_OPSYS==UNIX) sprintf(modelFileName,"%s/%s/Output/HDF/%s%s\0",OutputPath,ProjName,filename,ftype);
00525       else sprintf(modelFileName,"%s%s:Output:HDF:%s%s\0",OutputPath,ProjName,filename,ftype);
00526       break;
00527     case 2:     /* Full Path */
00528       sprintf(modelFileName,"%s.hdf\0",filename);
00529       break;
00530     }
00531   }
00532 
00533  else if(type=='C') {                         /* netCDF format */
00534     switch(pathType) {
00535     case 0:     /* No Path */
00536       if(H_OPSYS==UNIX) sprintf(modelFileName,"%s/%s/Output/NCDF/%s%s\0",OutputPath,ProjName,ncFileName,ftype);
00537       else sprintf(modelFileName,"%s%s:Output:NCDF:%s%s\0",OutputPath,ProjName,ncFileName,ftype);
00538       break;
00539     case 1:     /* Relative Path */
00540       if(H_OPSYS==UNIX) sprintf(modelFileName,"%s/%s/Output/NCDF/%s%s\0",OutputPath,ProjName,ncFileName,ftype);
00541       else sprintf(modelFileName,"%s%s:Output:NCDF:%s%s\0",OutputPath,ProjName,ncFileName,ftype);
00542       break;
00543     case 2:     /* Full Path (not used) */
00544       sprintf(modelFileName,"%s.hdf\0",filename);
00545       break;
00546     }
00547   }
00548 
00549   else if(type=='M') {  
00550     switch(pathType) {                   /* M==Map, generic binary (possibly larger than uchar size binary) Format */
00551     case 0:                                                             /* No Path */
00552 // v2.8.2 changed to varname-specific directory, must be existing directory (user will have to create, for now
00553       if(H_OPSYS==UNIX) sprintf(modelFileName,"%s/%s/Output/%s/%s%s\0",OutputPath,ProjName,filename,filename,ftype);
00554       else sprintf(modelFileName,"%s%s:Output:%s:%s%s\0",OutputPath,ProjName,filename,filename,ftype);
00555       break;
00556     case 1:     /* Relative Path */
00557       if(H_OPSYS==UNIX) sprintf(modelFileName,"%s/%s/Output/%s/%s%s\0",OutputPath,ProjName,filename,filename,ftype);
00558       else sprintf(modelFileName,"%s%s:Output:%s:%s%s\0",OutputPath,ProjName,filename,filename,ftype);
00559       break;
00560     case 2:     /* Full Path */
00561       sprintf(modelFileName,"%s%s\0",filename,ftype);
00562       break;
00563     }
00564   }
00565   else {
00566         bSize = 1;
00567     switch(pathType) {                   /* Generic Binary Format (uchar, 0-254 ints) */
00568     case 0:                                                             /* No Path */
00569       if(H_OPSYS==UNIX) sprintf(modelFileName,"%s/%s/Output/Animation%d/%s%s\0",OutputPath,ProjName,type,filename,ftype);
00570       else sprintf(modelFileName,"%s%s:Output:Animation%d:%s%s\0",OutputPath,ProjName,type,filename,ftype);
00571       break;
00572     case 1:     /* Relative Path */
00573       if(H_OPSYS==UNIX) sprintf(modelFileName,"%s/%s/Output/Animation%d/%s%s\0",OutputPath,ProjName,type,filename,ftype);
00574       else sprintf(modelFileName,"%s%s:Output:Animation%d:%s%s\0",OutputPath,ProjName,type,filename,ftype);
00575       break;
00576     case 2:     /* Full Path */
00577       sprintf(modelFileName,"%s%s\0",filename,ftype);
00578       break;
00579     }
00580   }
00581   
00582   bSize = (bSize < 1) ? 1 : bSize;
00583   bSize = (bSize > 4) ? 4 : bSize;
00584   if( Mtype == 'c' ) bSize = 1;
00585   
00586 /*  New for v.2.8.2, providing capability to write (4 byte) floating point output maps.
00587         This may not be elegant, but will get it done for now.  The issue is that 
00588         the size of the arrays are actually s0+2, s1+2, which will later result in
00589         having larger array sizes for these output maps.  Would need to use the equivalent
00590         of enc_Nb to consider only the data in s0,s1 array.  */
00591   if (bSize == 4) {
00592   
00593   for (i=0; i< (s0+2); i++) { /* was trying to only resample within 0,s0, but gave up and using whole s0+2 array */
00594     for (j=0; j< (s1+2); j++) { /* was trying to only resample within 0,s1, but gave up and using whole s1+2 array */
00595       if( ON_MAP[T(i,j)] ) { /* for resampling, was using T(i+1,j+1) */
00596          floatOut[T(i,j)] = (( (float*) Map)[T(i,j)]); 
00597       }
00598       else {
00599          floatOut[T(i,j)] = offMap_float; /* for resampling */
00600 //              ( (float*) Map)[T(i,j)]  = offMap_float; /* arrays were initialized to 0 */
00601       }
00602     }
00603   }
00604   
00605   if  ( debug >3) {  sprintf(msgStr,"\n\nWriting Float Map %s: no scaling should be used (scale and offset values are ignored, but should be 1 & 0, respectively) scale_value = %f, offset_value = %f, index = %d, filename = %s, type = %c, bSize = %d, pathType = %d, type = %d, units = %s\n",
00606                            filename,scale_value,offset_value,index,modelFileName,Mtype,bSize,pathType,type,thisvarUnits);   WriteMsg(msgStr,1); }
00607 
00608   writeFloatMap(modelFileName,filename,floatOut,bSize,type,index,thisvarUnits,outstep); 
00609   /* we're done with writing floats (no scaling done) */
00610   return(0);
00611   } 
00612 
00613 
00614   if(bSize == 1) { imax = 255; imin = 0; }
00615   else if(bSize == 2) { imax = 255*128; imin = -imax; } 
00616   else if(bSize == 3) { imax = 256*256*128; imin = -imax; }
00617   mPtr = gTemp;
00618   
00619   if  ( debug >3) {  sprintf(msgStr,"\n\nWriting Map %s: scale_value = %f, offset_value = %f, index = %d, filename = %s, type = %c, bSize = %d, pathType = %d, type = %d\n",
00620                            filename,scale_value,offset_value,index,modelFileName,Mtype,bSize,pathType,type);   WriteMsg(msgStr,1); }
00621   
00622   for (i=0; i<s0; i++) {
00623     for (j=0; j<s1; j++) {
00624       if( ON_MAP[T(i+1,j+1)] ) {
00625         switch(Mtype) {
00626         case 'l' :
00627       ftmp = ((( (double*) Map)[T(i+1,j+1)] - offset_value) / scale_value); /* v2.3.2 added double (casting to float ftmp) */
00628           itmp = (int) ftmp;
00629           itmp = (itmp > imax-1) ? imax-1 : itmp;
00630           itmp = (itmp < imin) ? imin : itmp;
00631           break;
00632         case 'f' :                      
00633           ftmp = ((( (float*) Map)[T(i+1,j+1)] - offset_value) / scale_value); 
00634           itmp = (int) ftmp;
00635           itmp = (itmp > imax-1) ? imax-1 : itmp;
00636           itmp = (itmp < imin) ? imin : itmp;
00637           break;
00638         case 'd' : case 'i' :   
00639           ftmp = ((( (int*) Map)[T(i+1,j+1)] - offset_value) / scale_value); 
00640           itmp = (int) ftmp;
00641           itmp = (itmp > imax-1) ? imax-1 : itmp;
00642           itmp = (itmp < imin) ? imin : itmp;
00643           break;
00644         case 'c' :                              
00645           itmp = ((unsigned char*) Map)[T(i+1,j+1)];
00646           itmp = (itmp > imax-1) ? imax-1 : itmp;
00647           itmp = (itmp < imin) ? imin : itmp;
00648           break;
00649         }
00650       }
00651       else   itmp = imax;  
00652       
00653       
00654       enc_Nb(&mPtr,itmp,bSize);
00655       
00656     }
00657   }     
00658 
00659   writeMap(modelFileName,gTemp,bSize,type,index);
00660   if(debug) quick_look(Map, (char*)filename, Mtype, dbgPt.x, dbgPt.y, 2,'E');
00661   return(0);
00662 }

Here is the call graph for this function:

int read_map_file ( const char *  filename,
VOIDP  Map,
unsigned char  Mtype,
float  scale_value,
float  offset_value 
)

Get the file and read/convert the data of map (array).

Parameters:
filename Input file name
Map Model variable array data
Mtype General data format type
scale_value Variable-scaling multiplier
offset_value Variable-scaling offset
Returns:
byte size of data values

Definition at line 674 of file Driver_Utilities.c.

References dbgPt, debug, gridSize, gTemp, gTempSize, lcl_size, link_edges(), msgStr, nalloc(), procnum, quick_look(), readMap(), s0, s1, T, usrErr(), WriteMsg(), point2D::x, and point2D::y.

Referenced by init_dynam_data(), and init_static_data().

00677 {
00678   int i, j, k0, size;
00679   unsigned temp;
00680   UCHAR *tmpPtr, Dsize;
00681   
00682 gridSize = (s0+2)*(s1+2);
00683 gTempSize = gridSize*8;
00684 
00685 
00686   size = gridSize*4 +1;
00687   if( size > gTempSize ) { 
00688     if(gTemp) free((char*)gTemp); 
00689     gTemp = (UCHAR*)nalloc( size, "gTemp" );    
00690     gTempSize = size; 
00691   }
00692   
00693   if(debug>2) { 
00694     sprintf(msgStr,"Reading %s\n",filename);  
00695     usrErr(msgStr); 
00696     WriteMsg(msgStr,1); 
00697   } 
00698   
00699   Dsize = readMap(filename,gTemp);
00700   
00701   if(debug) { 
00702     sprintf(msgStr,"name = %s, proc = %d, scale_value = %f, offset_value = %f, size = %x\n ",
00703             filename,procnum,scale_value,offset_value,Dsize);  
00704     WriteMsg(msgStr,1); 
00705   } 
00706   for (i=1; i<=s0; i++) {
00707     for (j=1; j<=s1; j++) {
00708       k0 = Dsize*((i-1)*lcl_size[1] + (j-1));
00709       tmpPtr = gTemp+k0;
00710       switch(Dsize) {
00711         case 1: temp = gTemp[k0]; break;
00712         case 2: temp = gTemp[k0]*256 + gTemp[k0+1]; break;
00713         case 3: temp = gTemp[k0]*65536 + gTemp[k0+1]*256 + gTemp[k0+2]; break;
00714         case 4: temp = gTemp[k0]*16777216 + gTemp[k0+1]*65536 + gTemp[k0+2]*256 + gTemp[k0+3]; break;
00715         default: fprintf(stderr,"ERROR, illegal size: %x\n",Dsize); temp = 0;
00716       }                                         
00717       switch (Mtype) {
00718         case 'f' :
00719           ((float*)Map)[T(i,j)] = scale_value*((float)temp)+offset_value; 
00720         break;
00721         case 'd' : case 'i' :
00722           ((int*)Map)[T(i,j)] = (int)(scale_value * (float)temp + offset_value); 
00723         break;
00724         case 'c' :
00725           ((unsigned char*)Map)[T(i,j)] = (int)(scale_value * (unsigned char)temp); 
00726         break;
00727       }
00728     }
00729   }
00730   if(debug) quick_look(Map, (char*)filename, Mtype, dbgPt.x, dbgPt.y, 2,'E');
00731   link_edges(Map,Mtype);
00732   fflush(stderr);
00733   return Dsize;
00734 }

Here is the call graph for this function:

void enc_Nb ( UCHAR **  sptr,
SLONG  value,
int  bytes 
)

Place data in bytes into a buffer to assemble a binary array.

Place a 1,2,3, or 4 (N) byte signed value into the specified buffer and advance the buffer pointer past the placed object.

Parameters:
sptr a pointer to pointer to UCHAR (the buffer)
value The value to place in the buffer
bytes Number of bytes in data

Definition at line 761 of file Driver_Utilities.c.

Referenced by write_map_file().

00762 {
00763   UCHAR tmp[4];
00764   switch(bytes) {
00765   case 1:
00766     *(*sptr)++ = value;
00767     break;
00768   case 2:
00769     *(*sptr)++ = (value >> 8);
00770     *(*sptr)++ = value;
00771     break;
00772   case 3:
00773     tmp[0] = value;
00774     tmp[1] = (value >>= 8);
00775     tmp[2] = (value >> 8);
00776     *(*sptr)++ = tmp[2];
00777     *(*sptr)++ = tmp[1];
00778     *(*sptr)++ = tmp[0];
00779     break;
00780   case 4:
00781     tmp[0] = value;
00782     tmp[1] = (value >>= 8);
00783     tmp[2] = (value >>= 8);
00784     tmp[3] = (value >> 8);
00785     *(*sptr)++ = tmp[3];
00786     *(*sptr)++ = tmp[2];
00787     *(*sptr)++ = tmp[1];
00788     *(*sptr)++ = tmp[0];
00789     break;
00790   }
00791 }

void quick_look ( void *  Map,
char *  name,
unsigned char  Mtype,
int  xc,
int  yc,
int  range,
unsigned char  format 
)

Prepare data and write heading for writing a data window in debug file.

Parameters:
Map Model variable array data
name Model variable name
Mtype General output format type
xc Point location x (row!)
yc Point location y (col!)
range Size range (cells) of window
format Numeric format type

Definition at line 802 of file Driver_Utilities.c.

References debug, iclip(), istep, lcl_start, msgStr, name_from_path(), on_this_proc(), recpnum, s0, s1, and writeWindow().

Referenced by read_map_file(), write_map_file(), and write_output().

00804 {
00805   int ymin, ymax, xmin, xmax, x, y, N0, N1;
00806   char* namePtr;
00807 
00808   if (!on_this_proc(xc,yc)) return;
00809   x = xc - lcl_start[0] + 1;
00810   y = yc - lcl_start[1] + 1;
00811   xmin = x - range;
00812   xmax = x + range + 1;
00813   ymin = y - range;
00814   ymax = y + range + 1;
00815   xmax = iclip( xmax, 0, s0+2);
00816   xmin = iclip( xmin, 0, s0+2);
00817   ymax = iclip( ymax, 0, s1+2);
00818   ymin = iclip( ymin, 0, s1+2);
00819   N0 = xmax-xmin;
00820   N1 = ymax-ymin;
00821   namePtr = name_from_path(name);
00822   if (debug >3) {
00823     sprintf(msgStr,"Window to Map %s, s=%d, proc0 = %d, proc1 = %d; Corners(gbl): (%d,%d) (%d,%d)\n",
00824             namePtr,range,recpnum[0],recpnum[1],xc-range,yc-range,xc+range+1,yc+range+1);
00825     writeWindow(Map,namePtr,msgStr,xmin,ymin,N0,N1,istep,Mtype,format);
00826   }
00827   
00828 }

Here is the call graph for this function:

void writeWindow ( void *  fValue,
char *  vName,
char *  desc,
int  x0,
int  y0,
int  N0,
int  N1,
int  index,
UCHAR  Mtype,
UCHAR  format 
)

Prepare a local data set for writing a local data window in debug file.

Parameters:
fValue Model variable array data
vName Model variable name
desc Message describing the output
x0 Lower x (row!) value
y0 Lower y (col!) value
N0 Range in x (row!) values
N1 Range in y (col!) values
index Current iteration number
Mtype General output format type
format Numeric format type

Definition at line 843 of file Driver_Utilities.c.

References Copy(), gTemp, gTempSize, s1, T, and writeSeries().

Referenced by quick_look().

00846 {
00847   int mSize, size;
00848   char ctemp[200];
00849   
00850   switch(Mtype) {
00851   case 'l':                             size = sizeof(double); break; /* v2.3.2 added */
00852   case 'f': case 'L': case 'E':         size = sizeof(float); break;
00853   case 'd': case 'i':                   size = sizeof(int);  break;
00854   case 'c':                             size = sizeof(char); break;
00855   }
00856   if( (mSize=size*N0*N1) > gTempSize ) {
00857     if(gTemp != NULL) free((char*)gTemp);
00858     gTemp = (UCHAR*)malloc(gTempSize=mSize);
00859   }
00860   
00861   Copy(((UCHAR*)fValue)+T(x0,y0)*size, gTemp, N1*size, N0, (s1+2)*size, N1*size);
00862   sprintf(ctemp,"(%d)WIND: %s",index,vName);
00863   writeSeries(gTemp,ctemp,desc,N0,N1,Mtype,format);
00864 }

Here is the call graph for this function:

int iclip ( int  x0,
int  min,
int  max 
)

Constrain x0 value within a min and a max.

Parameters:
x0 number to work on
min the minimum
max the maximum
Returns:
result

Definition at line 872 of file Driver_Utilities.c.

Referenced by quick_look().

00873 {
00874   int rv;
00875   rv = ( x0 > max) ?  max : x0;
00876   rv = ( rv < min) ?  min : rv;
00877   return rv;
00878 }

void Copy ( void *  src,
void *  dst,
int  w,
int  n,
int  sw,
int  dw 
)

Memory-copy data from large (global) domain to local domain.

Parameters:
src The source of info
dst The destination of info
w The number of characters
n The number of (row) repetitions
sw The source size in col direction
dw The destination size in col direction
Returns:
resulting (destination) copy

Definition at line 889 of file Driver_Utilities.c.

Referenced by writeWindow().

00890 {
00891   int i;
00892   for(i=0; i<n; i++) 
00893     memcpy( ((UCHAR*)dst)+i*dw, ((UCHAR*)src)+i*sw, w ); /* copy w chars from source to dest, return destination */
00894 }

void set_env_vars ( void   ) 

Acquire necessary environment variables.

Definition at line 900 of file Driver_Utilities.c.

References DriverPath, ModelPath, msgStr, OS_TYPE, ProjName, and usrErr().

Referenced by setup().

00900                         {
00901   
00902   FILE *infile;
00903   char filename[100], ch;
00904   static long start;
00905   int i, maxLen =200;
00906   
00907     ModelPath = getenv("ModelPath"); 
00908     ProjName = getenv("ProjName");
00909     DriverPath = getenv("DriverPath");
00910     OS_TYPE = getenv("OSTYPE"); /* OSTYPE not used in code, only here for informational output */
00911 
00912         sprintf(msgStr,"OS type = %s ",OS_TYPE); 
00913     usrErr(msgStr);
00914     
00915         sprintf(msgStr,"Project Name = %s ",ProjName); 
00916     usrErr(msgStr);
00917  
00918 }

Here is the call graph for this function:

void print_point ( ViewParm vp,
void *  Map,
char  Mtype,
char *  mName,
int  tIndex,
int  vpindex 
)

Print data at point locations to memory (not to file/disk yet).

Parameters:
vp struct of ViewParm output configuration
Map Array data of variable
Mtype General output format type
mName The name of the variable
tIndex Current model iteration number
vpindex Index of the current point number

Definition at line 929 of file Driver_Utilities.c.

References seriesParm::data, debug, fatal(), lcl_start, seriesParm::Length, seriesParm::Loc, MAX_PTSERIES, msgStr, N_iter, seriesParm::outstep, PListIndex, viewParm::points, pSeries, s0, s1, viewParm::step, T, usrErr(), WriteMsg(), point2D::x, point3D::x, point2D::y, point3D::y, and point3D::z.

Referenced by write_output().

00931 {
00932         int x, y;
00933         Point3D *pt;
00934   
00935         pt = vp->points + vpindex;
00936     x = pt->x - lcl_start[0];
00937     y = pt->y - lcl_start[1];
00938     if(  (x >= 0) && (x < s0)  &&  (y >= 0) && (y < s1)  ) {
00939       if(tIndex==0) { pt->z = PListIndex; pSeries[PListIndex].Length=0; 
00940     }
00941     else PListIndex = pt->z; 
00942     if(tIndex==0) {                     
00943               /* TODO: develop flexible output of calendar-based and julian-based outsteps (jan 11, 2005) */
00944           if(PListIndex >= MAX_PTSERIES ) fatal("Too many Point series.");
00945           else if( pSeries[PListIndex].data == NULL ) pSeries[PListIndex].data = (float*) malloc( (N_iter*sizeof(float)/vp->step)+2 );
00946       if( pSeries[PListIndex].data == NULL ) usrErr("out of Memory for Spatial Timeseries.");
00947           pSeries[PListIndex].Loc.x = pt->x;
00948           pSeries[PListIndex].Loc.y = pt->y;
00949           pSeries[PListIndex].outstep = vp->step; 
00950           strcpy(pSeries[PListIndex].name,mName);
00951           if(debug >2) { 
00952                         sprintf(msgStr,"\nSetup Pointlist %d for %s(%d), step=%d, point=(%d,%d)\n", PListIndex, mName, vpindex, vp->step, x, y ); 
00953                         WriteMsg(msgStr,1); 
00954             }
00955      }
00956       switch(Mtype) {
00957                   case 'f' :  pSeries[PListIndex].data[ pSeries[PListIndex].Length++ ] = ((float*)Map)[T(x+1,y+1)];     break;          
00958                   case 'i' :    pSeries[PListIndex].data[ pSeries[PListIndex].Length++ ] = ((int*)Map)[T(x+1,y+1)]; break;
00959                   case 'c' :  pSeries[PListIndex].data[ pSeries[PListIndex].Length++ ] = ((unsigned char*)Map)[T(x+1,y+1)];
00960       }
00961           if(debug >3) { 
00962                   sprintf(msgStr,"\nWriting Point %d for %s(%d), point=(%d,%d), value = %f, index = %d\n", 
00963                                                         PListIndex, mName, vpindex, x, y, ((float*)Map)[T(x+1,y+1)], pSeries[PListIndex].Length-1 ); 
00964                   WriteMsg(msgStr,1); 
00965           }
00966       PListIndex++;
00967     }
00968 }

Here is the call graph for this function:

void read_map_dims ( const char *  filename  ) 

Establish the number of rows and columns of the model.

Read the map dimensions of the global model array, establishing rows=s0 and columns=s1

Parameters:
filename character string of the representative map (usually "Elevation")

Definition at line 975 of file Driver_Utilities.c.

References broadcastInt(), debug, Exit(), gbl_size, Lprocnum, modelFileName, ModelPath, msgStr, ProjName, s0, s1, scan_forward(), usrErr(), and WriteMsg().

Referenced by get_map_dims().

00976 {
00977   FILE *file;
00978   
00979   if (debug>3) { sprintf(msgStr,"Getting map dims: %s",filename); usrErr(msgStr);} 
00980   if(Lprocnum == 1) {
00981     sprintf(modelFileName,"%s/%s/Data/Map_head/%s",ModelPath,ProjName,filename);
00982     file = fopen(modelFileName,"r");
00983     if(file==NULL) { 
00984       fprintf(stderr,"Unable to open map header file %s.\n",modelFileName); 
00985       fflush(stderr); 
00986       Exit(0);
00987     }
00988     scan_forward(file,"cols:");
00989     fscanf(file,"%d",&gbl_size[1]);
00990     sprintf(msgStr,"cols = %d\n",gbl_size[1]); WriteMsg(msgStr,1);
00991     scan_forward(file,"rows:");
00992     fscanf(file,"%d",&gbl_size[0]);
00993     sprintf(msgStr,"rows = %d\n",gbl_size[0]); WriteMsg(msgStr,1);
00994     fclose(file);
00995   }
00996   broadcastInt(gbl_size);   /* does nothing in serial (non-parallel) implementation */
00997   broadcastInt(gbl_size+1); /* does nothing in serial (non-parallel) implementation */
00998   s0 = gbl_size[0];
00999   s1 = gbl_size[1];
01000 }

Here is the call graph for this function:

void init_pvar ( VOIDP  Map,
UCHAR mask,
unsigned char  Mtype,
float  iv 
)

Initialize a variable to a value.

Parameters:
Map array of data
mask data mask
Mtype the data type of the map data
iv the value used to initialize variable

Definition at line 1008 of file Driver_Utilities.c.

References numBasn, s0, s1, and T.

Referenced by alloc_hab_hist(), alloc_mem_stats(), alloc_memory(), Canal_Network_Init(), Channel_configure(), and setup_grid().

01009 {
01010   int i0, i1;
01011   
01012   switch(Mtype) {
01013   case 'b' :    /* added double for (non-map) basin (b) array budget calcs */
01014     for(i0=0; i0<=numBasn; i0++) {
01015         ((double*)Map)[i0] = iv;
01016       }
01017     break;
01018   case 'l' :    /* added double (l == letter "ell" ) for map arrays */
01019     for(i0=0; i0<=s0+1; i0++) 
01020       for(i1=0; i1<=s1+1; i1++) {
01021         if(mask==NULL) ((double*)Map)[T(i0,i1)] = iv;
01022         else if ( mask[T(i0,i1)] == 0 ) ((double*)Map)[T(i0,i1)] = 0;
01023         else ((double*)Map)[T(i0,i1)] = iv;
01024       }
01025     break;
01026   case 'f' :    
01027     for(i0=0; i0<=s0+1; i0++) 
01028       for(i1=0; i1<=s1+1; i1++) {
01029         if(mask==NULL) ((float*)Map)[T(i0,i1)] = iv;
01030         else if ( mask[T(i0,i1)] == 0 ) ((float*)Map)[T(i0,i1)] = 0;
01031         else ((float*)Map)[T(i0,i1)] = iv;
01032       }
01033     break;
01034   case 'i' :    case 'd' :      
01035     for(i0=0; i0<=s0+1; i0++) 
01036       for(i1=0; i1<=s1+1; i1++) {
01037         if(mask==NULL) ((int*)Map)[T(i0,i1)] = (int)iv;
01038         else if ( mask[T(i0,i1)] == 0 ) ((int*)Map)[T(i0,i1)] = 0;
01039         else ((int*)Map)[T(i0,i1)] = (int)iv;
01040       }
01041     break;
01042   case 'c' :    
01043     for(i0=0; i0<=s0+1; i0++) 
01044       for(i1=0; i1<=s1+1; i1++) {
01045         if(mask==NULL) ((unsigned char*)Map)[T(i0,i1)] = (unsigned char) '\0' + (int) iv;
01046         else if ( mask[T(i0,i1)] == 0 ) ((unsigned char*)Map)[T(i0,i1)] = '\0';
01047         else ((unsigned char*)Map)[T(i0,i1)] = (unsigned char) '\0' + (int) iv;
01048       } 
01049     break;
01050  
01051    default :
01052     printf(" in default case\n");
01053    break;
01054   }
01055 }

void print_loc_ave ( Point3D vt,
void *  Map,
char  Mtype,
char *  mName,
int  tIndex 
)

Calculate summary statistics to determine local average.

Parameters:
vt struct of cell points
Map Model variable data array
Mtype the data type of the map data
mName variable name
tIndex the current iteration number

Definition at line 1065 of file Driver_Utilities.c.

References Combine(), kAVE, kAVECUM, kSUM, kSUMCUM, lcl_start, ON_MAP, s0, s1, T, point3D::type, point3D::x, point3D::y, and point3D::z.

Referenced by write_output().

01066 {
01067   int ix, iy, x, y, x0, y0, range, xmax, ymax, xmin, ymin, type = 11;
01068   float vout[4];
01069   double sum = 0, normCoef = 0;
01070   
01071   if(Mtype != 'f') { fprintf(stderr,"Warning: Wrong type in Loc Ave: %s(%c)\n",mName,Mtype); return; }  
01072   x0 = vt->x;
01073   y0 = vt->y;
01074   range = vt->z;
01075   x = x0 - lcl_start[0]; 
01076   y = y0 - lcl_start[1];
01077   xmin = x - range;
01078   xmax = x + range;
01079   ymin = y - range;
01080   ymax = y + range;
01081   xmax = (xmax > (s0)) ? (s0) : xmax;
01082   xmin = (xmin <  0  ) ?   0  : xmin;
01083   ymax = (ymax > (s1)) ? (s1) : ymax;
01084   ymin = (ymin <  0  ) ?   0  : ymin;
01085   
01086   for(ix=xmin; ix<xmax; ix++)  {
01087     for(iy=ymin; iy<ymax; iy++) { 
01088       if( ON_MAP[T(ix+1,iy+1)] ) sum += ((float*)Map)[T(ix+1,iy+1)];                    
01089       normCoef += 1.0;
01090     }
01091   }
01092   
01093   vout[0] = sum; vout[1] = normCoef;
01094   
01095   switch (vt->type) {
01096      case 's' :  Combine(vout,mName,1,kSUM,tIndex); break; /* Sum for all window cells at outStep iterations */
01097      case 'a' :  Combine(vout,mName,2,kAVE,tIndex); break; /* Average for all window cells at outStep iterations */
01098      case 'A' :  Combine(vout,mName,2,kAVECUM,tIndex); break; /* Cumulative average for all window cells over all outStep iterations */
01099      case 'S' :  Combine(vout,mName,1,kSUMCUM,tIndex); break; /* Cumulative sum for all window cells over all outStep iterations */
01100   }  
01101 }

Here is the call graph for this function:

void PTS_SetFields ( PTSeries thisStruct,
int  ix,
int  iy,
int  index,
int  format,
int  col 
)

Point Time Series interpolation (unused): set up the fields.

Definition at line 1105 of file Driver_Utilities.c.

References debug, pTSeries::fNpt, pTSeries::fTS, pTSeries::fValue, pTSeries::fX, pTSeries::fY, gNPtTs, gTS, modelFileName, msgStr, readSeriesCol(), and WriteMsg().

Referenced by PTSL_AddpTSeries().

01107 {
01108   float ptstep = 1.0, *value; 
01109   int n0;
01110   
01111   thisStruct->fX = ix;
01112   thisStruct->fY = iy;
01113   if(thisStruct->fValue) free((char*)thisStruct->fValue); 
01114 
01115   thisStruct->fValue = readSeriesCol(modelFileName,format,index,&n0,&ptstep,col);
01116   
01117   gNPtTs = thisStruct->fNpt = n0;
01118   gTS = thisStruct->fTS = ptstep;
01119   value = thisStruct->fValue;
01120   if  ( debug>2 ) {  sprintf(msgStr,"\nPTS_SetFields: TSVals: %f %f %f, TS: %f, NPt: %d \n",value[0],value[1],value[2],ptstep,n0);  WriteMsg(msgStr,1); }
01121 }

Here is the call graph for this function:

void PTS_Free ( PTSeries thisStruct  ) 

Point Time Series interpolation (unused): free up memory.

Definition at line 1124 of file Driver_Utilities.c.

References pTSeries::fValue.

Referenced by PTSL_Free().

01125 {
01126   if(thisStruct->fValue) free((char*)thisStruct->fValue);
01127 }

void PTS_CopyFields ( PTSeries thisStruct,
PTSeries  pV 
)

Point Time Series interpolation (unused): copy fields.

Definition at line 1131 of file Driver_Utilities.c.

References pTSeries::fValue, pTSeries::fX, and pTSeries::fY.

Referenced by PTSL_AddpTSeries().

01132 {
01133   thisStruct->fX = pV.fX;
01134   thisStruct->fY = pV.fY;
01135   thisStruct->fValue = pV.fValue;
01136 }

PTSeriesList* PTSL_Init ( int  nSlots,
int  format 
)

Point Time Series interpolation (unused): initialize structure.

Definition at line 1139 of file Driver_Utilities.c.

References pTSeriesList::fFormat, pTSeriesList::fList, pTSeriesList::fNptTS, pTSeriesList::fNSlots, pTSeriesList::fNSlotsUsed, and pTSeries::fValue.

Referenced by PtInterp_read().

01140 {
01141   int i;
01142   PTSeriesList* thisStruct;
01143   thisStruct = (PTSeriesList*) malloc(sizeof(PTSeriesList));
01144   thisStruct->fList = (PTSeries*) malloc(sizeof(PTSeries)*nSlots);
01145   for(i=0; i<nSlots; i++) thisStruct->fList[i].fValue = NULL;
01146   thisStruct->fNSlots = nSlots;
01147   thisStruct->fNSlotsUsed = 0;
01148   thisStruct->fNptTS = 0;
01149   thisStruct->fFormat = format;
01150   return(thisStruct);
01151 }

void PTSL_AddpTSeries ( PTSeriesList thisStruct,
int  x,
int  y,
int  index,
int  seriesNum,
int  col 
)

Point Time Series interpolation (unused): add to the series.

Definition at line 1154 of file Driver_Utilities.c.

References pTSeriesList::fFormat, pTSeriesList::fList, pTSeries::fNpt, pTSeriesList::fNptTS, pTSeriesList::fNSlots, pTSeriesList::fNSlotsUsed, pTSeries::fValue, Max, PTS_CopyFields(), and PTS_SetFields().

Referenced by PTSL_ReadLists().

01155 {
01156   PTSeries* valListtemp;
01157   int i, newSlots;
01158   
01159   if( seriesNum >= thisStruct->fNSlots ) {
01160     newSlots = Max(20,(int)(thisStruct->fNSlots * 0.2));
01161     thisStruct->fNSlots += newSlots;
01162     valListtemp = (PTSeries*) malloc(sizeof(PTSeries)*(thisStruct->fNSlots));
01163     for(i=0; i<thisStruct->fNSlotsUsed; i++) {
01164       valListtemp[i].fNpt = thisStruct->fNptTS;
01165       PTS_CopyFields(valListtemp+i,thisStruct->fList[i]);
01166     }
01167     for(i=thisStruct->fNSlotsUsed; i<thisStruct->fNSlots; i++) valListtemp[i].fValue = NULL;
01168     if( thisStruct->fList != NULL ) free((char*)thisStruct->fList);
01169     thisStruct->fList = valListtemp;
01170   }
01171   
01172   PTS_SetFields( thisStruct->fList + seriesNum, x, y, index, thisStruct->fFormat, col );
01173   thisStruct->fNSlotsUsed = seriesNum;
01174 }

Here is the call graph for this function:

void PTSL_Free ( PTSeriesList thisStruct  ) 

Point Time Series interpolation (unused): free up memory.

Definition at line 1177 of file Driver_Utilities.c.

References pTSeriesList::fList, pTSeriesList::fNSlotsUsed, and PTS_Free().

01178 {
01179   int i;
01180   if(thisStruct == NULL) return;
01181   for(i=0; i<thisStruct->fNSlotsUsed; i++) PTS_Free( thisStruct->fList +i );
01182   if( thisStruct->fList != NULL ) free((char*)thisStruct->fList);
01183   free((char*)thisStruct);
01184   thisStruct = NULL;
01185 }

Here is the call graph for this function:

float PTSL_GetInterpolatedValue0 ( PTSeriesList thisStruct,
int  x,
int  y,
int  step 
)

Point Time Series interpolation (unused): at point, calculate inverse distance squared interpolation (restricted, not using pow() function).

Definition at line 1188 of file Driver_Utilities.c.

References pTSeriesList::fList, pTSeriesList::fNSlotsUsed, pTSeries::fValue, pTSeries::fX, pTSeries::fY, GP_IDW_pow, and lcl_start.

Referenced by PTSL_CreatePointMap().

01189 {
01190   int i,  dx, dy, my_debug;
01191   PTSeries pV;
01192   float  wpow;
01193   float weight, InterpValue=0.0, distance=0.0; /* was double in v1.0 */
01194   int r;
01195   
01196   wpow = GP_IDW_pow; /* GP_IDW_pow is "adjustable" parameter in global parm input file */
01197 
01198   
01199   for(i=0; i<thisStruct->fNSlotsUsed; i++) {
01200     pV = thisStruct->fList[i];
01201     dx = (pV.fX-(x+lcl_start[0]));
01202     dy = (pV.fY-(y+lcl_start[1]));
01203     r = (dx*dx + dy*dy);
01204     if( r == 0 ) return pV.fValue[step];
01205     weight = (wpow == 1.0) ? (1.0)/r : 1.0/(r*r);
01206         /* the pow() and double was incredibly slow (signif slowed simualtion), so removed it
01207            and gave the choice of only inverse distance or inverse distance**2 weighting */
01208     /* weight = (wpow == 1.0) ? ( (double)1.0)/r : pow(r,-wpow) ; */
01209     InterpValue += pV.fValue[step]*weight;
01210     distance += weight;
01211   }
01212   if (distance > 0) InterpValue /= distance;
01213   else InterpValue = (thisStruct->fList[0]).fValue[step];
01214   return (float) InterpValue;
01215 }

void PTSL_ReadLists ( PTSeriesList thisStruct,
const char *  ptsFileName,
int  index,
float *  timeStep,
int *  nPtTS,
int  col 
)

Point Time Series interpolation (unused): read raw point data.

Definition at line 1218 of file Driver_Utilities.c.

References broadcastInt(), debug, Exit(), gNPtTs, gTS, H_OPSYS, Lprocnum, modelFileName, ModelPath, msgStr, ProjName, PTSL_AddpTSeries(), UNIX, usrErr(), and WriteMsg().

Referenced by PtInterp_read().

01220 {
01221   char pathname[150], infilename[60], ss[201], ret = '\n';
01222   FILE* cfile;
01223   int ix, iy, tst, sCnt=0;
01224   if( Lprocnum == 1 ) {
01225     if(H_OPSYS==UNIX) sprintf(modelFileName,"%s/%s/Data/%s.pts",ModelPath,ProjName,ptsFileName);
01226     else sprintf(modelFileName,"%s%s:Data:%s.pts",ModelPath,ProjName,ptsFileName); 
01227     cfile = fopen(modelFileName,"r");
01228     if(cfile==NULL) {fprintf(stdout,"\nERROR: Unable to open timeseries file %s\n",modelFileName); Exit(1); }
01229     else { sprintf(msgStr,"\nReading file %s\n",modelFileName); WriteMsg(msgStr,1); } 
01230     if (debug > 2) {sprintf(msgStr,"Reading %s timeseries, column %d",modelFileName, col); usrErr(msgStr);}
01231     
01232   
01233 
01234     fgets(ss,200,cfile); /* skip header line */
01235   }
01236   while(1) {
01237     if( Lprocnum == 1 ) {
01238       tst = fscanf(cfile,"%d",&ix);
01239       if( tst > 0  ) {
01240         fscanf(cfile,"%d",&iy); 
01241         tst = fscanf(cfile,"%s",infilename); 
01242         sprintf(modelFileName,"%s/%s/Data/%s",ModelPath,ProjName,infilename);
01243       }
01244     }
01245     broadcastInt(&tst); 
01246     if(tst<1) break;
01247     broadcastInt(&ix); 
01248     broadcastInt(&iy); 
01249     PTSL_AddpTSeries(thisStruct, ix, iy, index, sCnt, col);
01250     sCnt++;
01251   }
01252   if( Lprocnum == 1 ) fclose(cfile);  
01253   *nPtTS = gNPtTs;
01254   *timeStep = gTS;
01255 } 

Here is the call graph for this function:

void PTSL_CreatePointMap ( PTSeriesList pList,
void *  Map,
unsigned char  Mtype,
int  step,
float  scale 
)

Point Time Series interpolation (unused): generate interpolated spatial (map) data.

Definition at line 1258 of file Driver_Utilities.c.

References ON_MAP, PTSL_GetInterpolatedValue0(), s0, s1, and T.

Referenced by cell_dyn1().

01260 {
01261   int i0, i1;
01262   
01263   switch(Mtype) {
01264   case 'f' :    
01265     for(i0=0; i0<=s0+1; i0++) 
01266       for(i1=0; i1<=s1+1; i1++) 
01267         ((float*)Map)[T(i0,i1)] = (ON_MAP[T(i0,i1)]) ? PTSL_GetInterpolatedValue0(pList,i0,i1,step)*scale : 0.0 /*was this value (v0.5beta) -0.012 */; 
01268     break;
01269   case 'i' :    case 'd' :      
01270     for(i0=0; i0<=s0+1; i0++) 
01271       for(i1=0; i1<=s1+1; i1++) 
01272         ((int*)Map)[T(i0,i1)] = (int)  ( (ON_MAP[T(i0,i1)]) ? PTSL_GetInterpolatedValue0(pList,i0,i1,step)*scale : 0 );
01273     break;
01274   case 'c' :    
01275     for(i0=0; i0<=s0+1; i0++) 
01276       for(i1=0; i1<=s1+1; i1++) 
01277         ((unsigned char*)Map)[T(i0,i1)] = (unsigned char) '\0' + (int)  ( (ON_MAP[T(i0,i1)]) ? PTSL_GetInterpolatedValue0(pList,i0,i1,step)*scale : 0 );
01278     break;
01279   }
01280 }

Here is the call graph for this function:

float PTSL_GetInterpolatedValue1 ( PTSeriesList thisStruct,
int  x,
int  y,
int  step 
)

Point Time Series interpolation (unused): at point, calculate inverse distance interpolation (unrestricted power of distance).

Definition at line 1283 of file Driver_Utilities.c.

References pTSeriesList::fList, pTSeriesList::fNSlotsUsed, pTSeries::fValue, pTSeries::fX, pTSeries::fY, GP_IDW_pow, RPL_AddrPoint(), RPL_Free(), RPL_Init(), and RPL_Sort().

01284 {
01285   int i,  dx, dy;
01286   PTSeries pV;
01287   RPointList *pList;
01288   float  wpow;
01289   double weight, InterpValue=0.0, distance=0.0;
01290   long r;
01291   
01292   pList = RPL_Init( 20 );
01293   wpow = GP_IDW_pow; /* GP_IDW_pow is "adjustable" parameter in global parm input file */
01294   for(i=0; i<thisStruct->fNSlotsUsed; i++) {
01295     pV = thisStruct->fList[i];
01296     dx = (pV.fX-x);
01297     dy = (pV.fY-y);
01298     r = dx*dx + dy*dy;
01299     if( r == 0 ) return pV.fValue[step];
01300     RPL_AddrPoint(pList, dx, dy, r, pV.fValue[step]);
01301     weight = (wpow == 1.0) ? ((double)1.0)/r : pow(r,-wpow);
01302     InterpValue += pV.fValue[step]*weight;
01303     distance += weight;
01304   }
01305   RPL_Sort(pList);
01306   RPL_Free(pList);
01307   return (float) InterpValue;
01308 }

Here is the call graph for this function:

void RP_SetFields ( RPoint thisStruct,
int  ix,
int  iy,
float  r,
float  value 
)

Point Time Series interpolation (unused):.

Definition at line 1311 of file Driver_Utilities.c.

References rPoint::fr, rPoint::fValue, rPoint::fX, and rPoint::fY.

Referenced by RPL_AddrPoint().

01312 {
01313   thisStruct->fX = ix;
01314   thisStruct->fY = iy;
01315   thisStruct->fr = r;
01316   thisStruct->fValue = value;   
01317 }

void RP_CopyFields ( RPoint thisStruct,
RPoint that 
)

Point Time Series interpolation (unused):.

Definition at line 1320 of file Driver_Utilities.c.

References rPoint::fr, rPoint::fValue, rPoint::fX, and rPoint::fY.

Referenced by RP_SwapFields(), and RPL_AddrPoint().

01321 {
01322   thisStruct->fX = that->fX;
01323   thisStruct->fY = that->fY;
01324   thisStruct->fr = that->fr;
01325   thisStruct->fValue = that->fValue;
01326 }

void RP_SwapFields ( RPoint thisStruct,
RPoint that 
)

Point Time Series interpolation (unused):.

Definition at line 1329 of file Driver_Utilities.c.

References RP_CopyFields().

Referenced by RPL_Sort().

01330 {
01331   RPoint temp;
01332   RP_CopyFields (&temp, thisStruct);
01333   RP_CopyFields (thisStruct, that);
01334   RP_CopyFields (that, &temp);
01335 }

Here is the call graph for this function:

RPointList* RPL_Init ( int  nPoints  ) 

Point Time Series interpolation (unused):.

Definition at line 1338 of file Driver_Utilities.c.

References rPointList::fList, rPointList::fNPt, and rPointList::fNPtUsed.

Referenced by PTSL_GetInterpolatedValue1().

01339 {
01340   RPointList *thisStruct;
01341   thisStruct = (RPointList*) malloc(sizeof(RPointList));
01342   thisStruct->fList = (RPoint*) malloc(sizeof(RPoint)*nPoints);
01343   thisStruct->fNPt = nPoints;
01344   thisStruct->fNPtUsed = 0;
01345   return thisStruct;
01346 }

void RPL_AddrPoint ( RPointList thisStruct,
int  x,
int  y,
float  r,
float  value 
)

Point Time Series interpolation (unused):.

Definition at line 1349 of file Driver_Utilities.c.

References rPointList::fList, rPointList::fNPt, rPointList::fNPtUsed, RP_CopyFields(), and RP_SetFields().

Referenced by PTSL_GetInterpolatedValue1().

01350 {
01351   RPoint* pointListtemp;
01352   int i, newPoints;
01353   
01354   if( thisStruct->fNPtUsed >= thisStruct->fNPt ) {
01355     newPoints = 20;
01356     thisStruct->fNPt += newPoints;
01357     pointListtemp = (RPoint*) malloc(sizeof(RPoint)*(thisStruct->fNPt));
01358     for(i=0; i<thisStruct->fNPtUsed; i++) {
01359       RP_CopyFields(pointListtemp+i,thisStruct->fList+i);
01360     }
01361     if( thisStruct->fList != NULL ) free((char*)thisStruct->fList);
01362     thisStruct->fList = pointListtemp;
01363   }
01364   
01365   RP_SetFields( thisStruct->fList + thisStruct->fNPtUsed, x, y, r, value);
01366   thisStruct->fNPtUsed++;
01367 }

Here is the call graph for this function:

void RPL_Sort ( RPointList thisStruct  ) 

Point Time Series interpolation (unused):.

Definition at line 1370 of file Driver_Utilities.c.

References rPointList::fList, rPointList::fNPtUsed, rPoint::fr, and RP_SwapFields().

Referenced by PTSL_GetInterpolatedValue1().

01371 {
01372   int i, go=1;
01373   
01374   while(go) {
01375     go = 0;
01376     for(i=1; i<thisStruct->fNPtUsed; i++) if(thisStruct->fList[i-1].fr > thisStruct->fList[i].fr) {
01377       RP_SwapFields (thisStruct->fList+i-1, thisStruct->fList+i);
01378       go = 1;
01379     }
01380   }             
01381 }

Here is the call graph for this function:

void RPL_Free ( RPointList thisStruct  ) 

Point Time Series interpolation (unused):.

Definition at line 1385 of file Driver_Utilities.c.

References rPointList::fList.

Referenced by PTSL_GetInterpolatedValue1().

01386 {
01387   if(thisStruct == NULL) return;
01388    if( thisStruct->fList != NULL ) free((char*)thisStruct->fList);
01389   free((char*)thisStruct);
01390   thisStruct = NULL;
01391 }

void setFlag ( ViewParm vp,
UINT  mask,
int  value 
)

(Effectively unused). From Model.outList data, set a flag indicating array or not

In reading the Model.outList, each line pertain to either a 2D array (variable) or a non-array varible/parameter. This function pertains to very early version of ELM (translating Stella models), and Model.outList always refers to variables that are arrays.

Parameters:
vp struct of ViewParm w/ output configuration
mask array mask
value is always = 1 (is an array)

Definition at line 1405 of file Driver_Utilities.c.

References viewParm::flags.

Referenced by readViewParms().

01406  { 
01407   if(value) vp->flags |= mask; else vp->flags &= ~mask;
01408 }

int getFlag ( ViewParm vp,
UINT  mask 
)

Unused (never called) function.

Definition at line 1411 of file Driver_Utilities.c.

References viewParm::flags.

01412 { 
01413   if( vp->flags & mask ) return 1; else return 0;
01414 }

void setPrecision ( ViewParm vp,
int  value 
)

(Effectively unused).

Definition at line 1417 of file Driver_Utilities.c.

References viewParm::flags, PMASK1, and PMASK2.

Referenced by readViewParms().

01418 {
01419   if(value/3) vp->flags |= PMASK2; else vp->flags &= ~PMASK2;
01420   if((value-1)%2) vp->flags |= PMASK1; else vp->flags &= ~PMASK1;
01421 }

int getPrecision ( ViewParm vp  ) 

(Effectively unused).

Definition at line 1424 of file Driver_Utilities.c.

References viewParm::flags, PMASK1, and PMASK2.

Referenced by write_output().

01425  { 
01426   int rv = 1;
01427   if(vp->flags & PMASK2) rv +=2;
01428   if(vp->flags & PMASK1) rv +=1;
01429   return rv;
01430 }

int check_for ( char *  s0,
const char *  s1,
int  start,
int  cs,
int  rp 
)

Check for occurrences of string s1 in string s0 after position start.

After position start, check for occurrences of string s1 in string s0.

Parameters:
s0 String array
s1 String array
start Starting position
cs Case sensitivity
rp Return pointer to beginning or not
Returns:
location in string

Definition at line 1443 of file Driver_Utilities.c.

References BEG, and NOCASE.

Referenced by write_map_file().

01444 {
01445   /*  Check for occurrences of string s1 in string s0   */
01446   /*  after position start. Return -1 if not found.             */
01447   /* if cs = CASE -> case sensitive, cs = NOCASE, not case sens.        */
01448   /* if rp = BEG -> return position of beginning of s1,         */
01449   /*                    otherwise return position of (next char following the) end of s1                */
01450   int i, j=0, k=-1, Len1 = strlen(s1), Len0 = strlen(s0);
01451   char t1, t2;
01452   
01453   while(k<0) {
01454     k=0;
01455     for(i=start; i< Len0; ++i) { 
01456       t1 = s0[i];
01457       t2 = s1[j];
01458       if(cs==NOCASE) { t1 = tolower(t1); t2 = tolower(t2); }   
01459       if (t1 == t2)  j++;
01460       else {j=0; k=0;}
01461       if(j==Len1) { k=1; break; }
01462     }
01463   }
01464   if(k<=0)              return(-1);
01465   else if(rp==BEG)      return(i-Len1+1);
01466   else                  return(i+1);
01467 }

int isInteger ( char *  target_str  ) 

Determine if an integer is present in string.

Parameters:
target_str Target string
Returns:
true or false (found int or not)

Definition at line 1475 of file Driver_Utilities.c.

Referenced by ReadStructures(), and readViewParms().

01475                                  {
01476 
01477         int i=-1,first_num=0;
01478         char ch;
01479 
01480         while( (ch=target_str[++i]) != '\0' ) { 
01481                         if( isdigit(ch) ) first_num=1;
01482                         if( (ch=='-' || ch=='+') && first_num ) return(0);  
01483                         if( !( isspace(ch) || isdigit(ch) || ch=='-' || ch=='+') ) return(0);  
01484         }
01485         return(1);              
01486 }

int isFloat ( char *  target_str  ) 

Determine if a float is present in string.

Parameters:
target_str Target string
Returns:
true or false (found float or not)

Definition at line 1493 of file Driver_Utilities.c.

Referenced by ReadStructures(), and readViewParms().

01493                                {
01494 
01495         int i=-1,first_num=0;
01496         char ch;
01497 
01498         while( (ch=target_str[++i]) != '\0' ) { 
01499                         if( isdigit(ch) ) first_num=1;
01500                         if( (ch=='-' || ch=='+') && first_num ) return(0);  
01501                         if( !( isspace(ch) || isdigit(ch) || ch=='-' || ch=='+' || ch=='.' || toupper(ch) == 'E') ) return(0);  
01502         }
01503         return(1);              
01504 }

void WriteMsg ( const char *  msg,
int  wh 
)

Send a message to a debug file or to the console.

Depending on when this function is called, messages are sent to one of two debug-related files, or to the console. During initial model set-up, the first (Driver0.out) debug-info file is used to print confirmation information on items such as init/end dates of simulation, the model parameter values that were read, etc. During later access to this function while the model is iterating, the second (Driver1.out) file is opened and accessed here, followed by the X'th for multi-run sensitivity analyses.

Parameters:
msg A string message for printing
wh Unused

Definition at line 1519 of file Driver_Utilities.c.

References Driver_outfile.

Referenced by cell_dyn1(), cell_dyn12(), cell_dyn2(), cell_dyn7(), cell_dyn8(), cell_dyn9(), Combine(), flowCalc_CanCan(), flowCalc_CanCel(), flowCalc_CelCan(), flowData_CanCan(), flowData_CanCel(), flowData_CelCan(), flowData_CelCel(), Flux_GWcells(), Flux_SWstuff(), FluxChannel(), get_global_parm(), get_hab_parm(), get_modexperim_parm(), get_Nth_parm(), get_parmf(), HabSwitch_Init(), main(), make_more_points(), print_point(), PTS_SetFields(), PTSL_ReadLists(), read_map_dims(), read_map_file(), read_model_parameters(), Read_schedule(), ReadModExperimParms(), readOutlist(), ReadStructures(), readViewParms(), SensiParm_list(), setup_grid(), write_map_file(), and write_output().

01519                                        {
01520   wh = 1;
01521   if(Driver_outfile) fprintf(Driver_outfile,"%s\n",msg);
01522   else fprintf(stdout,"%s\n",msg);
01523   fflush(stdout);
01524 }

void usrErr0 ( const char *  dString  ) 

Send a message to the console.

The message text is not followed by a line feed.

Parameters:
dString A string message to print

Definition at line 1530 of file Driver_Utilities.c.

Referenced by alloc_mem_stats(), alloc_memory(), horizFlow(), init_dynam_data(), init_eqns(), init_static_data(), main(), PtInterp_read(), rain_data_wmm(), read_model_parameters(), ReadModExperimParms(), ReadStructFlow_PtSer(), ReadStructTP_PtSer(), ReadStructTS_PtSer(), reinitBIR(), and reinitCanals().

01531 {
01532   fprintf(stderr,"%s", dString); 
01533   fflush(stderr);
01534 }

void usrErr ( const char *  dString  ) 

void Exit ( int  code  ) 

Standard exit from program.

Definition at line 1548 of file Driver_Utilities.c.

Referenced by fatal(), get_global_parm(), get_modexperim_parm(), getCanalElev(), nalloc(), PTSL_ReadLists(), and read_map_dims().

01548 { exit(code); }

void fatal ( const char *  msg  ) 

Exit (code=9) from program after sending a message.

Definition at line 1551 of file Driver_Utilities.c.

References Exit().

Referenced by goto_index(), and print_point().

01552 {
01553   printf("%s",msg);
01554   fflush(stdout);
01555   Exit(9);
01556 }

Here is the call graph for this function:

double julday ( int  mon,
int  day,
int  year,
int  h,
int  mi,
double  se 
)

Determine the Julian calendar day from a Gregorian date.

Returns:
julian day + hms as a real number
Takes a date, and returns a Julian day. A Julian day is the number of days since some base date (in the very distant past). Handy for getting date of x number of days after a given Julian date (use jdate to get that from the Gregorian date). Author: Robert G. Tantzen, translator: Nat Howard Translated from the algol original in Collected Algorithms of CACM (This and jdate are algorithm 199). All taken (unmodified) from SFWMD HSM's /vol/hsm/src/libs/xmgr_julday/ directory.

Parameters:
mon Month
day Day
year Year
h Hour
mi Minute
se Second
Returns:
Julian day

Definition at line 1583 of file Driver_Utilities.c.

Referenced by get_parmf(), readSeriesCol(), ReadStructFlow_PtSer(), ReadStructTP_PtSer(), and ReadStructTS_PtSer().

01584 {
01585   long m = mon, d = day, y = year;
01586   long c, ya, j;
01587   double seconds = h * 3600.0 + mi * 60 + se;
01588 
01589   if (m > 2)
01590     m -= 3;
01591   else {
01592     m += 9;
01593     --y;
01594   }
01595   c = y / 100L;
01596   ya = y - (100L * c);
01597   j = (146097L * c) / 4L + (1461L * ya) / 4L + (153L * m + 2L) / 5L + d + 1721119L;
01598   if (seconds < 12 * 3600.0) {
01599     j--;
01600     seconds += 12.0 * 3600.0;
01601   } 
01602   else {
01603     seconds = seconds - 12.0 * 3600.0;
01604   }
01605   return (j + (seconds / 3600.0) / 24.0);
01606 }

void calcdate ( double  jd,
int *  m,
int *  d,
int *  y,
int *  h,
int *  mi,
double *  sec 
)

Determine the Gregorian date from a Julian calendar day.

Julian date converter. Takes a julian date (the number of days since some distant epoch or other), and returns an int pointer to static space. ip[0] = month; ip[1] = day of month; ip[2] = year (actual year, like 1977, not 77 unless it was 77 a.d.); ip[3] = day of week (0->Sunday to 6->Saturday) These are Gregorian. Copied from Algorithm 199 in Collected algorithms of the CACM Author: Robert G. Tantzen, Translator: Nat Howard. All taken (unmodified) from SFWMD HSM's /vol/hsm/src/libs/xmgr_julday/ directory.

Parameters:
jd Julian day
m Month
d Day
y Year
h Hour
mi Minute
sec Second

Definition at line 1630 of file Driver_Utilities.c.

Referenced by send_point_lists2(), and track_time().

01631 {
01632   static int ret[4];
01633 
01634   long j = (long)jd;
01635   double tmp, frac = jd - j;
01636 
01637   if (frac >= 0.5) {
01638     frac = frac - 0.5;
01639     j++;
01640   } 
01641   else {
01642     frac = frac + 0.5;
01643   }
01644 
01645   ret[3] = (j + 1L) % 7L;
01646   j -= 1721119L;
01647   *y  = (4L * j - 1L) / 146097L;
01648   j = 4L * j - 1L - 146097L * *y;
01649   *d  = j / 4L;
01650   j = (4L * *d + 3L) / 1461L;
01651   *d = 4L * *d + 3L - 1461L * j;
01652   *d = (*d + 4L) / 4L;
01653   *m = (5L * *d - 3L) / 153L;
01654   *d = 5L * *d - 3 - 153L * *m;
01655   *d = (*d + 5L) / 5L;
01656   *y = 100L * *y + j;
01657   if (*m < 10)
01658     *m += 3;
01659   else {
01660     *m -= 9;
01661     *y += 1;
01662   }
01663   tmp = 3600.0 * (frac * 24.0);
01664   *h = (int) (tmp / 3600.0);
01665   tmp = tmp - *h * 3600.0;
01666 
01667   *mi = (int) (tmp / 60.0);
01668   *sec = tmp - *mi * 60.0;
01669 }

float FMOD ( float  x,
float  y 
)

Modulus of a pair of (double) arguments.

Parameters:
x Numerator
y Denominator
Returns:
modulus (float) result

Definition at line 1675 of file Driver_Utilities.c.

Referenced by cell_dyn1(), CellAvg(), Flows_in_Structures(), gen_output(), init_eqns(), main(), and Run_Canal_Network().

01675                              { 
01676 return (float)fmod((double)x, (double)y); 
01677 } 

void getFloat ( FILE *  inFile,
const char *  lString,
float *  fValPtr 
)

Get a float value following a specific string.

Parameters:
inFile File that is open
lString The string being read
fValPtr The float number found

Definition at line 1683 of file Driver_Utilities.c.

References scan_forward().

Referenced by get_parmf().

01684 {
01685   int test, fSize;
01686   UCHAR iEx=0;
01687   if(lString)  scan_forward(inFile,lString);
01688   test = fscanf(inFile,"%f",fValPtr);
01689   if(test != 1) {
01690     fprintf(stderr,"Read Error (%d):",test);
01691     if(lString) fprintf(stderr,"%s\n",lString);
01692     *fValPtr = 0.0;
01693     iEx = 1;
01694   }
01695   if (iEx) exit(0);
01696 }

Here is the call graph for this function:

void getChar ( FILE *  inFile,
const char *  lString,
char *  cValPtr 
)

Get a character following a specific string.

Parameters:
inFile File that is open
lString The string being read
cValPtr The char value found

Definition at line 1702 of file Driver_Utilities.c.

References scan_forward().

01703 {
01704   int test;
01705   UCHAR iEx=0;
01706   if(lString)  scan_forward(inFile,lString);
01707   test = fscanf(inFile,"%c",cValPtr);
01708   if(test != 1) {
01709     fprintf(stderr,"Read Error (%d):",test);
01710     if(lString) fprintf(stderr,"%s\n",lString);
01711     iEx = 1;
01712     *cValPtr = '\0';
01713   }
01714   if (iEx) exit(0);
01715 }

Here is the call graph for this function:

void getString ( FILE *  inFile,
const char *  lString,
char *  inString 
)

Get a string following a specific string.

Parameters:
inFile File that is open
lString The string being read
inString The string found

Definition at line 1722 of file Driver_Utilities.c.

References scan_forward().

Referenced by get_parmf().

01723 {
01724   int test;
01725   UCHAR iEx=0;
01726   if(lString)  scan_forward(inFile,lString);
01727   test = fscanf(inFile,"%s",inString);
01728   if(test != 1) {
01729     fprintf(stderr,"Read Error (%d):",test);
01730     if(lString) fprintf(stderr,"%s\n",lString);
01731     iEx = 1;
01732   }
01733   if (iEx) exit(0);
01734 }

Here is the call graph for this function:

void getInt ( FILE *  inFile,
const char *  lString,
int *  iValPtr 
)

Get an integer following a specific string.

Parameters:
inFile File that is open
lString The string being read
iValPtr The char value found

Definition at line 1740 of file Driver_Utilities.c.

References scan_forward().

Referenced by get_parmf().

01741 {
01742   int test;
01743   UCHAR iEx=0;
01744   if(lString)  
01745     scan_forward(inFile,lString);
01746   test = fscanf(inFile,"%d",iValPtr);
01747   if(test != 1) {
01748     fprintf(stderr,"Read Error (%d):",test);
01749     if(lString) fprintf(stderr,"%s\n",lString);
01750     *iValPtr = 0;
01751     iEx = 1;
01752   }
01753   if (iEx) exit(0);
01754 }

Here is the call graph for this function:

int find_char ( FILE *  infile,
char  tchar 
)

Find a character.

Parameters:
infile The file that is open
tchar The character being sought
Returns:
true/false (0 or 1)

Definition at line 1760 of file Driver_Utilities.c.

Referenced by get_Nth_parm(), and goto_index().

01761 {
01762   char test = '1', cchar = '#';
01763   int in_c=0;
01764 
01765   while( test != EOF ) {
01766     test = fgetc(infile);
01767     if(test == tchar && in_c==0 ) { return 1; }
01768     if(test == cchar ) in_c=1;
01769     if(test == '\n' )  in_c=0;
01770   }
01771   return(0);
01772 }

int Round ( float  x  ) 

truncate (not rounding) to an integer

Parameters:
x the value being operated on
Returns:
result

Definition at line 1777 of file Driver_Utilities.c.

Referenced by Channel_configure().

01778 { 
01779   int i = (int)x;
01780   return (i);
01781 }

char* Scip ( char *  s,
char  SYM 
)

Skip ahead in a string until next field.

Parameters:
s A character array
SYM The specific symbol being used to skip over
Returns:
Location in string

Definition at line 1788 of file Driver_Utilities.c.

References EOS.

Referenced by BIRinit(), get_hab_parm(), Read_schedule(), ReadStructFlow_PtSer(), ReadStructTP_PtSer(), ReadStructTS_PtSer(), and ReadStructures().

01789 {
01790   if(*s == SYM ) return ++s;
01791   while(*s != SYM && *s != EOS ) s++;
01792   if(*s != EOS) return ++s;
01793   else  return s;
01794 }

int skip_white ( FILE *  infile  ) 

Skip white space(s) in a file.

Parameters:
infile 
Returns:
success/failure

Definition at line 1800 of file Driver_Utilities.c.

Referenced by get_parmf(), and init_config_file().

01801 {
01802   int ch;
01803   
01804   while( isspace(ch=fgetc(infile)) ) {;}
01805   if(ch==EOF) return 0;
01806   ungetc(ch,infile);
01807   return 1;             
01808 }  

int scan_forward ( FILE *  infile,
const char *  tstring 
)

Scan forward until a particular string is found.

Parameters:
infile The file being read
tstring The sought-after string
Returns:
Success/failure

Definition at line 1814 of file Driver_Utilities.c.

Referenced by get_global_parm(), get_modexperim_parm(), get_parmf(), getChar(), getFloat(), getInt(), getString(), read_header(), read_map_dims(), and readSeriesCol().

01815 {
01816   int sLen, i, cnt=0;
01817   char Input_string[100], test;
01818   
01819   sLen = strlen(tstring);
01820   while( ( test = fgetc(infile) ) != EOF ) {
01821     for(i=0; i<(sLen-1); i++) 
01822         Input_string[i] = Input_string[i+1];
01823     Input_string[sLen-1] = test;
01824     Input_string[sLen] = '\0';
01825     if(++cnt >= sLen) {
01826       test =  strcmp(Input_string,tstring);
01827       if( test == 0 ) return 1;
01828     }
01829   }
01830   return(-1);
01831 }

char* name_from_path ( char *  name  ) 

Get the var name from a longer path/filename.

Parameters:
name The var name & path
Returns:
Pointer to var name alone

Definition at line 1837 of file Driver_Utilities.c.

Referenced by quick_look().

01838 {
01839   char* namePtr; int i, slen;
01840   char dirCh;
01841   
01842   namePtr = name;
01843   dirCh = '/';
01844   slen = strlen(name);
01845   
01846   for(i=0; i<slen; i++) {
01847         if( name[slen-i-1] == dirCh ) { namePtr = name+slen-i; break; }
01848   }
01849   return namePtr;  
01850 }

VOIDP nalloc ( unsigned  mem_size,
const char  var_name[] 
)

Allocate memory for a variable.

Parameters:
mem_size The size of memory space
var_name The variable's name
Returns:
Pointer to that memory

Definition at line 1857 of file Driver_Utilities.c.

References Exit(), fasync(), fmulti(), total_memory, and VOIDP.

Referenced by alloc_hab_hist(), alloc_mem_stats(), alloc_memory(), Canal_Network_Init(), Channel_configure(), initDataStruct(), read_map_file(), readSeriesCol(), ReadStructFlow_PtSer(), readViewParms(), setup_grid(), and write_map_file().

01858 {
01859   VOIDP rp;
01860 
01861   
01862   if(mem_size == 0) return(NULL);
01863   rp = (VOIDP)malloc( mem_size );
01864   total_memory += mem_size;
01865   fasync(stderr);
01866   if( rp == NULL ) {
01867     fprintf(stderr,"Sorry, out of memory(%d): %s\n",mem_size,var_name);
01868     Exit(0);
01869   }
01870   fmulti(stderr);
01871   return(rp);
01872 }

Here is the call graph for this function:

float Normal ( float  mean,
float  sd 
)

Unused, never called. Normal distribution.

Definition at line 1875 of file Driver_Utilities.c.

References gRTable, and SMDRAND().

01876 {
01877     int table_loc ;
01878     double rand_num ;
01879     float sign ;
01880     float interval = .1 ;
01881     int n_interval = 40 ;
01882     float high, low ;
01883     float return_val = 0.0;
01884 
01885     sign = SMDRAND(0.0, 1.0) ;
01886     sign = (sign < .5 ? -1 : 1) ;
01887     rand_num = SMDRAND(.5, 1.0);
01888     low = gRTable[0] ;
01889     for (table_loc=1; table_loc<n_interval; table_loc++)
01890     {
01891         high = gRTable[table_loc] ;
01892         if (high > rand_num + .5)
01893         {
01894             return_val = mean + sd * (sign  * interval * (table_loc - 1 +
01895                                                           (rand_num+.5-low)/(high-low))) ;
01896             return(return_val) ;
01897         }
01898         low = high ;
01899     }
01900     return(return_val) ;
01901 }

Here is the call graph for this function:

int Poisson ( float  mu  ) 

Unused, never called. Poisson distribution.

Definition at line 1904 of file Driver_Utilities.c.

References Exp, and SMDRAND().

01905 {
01906   int ix;
01907   float f0, r, Lp = 1, xf = 1, p=0;
01908   
01909   p = f0 = Exp(-mu);
01910   r = SMDRAND(0.0,1.0);
01911   
01912   for( ix=0; ix<500; ix++) {
01913     if( r < p ) return ix;
01914     Lp *= mu;
01915     if(ix>0) xf *= ix;
01916     p += (Lp*f0)/xf;
01917   }
01918   return ix;    
01919 }

Here is the call graph for this function:

void link_edges ( VOIDP  Map,
unsigned char  Mtype 
)

Effectively unused in serial (non-parallel) implementation.

Definition at line 1924 of file Driver_Utilities.c.

References exchange_borders().

Referenced by read_map_file().

01925 {
01926   switch(Mtype) {
01927   case 'f' :    
01928     exchange_borders((byte*)Map,sizeof(float)); break;
01929   case 'd' : case 'i' : 
01930     exchange_borders((byte*)Map,sizeof(int)); break;
01931   case 'c' :    
01932     exchange_borders((byte*)Map,sizeof(UCHAR)); break;
01933   }     
01934 }

Here is the call graph for this function:

void setup_platform (  ) 

Effectively unused in serial (non-parallel) implementation.

Definition at line 1937 of file Driver_Utilities.c.

References env, exgridcoord(), exgridinit(), exgridsplit(), exparam(), nprocs, nodenv::nprocs, nodenv::procnum, procnum, recpnum, and usrErr().

Referenced by setup().

01937                       {
01938  
01939   exparam(&env);
01940   procnum = env.procnum;
01941   exgridsplit(env.nprocs, 2, nprocs);
01942   if( exgridinit(2, nprocs) < 0) { usrErr("Failed to Setup Grid"); exit(0); }
01943   exgridcoord(procnum, recpnum);
01944 }

Here is the call graph for this function:


Generated on Sat Jan 7 14:04:24 2012 for ELM source code by  doxygen 1.5.6