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

serial.h File Reference

Header file for Serial (non-parallel) utilities. More...

#include "globals.h"

Include dependency graph for serial.h:

Include dependency graph

This graph shows which files directly or indirectly include this file:

Included by dependency graph

Go to the source code of this file.

Data Structures

struct  combo_table

Defines

#define HDF_VERIFY(a)   if(ret == FAIL) { printf("*** UNEXPECTED RETURN from %s is %d\n", a, (int)ret); }
#define MAXCOMBOS   30

Functions

void writeMap (char *, void *, int, unsigned char, int)
 Write data for spatial (map) output binary file.
void write_header (char *mapFileName, int size)
 Write header info for spatial (map) output binary file.
void send_point_lists2 (SeriesParm *pSeries, int nSeries)
 Point time series output: print time series data to file(s).
void writeSeries (void *fValue, char *label, char *desc, int N0, int N1, byte Mtype, byte format)
 Write to a spatial data window in a debug file.
void Combine (float *fValue, char *label, int nComp, int cType, int step)
 A variety of stat summaries in a selected spatial window (debug-related).
void open_point_lists (SeriesParm *pSeries, int nSeries)
 Point time series output: open files and print headers.
void exparam (struct nodenv *envInfo)
 Parallel code: effectively unused in serial implementation.
void exgridsplit (int nprocs, int ndim, int nprocs2[2])
 Parallel code: effectively unused in serial implementation.
void exgridcoord (int pnum, int rnum[2])
 Parallel code: effectively unused in serial implementation.
void exgridsize (int pnum, int gsize[2], int lsize[2], int lstart[2])
 Parallel code: effectively unused in serial implementation.
void set_async_mode (FILE *file)
 Parallel code: does nothing in serial implementation).
void fmulti (FILE *file)
 Parallel code: does nothing in serial implementation).
void fsingl (FILE *file)
 Parallel code: does nothing in serial implementation).
void fasync (FILE *file)
 Parallel code: does nothing in serial implementation).
void exchange_borders (UCHAR *map, int size)
 Parallel code: does nothing in serial implementation).
void Cplot (VOIDP Map, unsigned char Mtype, float max_value, float min_value)
 Parallel code: does nothing in serial implementation).
void broadcastMsg (UCHAR *msgPtr)
 Parallel code: does nothing in serial implementation).
void broadcastInt (int *iValPtr)
 Parallel code: does nothing in serial implementation).
void broadcastChar (UCHAR *cPtr)
 Parallel code: does nothing in serial implementation).
void broadcastData (void *dataPtr, int *dataSize)
 Parallel code: does nothing in serial implementation).
void broadcastFloat (void *dataPtr)
 Parallel code: does nothing in serial implementation).
void sync_processors ()
 Parallel code: does nothing in serial implementation).
void open_debug_outFile (int index)
 Open debug-related output files.
int exgridinit (int dim, int *nprocs)
 Parallel code: does nothing in serial implementation).
int on_this_proc (int x, int y)
 Parallel code: does nothing in serial implementation).
void local_setup (int argc, char **argv)
 Does very little in serial implementation (opens a low-level debug file).
int init_config_file (FILE *vpFile, char term1, char term2, char term3, char term4)
 Get format definition of output configuration file (does nothing effective!).
int skip_cnfg_space (FILE *vpFile, char *tch)
 Skip spaces in reading (model outlist) configuration file.
int parse_packet (FILE *vpFile, int *nArgs, char *test)
 Parse through a configuration fileline to obtain the configuration commands.
int get_number (FILE *infile)
 Get a numeric digit from a file.
int goto_index (FILE *infile, char tchar, int index)
 Go to a particular indexed/demarked point in the habitat-specfic parameter file.
int read_header (char *mapfile)
 Read header info for spatial (map) input binary file.
int getCombineIndex (char *name, int step, int type, int *last)
 A variety of stat summaries in a selected spatial window (debug-related).
float * get_hab_parm (char *s_parm_name, int s_parm_relval, char *parmName)
 Read the input data file to get a habitat-specfic parameter array.
float get_global_parm (char *s_parm_name, int s_parm_relval, char *parmName)
 Read the input data file to get a global parameter.
float get_Nth_parm (FILE *infile, int pIndex, int *end, int hIndex)
 Get the N'th parameter in the habitat-specfic parameter file.
char * match_Sparm (char *s_parm_name, int s_parm_relval, char *parmName)
 Determine if the parameter is being varied for a sensitivity analysis.
float SMDRAND (float fminVal, float fmaxVal)
 Psuedo-random number generator (unused).
float * readSeriesCol (char *filename, int format, int index, int *Npt, float *TStep, int col)
 (Unused). Read time series input data for spatial interpolations
byte readMap (char *, void *)
 Read data for spatial (map) input binary file.
void fatal (const char *msg)
 Exit (code=9) from program after sending a message.
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.
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.
int find_char (FILE *infile, char tchar)
 Find a character.
double julday (int mon, int day, int year, int h, int mi, double se)
 Determine the Julian calendar day from a Gregorian date.
VOIDP nalloc (unsigned mem_size, const char var_name[])
 Allocate memory for a variable.

Variables

char gSectorChar = '@'
char gHabChar = '^'
int habNumTot = 0
char fileDelimitChar = 'È'
char cTemp [200]
char gTerm [4]
char gCArg [kCArgDepth][kCArgWidth]
int cell_pts [MAX_TS_FILES]
int numPtFiles = 0
FILE * dFile
FILE * Driver_outfile
FILE ** cnfgFile
combo_table ctable [MAXCOMBOS]
UINT max_combos_open
int gSLen [MAX_NHAB]
char * ProjName
char * ModelPath
char * OutputPath
char modelName [20]
char modelVers [10]
char SimAlt [20]
char SimModif [20]
int gbl_size [2]
int seed
int procnum
int Lprocnum
int nprocs [2]
int nproc
int recpnum [2]
int tramType
int tramNum [2]
int PORnumday
double Jdate_init


Detailed Description

Header file for Serial (non-parallel) utilities.

This defines or declares variables & functions that are global to Serial.c.

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

The Everglades Landscape Model (ELM).
last updated: Dec 2004

Definition in file serial.h.


Define Documentation

#define HDF_VERIFY  )     if(ret == FAIL) { printf("*** UNEXPECTED RETURN from %s is %d\n", a, (int)ret); }
 

Definition at line 27 of file serial.h.

Referenced by writeSeries().

#define MAXCOMBOS   30
 

Maximum # of current combos used for spatial array summaries (debug-related)

Definition at line 60 of file serial.h.


Function Documentation

void writeMap char *  filename,
void *  data,
int  bSize,
unsigned char  type,
int  index
 

Write data for spatial (map) output binary file.

Parameters:
filename Filename (variable name) of data
data Data array
bSize Byte size of data
type Type, or format, of (binary) data
index Index used in HDF output (which is unused)

Definition at line 125 of file Serial.c.

References gbl_size, s0, s1, and write_header().

Referenced by write_map_file().

00126 {
00127   int gsize, istat;
00128   FILE* bFile; 
00129   
00130   if(type=='M') write_header(filename,bSize);
00131   
00132   if(type == 'H') {
00133 #if HDF
00134     if(index==0) { istat = DFR8putimage(filename,(char*)data,s1,s0,0); }
00135     else { istat = DFR8addimage(filename,(char*)data,s1,s0,0); }
00136     if(istat != 0) printf("\nerror writing HDF file: %s\n",filename);
00137 #endif
00138   } 
00139   else {
00140     if((bFile = fopen(filename,"wb") ) == NULL ) { 
00141       fprintf(stderr,"Can't Open Mapfile: %s",filename); 
00142       exit(0); 
00143     }
00144     gsize = gbl_size[0]*gbl_size[1]*bSize;
00145     fwrite((char*)data, gsize, 1, bFile );
00146     fclose(bFile);
00147   }
00148 }

Here is the call graph for this function:

void write_header char *  mapFileName,
int  size
 

Write header info for spatial (map) output binary file.

Parameters:
mapFileName Filename (variable name) of data
size Byte size of data

Definition at line 154 of file Serial.c.

References dFile, and gbl_size.

Referenced by writeMap().

00155 {
00156   FILE* header;
00157   fprintf(dFile,"Writing Header: filen = %s\n",mapFileName); 
00158   fflush(dFile);
00159   header = fopen(mapFileName,"w");
00160   if(header==NULL) { 
00161     fprintf(stderr,"Can't open header file: %s\n",mapFileName); 
00162     fflush(stderr); exit(-1); 
00163   }
00164   fprintf(header,"ROWS=%d\nCOLUMNS=%d\nCELLSIZE=1", 
00165                   gbl_size[0], gbl_size[1]);
00166   fprintf(header,"\nUNITS=KM\nFORMAT=BIN\nSIZE=%d\nLOCATION=\"%s.bin\"\n",
00167                   size,mapFileName); /* prior to v2.3, had the file delimited by the fileDelimitChar */
00168   fclose(header);
00169   strcat(mapFileName,".bin");
00170 }

void send_point_lists2 SeriesParm pSeries,
int  nSeries
 

Point time series output: print time series data to file(s).

open_point_lists Has documentation relevant to this function

Parameters:
pSeries A struct of the variables to have point time series output
nSeries Number of point time series occurances

Definition at line 474 of file Serial.c.

References calcdate(), cell_pts, Jdate_init, seriesParm::laststep, seriesParm::Length, msgStr, numPtFiles, OutputPath, seriesParm::outstep, ProjName, pSeries, and SeriesParm.

Referenced by main().

00475 {
00476   FILE *oFile;
00477   int i=0, ii, j, ix, iy, k= 0, last_pt;
00478   int yr_pt[2],mo_pt[2],da_pt[2],hr_pt[2],mi_pt[2];    
00479   double se_pt[2];           
00480   double Jdate_pt;
00481   
00482   if (numPtFiles==0) return;
00483   /* k = file/variable counter; i = indiv cellLoc time series counter */
00484   for (k = 0; k <= numPtFiles; k++) { /* loop over the number of point ts files */
00485       sprintf(msgStr,"%s%s/Output/PtSer/%s.pts",OutputPath,ProjName,pSeries[i].name);
00486       if( (oFile = fopen(msgStr,"a") ) == NULL) { 
00487           fprintf(stderr,"\nERROR, unable to open %s point time series output file.",msgStr); 
00488           exit(-1); 
00489       }
00490 
00491       for(j=pSeries[i].laststep; j<pSeries[i].Length; j++ ) { /*temporal loop */
00492           Jdate_pt = Jdate_init+j*pSeries[i].outstep;
00493           calcdate( Jdate_pt, mo_pt, da_pt, yr_pt, hr_pt, mi_pt, se_pt); /* get the calendar date info from the julian date */
00494           fprintf(oFile,"\n%d/%d/%d\t",yr_pt[0],mo_pt[0],da_pt[0] ); /* calendar date in col 1 */
00495 
00496           last_pt = i+cell_pts[k]; /* # of last cellLoc point of the current variable's file */
00497           for (ii=i; ii<last_pt; ii++) {/* loop over number of point locations per file */
00498               fprintf(oFile,"%f\t",pSeries[ii].data[j]);
00499           }
00500       }
00501       fclose (oFile); 
00502       pSeries[i].laststep = j; /* remember the last temporal outstep for this file */
00503       i += cell_pts[k];     /* increment the indiv cellLoc time series counter */ 
00504   }
00505   return;
00506 }

Here is the call graph for this function:

void writeSeries void *  fValue,
char *  label,
char *  desc,
int  N0,
int  N1,
byte  Mtype,
byte  format
 

Write to a spatial data window in a debug file.

Parameters:
fValue Model variable (local) array data
label Output message label (w/ variable name)
desc Message describing the output
N0 Range in x (row!) values
N1 Range in y (col!) values
Mtype General output format type
format Numeric format type

Definition at line 520 of file Serial.c.

References cTemp, Driver_outfile, HDF_VERIFY, OutputPath, ProjName, and UCHAR.

Referenced by writeWindow().

00521 {
00522         /* check on these! (who wrote this? Why? (HCF Dec'04) )*/
00523   int ix, iy; 
00524   static unsigned char first_write = 1;
00525   long int  ret, dimsizes[2];
00526   unsigned short int refnum;
00527   if(format == 'H') {
00528   
00529 #if HDF   
00530           dimsizes[0] = N0;
00531           dimsizes[1] = N1;
00532           sprintf(cTemp,"%s%s:Output:Windows.hdf",OutputPath,ProjName);
00533           DFSDclear();
00534           
00535           switch(Mtype) {
00536                  case 'f': 
00537                     DFSDsetNT(DFNT_FLOAT32);  break;
00538                  case 'L': 
00539                     DFSDsetNT(DFNT_FLOAT32);  break;
00540                  case 'E': 
00541                     DFSDsetNT(DFNT_FLOAT32);  break;
00542                  case 'd': case 'i': 
00543                     DFSDsetNT(DFNT_INT32);  break;
00544                  case 'c': 
00545                     DFSDsetNT(DFNT_UINT8);  break;
00546           }
00547           if(first_write) {
00548                 ret = DFSDputdata(cTemp,2,dimsizes,fValue);
00549                 first_write = 0;
00550           } else {
00551                 ret = DFSDadddata(cTemp,2,dimsizes,fValue);
00552           }
00553           HDF_VERIFY("DFSDadddata");
00554           refnum = DFSDlastref();
00555           ret = DFANputlabel(cTemp,DFTAG_SDG,refnum,label);
00556           HDF_VERIFY("DFANputlabel");
00557           ret = DFANputdesc(cTemp,DFTAG_SDG,refnum,desc,strlen(desc));
00558           HDF_VERIFY("DFANputdesc");
00559 #endif
00560   }
00561   else {
00562     fprintf(Driver_outfile,"\n_________%s\n",label);    
00563     fprintf(Driver_outfile,"%s\n",desc);        
00564     for (ix=0; ix<N0; ix++) {
00565       fprintf(Driver_outfile,"\n");
00566       for (iy=0; iy<N1; iy++) {
00567         switch(Mtype) {
00568           case 'f': 
00569                 if(format=='L')                 fprintf(Driver_outfile,"%f ",*(((float*)fValue)+iy+ix*N1)); 
00570                 else if(format=='E')    fprintf(Driver_outfile,"%.3E ",*(((float*)fValue)+iy+ix*N1)); 
00571                         else                            fprintf(Driver_outfile,"%.3f ",*(((float*)fValue)+iy+ix*N1));
00572                         break;
00573         case 'd': case 'i': 
00574                         fprintf(Driver_outfile,"%d ",*(((int*)fValue)+iy+ix*N1)); 
00575                         break;
00576         case 'c': 
00577                         fprintf(Driver_outfile,"%x ",*(((UCHAR*)fValue)+iy+ix*N1)); 
00578                         break;
00579         }
00580       }
00581     }  
00582   }
00583 }

void Combine float *  fValue,
char *  label,
int  nComp,
int  cType,
int  step
 

A variety of stat summaries in a selected spatial window (debug-related).

This determines maximum, minimum, sum, average, either cumulatively over iterations or not cumulatively. This Model.outList command has not been used in ELM, and has not been verified for accuracy.

Parameters:
fValue Model variable (local) array data
label variable name
nComp number of comps
cType The combination (stats) type
step The current iteration number

Definition at line 598 of file Serial.c.

References ctable, combo_table::fvalue, getCombineIndex(), kAVE, kAVECUM, kMAX, kMAXMIN, kMIN, kSUM, kSUMCUM, msgStr, and WriteMsg().

Referenced by calc_maxmin(), and print_loc_ave().

00599 {
00600         int print, cIndex, i, cum;
00601         static int type = 11;
00602         char tmpStr[50];
00603         if( ++type > 99) type = 11;
00604 
00605         cum = ((cType == kAVECUM) || (cType == kSUMCUM)) ? 1 : 0;       
00606         if(cum) { cIndex = getCombineIndex(label,step,cType,&print); }
00607         
00608         switch(cType) {
00609                 case kMAXMIN: 
00610                         sprintf(msgStr,"\nMAXMIN(%d) for %s:",step,label); 
00611                         for(i=0; i<nComp; i++) { sprintf(tmpStr," %f",fValue[i]); strcat(msgStr,tmpStr); }
00612                         WriteMsg(msgStr,1);
00613                 break;
00614                 case kMAX:
00615                         sprintf(msgStr,"\nMAX(%d) for %s:",step,label); 
00616                         for(i=0; i<nComp; i++) { sprintf(tmpStr," %f",fValue[i]); strcat(msgStr,tmpStr); }
00617                         WriteMsg(msgStr,1);
00618                 break;
00619                 case kMIN:
00620                         sprintf(msgStr,"\nMIN(%d) for %s:",step,label); 
00621                         for(i=0; i<nComp; i++) { sprintf(tmpStr," %f",fValue[i]); strcat(msgStr,tmpStr); }
00622                         WriteMsg(msgStr,1);
00623                 break;
00624                 case kSUM:
00625                         sprintf(msgStr,"\nSUM(%d) for %s:",step,label); 
00626                         for(i=0; i<nComp; i++) { sprintf(tmpStr," %f",fValue[i]); strcat(msgStr,tmpStr); }
00627                         WriteMsg(msgStr,1);
00628                 break;
00629                 case kAVE:
00630                         sprintf(msgStr,"\nAVE(%d) for %s:",step,label); 
00631                         for(i=0; i<nComp; i+=2) { sprintf(tmpStr," %f",fValue[i]/fValue[i+1]); strcat(msgStr,tmpStr); }
00632                         WriteMsg(msgStr,1);
00633                 break;
00634                 case kSUMCUM:
00635                         if( print == -1) {
00636                                 for(i=0; i<nComp; i++) ctable[cIndex].fvalue[i] = fValue[i]; 
00637                         
00638                         } else {
00639                                 for(i=0; i<nComp; i++) ctable[cIndex].fvalue[i] += fValue[i]; 
00640                         }
00641                         if(print==1) {                          
00642                                 sprintf(msgStr,"\nSUMCUM(%d) for %s:",step,label); 
00643                                 for(i=0; i<nComp; i++) { sprintf(tmpStr," %f",ctable[cIndex].fvalue[i]); strcat(msgStr,tmpStr); }
00644                                 WriteMsg(msgStr,1);
00645                         }
00646                 break;
00647                 case kAVECUM:
00648                         if( print == -1) {
00649                                 for(i=0; i<nComp; i++) ctable[cIndex].fvalue[i] = fValue[i]; 
00650                         
00651                         } else {
00652                                 for(i=0; i<nComp; i++) ctable[cIndex].fvalue[i] += fValue[i]; 
00653                         }
00654                         if(print==1) {                          
00655                                 sprintf(msgStr,"\nAVECUM(%d) for %s:",step,label); 
00656                                 for(i=0; i<nComp; i+=2) { sprintf(tmpStr," %f",ctable[cIndex].fvalue[i]/ctable[cIndex].fvalue[i+1]); strcat(msgStr,tmpStr); }
00657                                 WriteMsg(msgStr,1);
00658                         }
00659                 break;
00660         }
00661 }       

Here is the call graph for this function:

void open_point_lists SeriesParm pSeries,
int  nSeries
 

Point time series output: open files and print headers.

Provides for multi-column (locations), multi-file (model variables)format of point time series. The user can define (via Model.outList commands), for any variable in the model, one or more cell (point) locations for which point time series data are written. There can be multiple point TS each for different variables. Thus, we make a separate file for each variable (unknown until user chooses) that has multiple columns for multiple points (unknown until user chooses).

Parameters:
pSeries An array of SeriesParm structs for point time series output
nSeries Number of point time series occurances
Remarks:
A structure should/could be set up for this, but to maintain minimal changes between the parallel and serial versions of the code (ELMv1.0), for now we just maintain the original data structure and use some counters below to keep track of diff files and numbers of columns (also allowing different output steps as chosen by the user). (Note: The original SME code printed all variables in one column in one file).
Note:
TODO: this whole point-time-series output functionality needs improvement (not high priority, Jan 2005). One of the more important capabilities is to have ability to have irregular, calendar-month/year etc output intervals.

Definition at line 431 of file Serial.c.

References cell_pts, seriesParm::data, seriesParm::Loc, modelName, modelVers, msgStr, numPtFiles, OutputPath, ProjName, pSeries, SeriesParm, SimAlt, SimModif, point2D::x, and point2D::y.

Referenced by main().

00432 {
00433   FILE *oFile;
00434   int i, j, ix, iy, k= 0 ;
00435 
00436   for (i=0; i<nSeries; i++) {
00437      if( pSeries[i].data == NULL ) {
00438         if ( numPtFiles>0 ) fclose(oFile); /* in (rare?) case where user asks for no point output, no files stream to close */
00439         return;
00440       }
00441       if (strcmp(pSeries[i].name,pSeries[i-1].name) != 0) {
00442               /* this is new variable, thus new file.  numPtFiles== increment counter of number of variables (one file per variable) used for output */
00443           if (i>0) { 
00444             numPtFiles++; 
00445             fclose (oFile); 
00446           }
00447           
00448           sprintf(msgStr,"%s%s/Output/PtSer/%s.pts",OutputPath,ProjName,pSeries[i].name);
00449           if( (oFile = fopen(msgStr,"w") ) == NULL) { 
00450               fprintf(stderr,"\nERROR, unable to open %s point time series output file.",msgStr); 
00451               exit(-1); 
00452           }
00453           fprintf (oFile, "%s %s %s %s scenario: \nDate\t", &modelName, &modelVers, &SimAlt, &SimModif);
00454           
00455       }
00456 /* populate the grid cell locations in the header for this variable/file */
00457       ix = pSeries[i].Loc.x;
00458       iy = pSeries[i].Loc.y;
00459       fprintf(oFile,"%s:(%d,%d)\t",pSeries[i].name,ix,iy);
00460       cell_pts[numPtFiles]++; /* count the number of cell point locs per variable (1 var per file) */
00461       
00462   }
00463 }

void exparam struct nodenv envInfo  ) 
 

Parallel code: effectively unused in serial implementation.

Definition at line 986 of file Serial.c.

References nodenv::groupid, nodenv::nprocs, nodenv::procnum, and nodenv::taskid.

Referenced by setup_platform().

00987 {       
00988         envInfo->procnum = 1;
00989         envInfo->nprocs = 1;
00990         envInfo->groupid = 0;
00991         envInfo->taskid = 0;
00992  
00993 }

void exgridsplit int  nprocs,
int  ndim,
int  nprocs2[2]
 

Parallel code: effectively unused in serial implementation.

Definition at line 1000 of file Serial.c.

Referenced by setup_platform().

01001 {
01002   nprocs2[0] = 1;
01003   nprocs2[1] = 1;
01004 }

void exgridcoord int  pnum,
int  rnum[2]
 

Parallel code: effectively unused in serial implementation.

Definition at line 1007 of file Serial.c.

References tramNum.

Referenced by setup_platform().

01008 {
01009     tramNum[0] = rnum[0] = 0;
01010     tramNum[1] = rnum[1] = 0;
01011 }

void exgridsize int  pnum,
int  gsize[2],
int  lsize[2],
int  lstart[2]
 

Parallel code: effectively unused in serial implementation.

Definition at line 1014 of file Serial.c.

References nprocs, and recpnum.

Referenced by setup_grid().

01015 {
01016         int rem[2], i, j;
01017         for( i=0; i<2; i++ ) {
01018                 lsize[i] = gsize[i]/nprocs[i];
01019                 rem[i] = gsize[i] - lsize[i]*nprocs[i];
01020                 if(recpnum[i]<rem[i]) lsize[i]++;
01021                 for(j=0; j<recpnum[i]; j++) if( j<rem[i] && recpnum[i] >= rem[i] ) lstart[i] += (lsize[i]+1); else lstart[i] += lsize[i];
01022         }
01023 }

void set_async_mode FILE *  file  ) 
 

Parallel code: does nothing in serial implementation).

Definition at line 1026 of file Serial.c.

01027 { return;}

void fmulti FILE *  file  ) 
 

Parallel code: does nothing in serial implementation).

Definition at line 1030 of file Serial.c.

Referenced by nalloc().

01031 { return;}

void fsingl FILE *  file  ) 
 

Parallel code: does nothing in serial implementation).

Definition at line 1034 of file Serial.c.

01035 { return;}

void fasync FILE *  file  ) 
 

Parallel code: does nothing in serial implementation).

Definition at line 1038 of file Serial.c.

Referenced by nalloc().

01039 { return;}

void exchange_borders UCHAR map,
int  size
 

Parallel code: does nothing in serial implementation).

Definition at line 1043 of file Serial.c.

Referenced by link_edges().

01044 {return;}

void Cplot VOIDP  Map,
unsigned char  Mtype,
float  max_value,
float  min_value
 

Parallel code: does nothing in serial implementation).

Definition at line 1051 of file Serial.c.

01052 {}

void broadcastMsg UCHAR msgPtr  ) 
 

Parallel code: does nothing in serial implementation).

Definition at line 1055 of file Serial.c.

01056 {}

void broadcastInt int *  iValPtr  ) 
 

Parallel code: does nothing in serial implementation).

Definition at line 1059 of file Serial.c.

Referenced by get_parmf(), PTSL_ReadLists(), and read_map_dims().

01060 {}

void broadcastChar UCHAR cPtr  ) 
 

Parallel code: does nothing in serial implementation).

Definition at line 1063 of file Serial.c.

01064 {}

void broadcastData void *  dataPtr,
int *  dataSize
 

Parallel code: does nothing in serial implementation).

Definition at line 1067 of file Serial.c.

01068 {}

void broadcastFloat void *  dataPtr  ) 
 

Parallel code: does nothing in serial implementation).

Definition at line 1075 of file Serial.c.

01076 {}

void sync_processors  ) 
 

Parallel code: does nothing in serial implementation).

Definition at line 1071 of file Serial.c.

01072 {return;}

void open_debug_outFile int  index  ) 
 

Open debug-related output files.

The Driver0.out and Driver1.out are two output files with debug and/or standard error-warning information. They are always produced, but have varying levels of detail (esp. Driver1.out) depending on the user-selected (at run-time) level of the "debug" variable. Driver0.out basically provides initial, static information on data and setup of the model. Driver1.out provides dynamic information on the simulation. In sensitivity analysis mode, subsequent Driver2.out, Driver3.out, etc provide dynamic information on each new simulation.

Parameters:
index Index to indicate file name w/ "0", "1", and subsequent runs under a sensitivity analysis

Definition at line 720 of file Serial.c.

References Driver_outfile, OutputPath, and ProjName.

Referenced by get_parmf(), and main().

00721 {
00722   char filename[120];
00723   
00724   sprintf(filename,"%s/%s/Output/Debug/Driver%d.out",OutputPath,ProjName,index);
00725 
00726   Driver_outfile = fopen(filename,"w");
00727   if(Driver_outfile == NULL) { 
00728         fprintf(stderr,"Error, unable to open %s file.\n",filename);
00729         fprintf(stderr,"OutputPath: %s\n",OutputPath);  
00730         fprintf(stderr,"Project: %s\n",ProjName);  
00731         exit(0); 
00732   }
00733 
00734 }

int exgridinit int  dim,
int *  nprocs
 

Parallel code: does nothing in serial implementation).

Definition at line 996 of file Serial.c.

Referenced by setup_platform().

00997 { return 0;}

int on_this_proc int  x,
int  y
 

Parallel code: does nothing in serial implementation).

Definition at line 1047 of file Serial.c.

Referenced by quick_look().

01048 { return 1; }

void local_setup int  argc,
char **  argv
 

Does very little in serial implementation (opens a low-level debug file).

Primarily intended for parallel apps:
establish processor attributes, open a low-level debug file (in the user's current directory, set by the model execution script ("go"), and seed the pseudo-random number.

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

Definition at line 950 of file Serial.c.

References ctable, dFile, combo_table::free, Lprocnum, max_combos_open, nprocs, combo_table::ocnt, procnum, recpnum, seed, tramType, and usrErr().

Referenced by main().

00951 {
00952   int i;
00953   char debugfileName[300];
00954   nprocs[0] = 1;
00955   nprocs[1] = 1;
00956   tramType =  0;
00957   procnum = 1;
00958   recpnum[0] = 0;
00959   recpnum[1] = 0;
00960   Lprocnum = 1;
00961   /* the combo_table (ctable) used in Combine operation for spatial array summaries (debug-related) */ 
00962   max_combos_open = 0;  
00963   for(i = 0; i < MAXCOMBOS; i++) {
00964     ctable[i].ocnt = 0; 
00965     ctable[i].free = 1;
00966   }
00967 
00968   /* this debug output file is not used extensively in current code - it is opened before we get
00969      environment vars, thus is written to user's current directory ($ModelPath/$ProjName/Load if
00970      ELM is executed from the "go" script) */ 
00971  dFile = fopen("ELM.debug","w");
00972   if(dFile == NULL) { 
00973     usrErr("Can't open ELM.debug file."); 
00974     exit(0); 
00975   } 
00976   /* there are no random processes in current ELM (v2.4) w/o fire */ 
00977   srand(seed);
00978   fprintf(dFile," RAND_MAX = %d\n",(int)RAND_MAX);
00979 }

Here is the call graph for this function:

int init_config_file FILE *  vpFile,
char  term1,
char  term2,
char  term3,
char  term4
 

Get format definition of output configuration file (does nothing effective!).

Identifies the leading characters in the Model.outlist output configuration file that define its format, which will never change from it's value of "#2". (This is another SME component of past flexibility.)

Parameters:
vpFile Pointer to the (model outlist) configuration file
term1 The character "#"
term2 The character "*"
term3 The character "@"
term4 The character "~"
Returns:
The (integer) format of the configuration file

Definition at line 747 of file Serial.c.

References gTerm, and skip_white().

Referenced by readViewParms().

00748 {
00749   char test;
00750   int format,size=-1;
00751 
00752   gTerm[0] = term1;
00753   gTerm[1] = term2;  
00754   gTerm[2] = term3;  
00755   gTerm[3] = term4;  
00756   skip_white(vpFile);
00757   test = fgetc(vpFile);
00758   if(test == gTerm[0])
00759       fscanf(vpFile,"%d",&format);
00760   else
00761       format = -1;
00762   return format;
00763 }

Here is the call graph for this function:

int skip_cnfg_space FILE *  vpFile,
char *  tch
 

Skip spaces in reading (model outlist) configuration file.

Parameters:
vpFile Pointer to file being read
tch A space
Returns:
negative or success

Definition at line 771 of file Serial.c.

References cnfgFile, and gTerm.

Referenced by parse_packet().

00772 {
00773         char ch; int rv = 1;
00774         ch = *tch;
00775         while( isspace(ch) ) { 
00776                 if( (ch=fgetc(vpFile)) == EOF || ch == gTerm[3] || ch == '\0' ) {
00777                         fclose(vpFile); cnfgFile = NULL; return -3; 
00778                 }
00779         }
00780         *tch = ch;
00781         return rv;
00782 }

int parse_packet FILE *  vpFile,
int *  nArgs,
char *  test
 

Parse through a configuration fileline to obtain the configuration commands.

Populates gCArg[][] with command info. In very early versions of ELM, this was used in reading the configuration file that translated "Stella" model equations into spatial (SME) code. Thus, much of the detail here is unused (ELM v1.0 and later) when reading the output (e.g., Model.outList) configuration file (both w/ similar syntax).

Parameters:
vpFile Pointer to the (model outlist) configuration file
nArgs Number of arguments in command
test A character that will be used to indicate an array (in outlist, always is array, char="*")
Returns:
The index (aka index sequence of variables) of the ViewParm

Definition at line 796 of file Serial.c.

References cTemp, gCArg, gTerm, kCArgWidth, and skip_cnfg_space().

Referenced by readViewParms().

00797 {
00798     static      int     gVPindex = -1;
00799     static      char    gCnfg;
00800     
00801         char ch = ' ', eChar = ' '; 
00802         int btype=0, argc=2, go=1, i=0, j=0, new_name = 0;
00803 
00804         if(vpFile == NULL) return -3;
00805         while (1) {
00806                 if ( skip_cnfg_space(vpFile, &ch) < 0) return -3; j=0;
00807                 if( ch == gTerm[1] || ch == gTerm[2] ) {
00808                     gCnfg = ch; ch = ' ';
00809                         if ( skip_cnfg_space(vpFile, &ch) < 0 ) return -3;
00810                         while ( !isspace(ch) ) { cTemp[j++] = ch; ch=fgetc(vpFile); }
00811                         cTemp[j++] = '\0'; new_name = 1;
00812                         gVPindex++;
00813                 }
00814                 else break;
00815         }
00816         strcpy(gCArg[0],cTemp);
00817         *test = gCnfg;
00818         while ( isalnum( ch ) ) { gCArg[1][i++]=ch; ch=fgetc(vpFile); }
00819         gCArg[1][i]='\0'; i=0;
00820         while( 1 ) {
00821                 if( ch == '(' ) { eChar = ')'; break;} 
00822                 else if( ch == '[' ) { eChar = ']'; break;} 
00823                 else if( ch == '{' ) { eChar = '}'; break;} 
00824                 else if( !isspace(ch) ) { return -3;}
00825                 ch=fgetc(vpFile);
00826         }
00827         while (go) {
00828                 while( ch=fgetc(vpFile) ) {
00829                         if( ch == ',' ) { argc++; break; }
00830                         if( ch == ')' ||  ch == '}' ||  ch == ']')  { 
00831                                 if( ch == eChar ) {  argc++; go=0; break;} 
00832                                 else { printf( "\nWarning: Syntax error in parse_config, var: %s\n",gCArg[0]); return -2; } 
00833                         }
00834                         gCArg[argc][i++]=ch;
00835                         if( i==(kCArgWidth-1) ) break;
00836                 }
00837                 if(i==0) { printf( "\nWarning: Syntax error in parse_config, var: %s\n",gCArg[0]); return -2; } 
00838                 else { gCArg[argc-1][i]='\0'; i=0; }
00839                 if(argc == kCArgDepth) { 
00840                         while( ch != eChar ) ch=fgetc(vpFile);  
00841                         go = 0; 
00842                 }
00843         }
00844         *nArgs = argc;
00845         if(argc==0) { printf( "\nWarning: Syntax error in parse_config, var: %s\n",gCArg[0]); return -2; }
00846         else return gVPindex;           
00847 } 

Here is the call graph for this function:

int get_number FILE *  infile  ) 
 

Get a numeric digit from a file.

Parameters:
infile file pointer
Returns:
The digit

Definition at line 855 of file Serial.c.

Referenced by goto_index().

00855                                {
00856         char ch;
00857         int rv;
00858         
00859         ch = fgetc(infile);
00860         if( !isdigit( ch ) ) return(-1);
00861         rv = ch - '0';
00862         
00863         while( isdigit( ch = fgetc(infile) ) ) 
00864                 rv = rv*10 + ( ch - '0' );
00865                 
00866         return rv;
00867 }

int goto_index FILE *  infile,
char  tchar,
int  index
 

Go to a particular indexed/demarked point in the habitat-specfic parameter file.

Parameters:
infile file pointer
tchar special character that denotes either habitat or module/sector
index index that points to either habitat or module/sector number
Returns:
succes/fail

Definition at line 876 of file Serial.c.

References fatal(), find_char(), and get_number().

Referenced by get_hab_parm().

00877 {
00878         int rv=1, current_index=-1, itest;
00879 
00880         while(current_index != index) { 
00881                 itest = find_char (infile, tchar);
00882                 if(itest <= 0) return 0;
00883                 current_index = get_number(infile);
00884                 if(current_index < 0) fatal("Bad number format in dBase");
00885         }
00886         return 1;
00887 }

Here is the call graph for this function:

int read_header char *  filename  ) 
 

Read header info for spatial (map) input binary file.

Parameters:
filename data variable's file name
Returns:
byte size of data values

Definition at line 67 of file Serial.c.

References dFile, gbl_size, ModelPath, ProjName, and scan_forward().

Referenced by readMap().

00068 {
00069   FILE* file;
00070   char headerFileName[300];
00071   
00072   int rows, cols, i, Dsize=1, test, offset;
00073   char ch, dirCh;
00074   long int start;
00075         
00076   sprintf(headerFileName,"%s/%s/Data/Map_head/%s",ModelPath,ProjName,filename);
00077 
00078   file = fopen(headerFileName,"r");
00079   if(file==NULL) { 
00080     fprintf(stderr,"Unable to open header file %s.\n",headerFileName); 
00081     fflush(stderr); 
00082     exit(0);
00083   }
00084   else { 
00085     fprintf(dFile,"Successfully opened header file %s.\n",headerFileName);  
00086     fflush(dFile); 
00087   } 
00088   scan_forward(file,"cols:");
00089   fscanf(file,"%d",&cols);
00090   fprintf(dFile,"cols = %d\n",cols); 
00091   scan_forward(file,"rows:");
00092   fscanf(file,"%d",&rows);
00093   fprintf(dFile,"rows = %d\n",rows);
00094   fflush(dFile);
00095   if( !( rows == gbl_size[0] && cols == gbl_size[1] ) ) { 
00096     fprintf(stderr,"Error, Wrong map size: %s: (%d,%d) : (%d,%d)\n",
00097              headerFileName,rows,gbl_size[0],cols,gbl_size[1]); 
00098   }
00099   start = ftell(file);
00100   test = scan_forward(file,"format:");
00101   if(test < 1) { 
00102     clearerr(file); 
00103     fseek(file, start, 0); 
00104   }
00105   else {        
00106     fscanf(file,"%d",&Dsize);
00107     fprintf(dFile,"size = %d\n",Dsize);
00108     Dsize = Dsize + 1; /* using header generated by GRASS, the byte size is actually the value read from header plus 1 */
00109     if( Dsize < 1 || Dsize > 4 ) {  
00110       fprintf(stderr,"Error, Illegal map size: %s  (%d)\n",headerFileName,Dsize); 
00111       exit(0); 
00112     }
00113   }
00114   fclose(file);
00115   return Dsize;
00116 }

Here is the call graph for this function:

int getCombineIndex char *  name,
int  step,
int  type,
int *  last
 

A variety of stat summaries in a selected spatial window (debug-related).

This determines maximum, minimum, sum, average, either cumulatively over iterations or not cumulatively. This Model.outList command has not been used in ELM, and has not been verified for accuracy.

Parameters:
name variable name
step The current iteration number
type The combination (stats) type
last 
Returns:
index of the count

Definition at line 675 of file Serial.c.

References ctable, dFile, combo_table::free, max_combos_open, msgStr, combo_table::step, combo_table::type, and usrErr().

Referenced by Combine().

00676 {
00677         int count, index = -1;
00678         *last = 0;
00679         
00680         for(count = 0; count < max_combos_open; count++) {
00681         
00682                 if( ctable[count].free )        {                       /* Determine if the slot is in use. */
00683                         if(index == -1) index = count;          /* Nope, keep track of first free global stream table slot. */ 
00684                         if(debug) { fprintf(dFile,"cnt = %d, index = %d, free combo stream\n",count,index); fflush(dFile); }
00685                 }
00686                 else if( strncmp(name,ctable[count].name,25) == 0 && ctable[count].type == type ) {
00687                     *last = 1; 
00688                     if(debug) { 
00689                       fprintf(dFile,"\n(%s)combo cnt = %d, step = %d, type = %d\n",
00690                               name,count,step,type); 
00691                         fflush(dFile); 
00692                     }
00693                     return count;
00694                 }
00695         }
00696         if( index == -1 ) { 
00697                 index = max_combos_open; 
00698                 if( ++max_combos_open > MAXCOMBOS) { sprintf(msgStr,"Out of combo slots: %s, step=%d, type=%d\n",name,step,type);  usrErr(msgStr); return -1; }
00699         }
00700         if(debug) { fprintf(dFile,"\n(%s)index = %d, step=%d, set-up combo\n",name,index,step); fflush(dFile); }
00701         strncpy(ctable[index].name,name,25);
00702         ctable[index].step = step;
00703         ctable[index].type = type;
00704         ctable[index].free = 0;
00705         *last = -1;
00706         return index;
00707 }

Here is the call graph for this function:

float* get_hab_parm char *  s_parm_name,
int  s_parm_relval,
char *  parmName
 

Read the input data file to get a habitat-specfic parameter array.

This gets an array of the targeted parameter, a value for each of (usually) multiple habitats.

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)
parmName String that identifies the parameter to be read in dbase file
Returns:
fTmp Array of values of single parameter across multiple habitats

Definition at line 268 of file Serial.c.

00269 {
00270         int hIndex, end=0;
00271         FILE* parmFile;
00272         float* fTmp;
00273         char lline[2001], *line;
00274         int pLoc = -1;
00275         int foundParm= False;
00276         char parmNameHead[30];
00277         char modelFileName[300];
00278     char HabParmFile[300];
00279     char *fileAppend;
00280     extern ProgAttr *ProgExec;
00281     
00282         
00283         if ( (fTmp = (float*) malloc( MAX_NHAB * sizeof(float) ) ) == NULL) {
00284         sprintf(msgStr, "Failed to allocate memory for HabParm array.\n ") ;
00285         usrErr(msgStr);
00286         exit( -2 ) ;
00287         };
00288         fTmp[0] = 0.0;
00289 
00290     fileAppend = match_Sparm( s_parm_name, s_parm_relval, parmName);
00291         sprintf(HabParmFile,"HabParms_%s",fileAppend);
00292         sprintf(modelFileName,"%s/%s/Data/%s",ModelPath,ProjName,HabParmFile);
00293         parmFile = fopen(modelFileName,"r");
00294         if(parmFile==NULL) {fprintf(stdout,"\nERROR: Unable to open dBase file %s\n",modelFileName); exit(-1); }
00295         
00296      fgets(lline, 2000, parmFile); /* skip 1st header line  */
00297      fgets(lline, 2000, parmFile); /* read 2nd header line with column names */
00298      line=lline;
00299 
00300      while (!foundParm)  
00301      {
00302         sscanf( line,"%s",&parmNameHead);
00303         if (strcmp(parmName,parmNameHead) ==0) foundParm = True;
00304         pLoc++;
00305         if (*line == EOS || *line == EOL) {
00306            sprintf(msgStr,"ERROR: Could not find header tag of %s in HabParms dbase file.", parmName); 
00307            usrErr(msgStr); 
00308            exit(-1);
00309         }
00310         line = Scip( line, TAB );
00311      }
00312     
00313     sprintf(msgStr,"Parameter group: %s",parmName); 
00314     fflush(dFile); 
00315     WriteMsg(msgStr,1); 
00316         for( hIndex = 1; hIndex < MAX_NHAB; hIndex++) {
00317                 goto_index (parmFile, gHabChar, hIndex); 
00318                 fTmp[hIndex] = get_Nth_parm( parmFile, pLoc, &end, hIndex );
00319                 if(end) break;
00320         }
00321         fclose(parmFile);
00322         habNumTot = hIndex-1;
00323 
00324         fflush(dFile); 
00325         /* TODO: this HARDCODES into the BIR (BIRavg) model output file ONLY, 
00326         the incorrect impression of running sensitivity on a single habitat ID 
00327         (hab 2 = sawgrass plain, ELMv2.4) */
00328     if (strcmp(s_parm_name,parmName) == 0) ProgExec->S_ParmVal = fTmp[2];
00329         return fTmp; 
00330 }

float get_global_parm char *  s_parm_name,
int  s_parm_relval,
char *  parmName
 

Read the input data file to get a global parameter.

This gets the single global value of the targeted parameter.

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)
parmName String that identifies the parameter to be read in dbase file
Returns:
parmVal The value of the global parameter

Definition at line 372 of file Serial.c.

00373 {
00374   int test;
00375   char modelFileName[300];
00376   FILE *parmFile;
00377   float parmVal;
00378   char parmNameHead[30];
00379   extern ProgAttr *ProgExec;
00380 
00381 
00382   char GlobalParmFile[50];
00383   char *fileAppend;
00384   
00385   fileAppend = match_Sparm( s_parm_name, s_parm_relval, parmName);
00386   sprintf(GlobalParmFile,"GlobalParms_%s",fileAppend);
00387   sprintf(modelFileName,"%s/%s/Data/%s",ModelPath,ProjName,GlobalParmFile);
00388   
00389   parmFile = fopen(modelFileName,"r");
00390   if(parmFile==NULL) { 
00391         sprintf(msgStr,"ERROR, can't open data file %s",modelFileName); 
00392     usrErr(msgStr);
00393         Exit(0); 
00394   }
00395 
00396   sprintf(parmNameHead,"%s=", parmName);
00397   scan_forward(parmFile,parmNameHead);
00398   if ( (test = fscanf(parmFile,"%f",&parmVal) ) <= 0 ) { 
00399     sprintf(msgStr,"ERROR in reading %s from %s; see Driver0.out debug file.", parmName, modelFileName); 
00400     usrErr(msgStr);
00401     Exit(0); 
00402   }
00403   sprintf(msgStr,"%s %f\n",parmNameHead, parmVal); 
00404   WriteMsg(msgStr,1); 
00405 
00406   fclose(parmFile);
00407   if (strcmp(s_parm_name,parmName) == 0) ProgExec->S_ParmVal = parmVal;
00408   return parmVal;
00409 }

float get_Nth_parm FILE *  infile,
int  pIndex,
int *  end,
int  hIndex
 

Get the N'th parameter in the habitat-specfic parameter file.

After finding the correct habitat and module/sector location in the file, get the value of a parameter.

Parameters:
infile file pointer
pIndex the index number of a parameter within a module set of parms
end denotes end of file
hIndex the index number of current habitat being read
Returns:
the parameter value

Definition at line 900 of file Serial.c.

References dFile, find_char(), msgStr, usrErr(), and WriteMsg().

Referenced by get_hab_parm().

00901 {
00902         int i=1, itest=1;
00903         float rv; char ch;
00904         
00905         while ( (i++ < pIndex) && itest > 0 ) { itest = find_char ( infile, '\t' ); }
00906         if( itest == 0 ) { *end = 1; return(0.0); }
00907         
00908         itest = fscanf(infile,"%f",&rv);
00909         if(itest==1) { 
00910         if(debug) { 
00911            sprintf(msgStr,"Habitat %d:\t%f",hIndex,rv); 
00912            WriteMsg(msgStr,1); 
00913         }
00914         }
00915         else if ( (ch = fgetc(infile)) == EOF ) { *end = 1; return(0.0); }
00916         else {
00917                 sprintf(msgStr,"Read Error in dBase(%d)\n REad Dump:\n",itest); WriteMsg(msgStr,1); usrErr(msgStr);
00918                 for(i=0; i<12; i++) { 
00919                         ch = fgetc(infile);
00920                         if(ch==EOF) { sprintf(msgStr,"\nAt EOF\n"); WriteMsg(msgStr,1); break; }
00921                         else fputc(ch,dFile);
00922                 }
00923                 exit(0);
00924         }
00925         *end = 0;
00926         return(rv);
00927 }

Here is the call graph for this function:

char* match_Sparm char *  s_parm_name,
int  s_parm_relval,
char *  parmName
 

Determine if the parameter is being varied for a sensitivity analysis.

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)
parmName String that identifies the parameter to be read in dbase file
Returns:
fileAppend The suffix (not extension) to be appended to end of base name of parameter input file.

Definition at line 339 of file Serial.c.

References msgStr, and usrErr().

Referenced by get_global_parm(), and get_hab_parm().

00340 {
00341     char *fileAppend;
00342  
00343     if (strcmp(s_parm_name,parmName) == 0) /* match, it is a parameter being varied in this set of runs */
00344         { 
00345                 switch (s_parm_relval) {
00346                    case 0: fileAppend = "NOM"; break;
00347                    case 1: fileAppend = "LO"; break;
00348                    case 2: fileAppend = "HI"; break;
00349                    default:  {
00350                       sprintf(msgStr,"ERROR: The relative parameter value (%d) is unknown for %s",s_parm_relval, s_parm_name); 
00351                       usrErr(msgStr);
00352                       exit(-1);
00353                    }
00354            }
00355         }
00356     else
00357         { /* no match, it is NOT a parameter being varied in this set of runs */
00358               fileAppend = "NOM"; 
00359             }
00360     return (fileAppend);
00361 }

Here is the call graph for this function:

float SMDRAND float  fminVal,
float  fmaxVal
 

Psuedo-random number generator (unused).

Definition at line 931 of file Serial.c.

Referenced by Normal(), and Poisson().

00932 { 
00933   float rv, tmp;
00934   tmp = rand();
00935   rv = fminVal + (fmaxVal-fminVal)*(tmp/RAND_MAX); 
00936   return(rv);
00937 } 

float* readSeriesCol char *  filename,
int  format,
int  index,
int *  Npt,
float *  TStep,
int  col
 

(Unused). Read time series input data for spatial interpolations

Parameters:
filename Filename of data
format Always float data format
index Unused. Was used to concatenate multiple files over time
Npt Number of time points
TStep Time step
col column ID (for different variables)

Definition at line 182 of file Serial.c.

References debug, dFile, julday(), nalloc(), and scan_forward().

Referenced by PTS_SetFields().

00183 {
00184     int line = 0, cread=1, itest, j, sLen = 372 ;
00185     FILE *cfile;
00186     char  ctest, cmark[373], ret = '\n';
00187     unsigned char cmove[373], cmv=0;
00188     char tfilename[200], date_read[20],ss[200];
00189     int yyyy,mm, dd;
00190     double Jdate_read; 
00191     float  *tvar, *nullvar, first[10];
00192 
00193     sprintf(tfilename,"%s%d.ts",filename,index);
00194     if(debug>4) fprintf(dFile,"\nReading file %s, col %d, index = %d\n",tfilename,col,index); fflush(dFile);
00195     cfile = fopen(tfilename,"r"); 
00196     if(cfile==NULL) {  
00197         if( index > 0 ) {  fprintf(stdout,"\nWARNING: Unable to open timeseries file %s, using %s0.ts\n",tfilename,filename); return 0; } 
00198         else { fprintf(stdout,"\nERROR: Unable to open timeseries file %s\n",tfilename); exit(-1); } 
00199     }
00200 
00201     if (format != 2) { fprintf(stderr,"ERROR: only using floats in read_timeseries: %d\n",format); exit(0); }
00202     
00203            sLen = PORnumday; /* read/determined in genericDriver */
00204             tvar = (float*) nalloc( (sLen+2)*sizeof(float), "timeseries temp" );
00205             scan_forward(cfile,"{END COMMENT}\n");
00206             fgets(ss,200,cfile); /* skip  the header line */
00207             
00208             do {
00209                 fscanf(cfile, "%d %d %d %f %f %f %f", &yyyy,&mm,&dd,&first[1],&first[2],&first[3],&first[4] ); 
00210         /* julian day, returns a double (args = month, day, year, hours, minutes, seconds) */
00211                 Jdate_read = julday(mm, dd, yyyy, 0, 0, 0); 
00212                 if (Jdate_read > Jdate_init) {printf (" \n***Error\nInit date in %s file > simulation start date.\n",tfilename); exit (-1);}
00213                 if (feof(cfile)) {
00214         printf (" \n***Error\nNon-matching starting date for %s meteorological time series\n",tfilename); 
00215                         exit (-1);
00216                 }
00217             } while (Jdate_read < Jdate_init);
00218             
00219             tvar[0] = first[col]; /* have now read the first data record, assign to array */
00220             if(debug>4) fprintf(dFile,"%d %d %d %f\n",yyyy,mm,dd,tvar[0]);
00221             for (line = 1; line<sLen; line++) {
00222             
00223             /* each case for reading a different column */
00224                 switch (col) {
00225                     case 1:
00226                         itest = fscanf(cfile,"%d %d %d %f %f %f %f",&yyyy,&mm,&dd, &(tvar[ line ]),&nullvar, &nullvar, &nullvar);
00227                         break;
00228                     case 2:
00229                         itest = fscanf(cfile,"%d %d %d %f %f %f %f",&yyyy,&mm,&dd,&nullvar, &(tvar[ line ]), &nullvar, &nullvar);
00230                         break;
00231                     case 3:
00232                         itest = fscanf(cfile,"%d %d %d %f %f %f %f",&yyyy,&mm,&dd,&nullvar, &nullvar, &(tvar[ line ]), &nullvar);
00233                         break;
00234                     case 4:
00235                         itest = fscanf(cfile,"%d %d %d %f %f %f %f",&yyyy,&mm,&dd,&nullvar, &nullvar, &nullvar, &(tvar[ line ]));
00236                         break;
00237                     default:
00238                         printf ("\nError in interpolation time series data.\n"); 
00239                         exit(-1);
00240                         break;
00241                 } /* end switch */
00242 
00243                 if(debug>4) fprintf(dFile,"%d %d %d %f\n",yyyy,mm,dd,tvar[ line ]);
00244                 if (feof(cfile)) {printf (" \n***Error\nExceeded number of records for %s meteorological time series\n",tfilename); exit (-1);}
00245             }
00246             tvar[ sLen ] = *TStep;
00247  
00248     if(debug>4) { fprintf(dFile,"\nDone Reading file %s\n",tfilename); fflush(dFile); }
00249     
00250     fflush(stdout);
00251     fclose(cfile);
00252     *Npt = sLen;
00253     return tvar;
00254 }

Here is the call graph for this function:

byte readMap char *  filename,
void *  data
 

Read data for spatial (map) input binary file.

Parameters:
filename data variable's name
data variable's array data
Returns:
byte size of data values

Definition at line 38 of file Serial.c.

References byte, dFile, gbl_size, ModelPath, ProjName, and read_header().

Referenced by read_map_file().

00039 {
00040   int gsize, nbytes; byte bsize;
00041   FILE* bFile;
00042   char binFileName[300];
00043   
00044   bsize = read_header(filename);
00045 
00046   sprintf(binFileName,"%s/%s/Data/Map_bin/%s",ModelPath,ProjName,filename);
00047 
00048   if((bFile = fopen(binFileName,"rb") ) == NULL ) { 
00049     fprintf(stderr,"Can't Open Mapfile: %s",binFileName); 
00050     exit(0); 
00051   }
00052   gsize = gbl_size[0] * gbl_size[1];
00053   nbytes = fread((char*)data, (int)bsize, gsize, bFile );
00054   if(debug) { 
00055     fprintf(dFile," %d of %d items Read for %s, size = %x bytes ",
00056             nbytes,gsize,filename,bsize); 
00057   }
00058   fclose(bFile);
00059   return bsize;
00060 }

Here is the call graph for this function:

void fatal const char *  msg  ) 
 

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

Definition at line 1468 of file Driver_Utilities.c.

References Exit().

Referenced by goto_index(), and print_point().

01469 {
01470   printf("%s",msg);
01471   fflush(stdout);
01472   Exit(9);
01473 }

Here is the call graph for this function:

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 1547 of file Driver_Utilities.c.

Referenced by send_point_lists2(), and track_time().

01548 {
01549   static int ret[4];
01550 
01551   long j = (long)jd;
01552   double tmp, frac = jd - j;
01553 
01554   if (frac >= 0.5) {
01555     frac = frac - 0.5;
01556     j++;
01557   } 
01558   else {
01559     frac = frac + 0.5;
01560   }
01561 
01562   ret[3] = (j + 1L) % 7L;
01563   j -= 1721119L;
01564   *y  = (4L * j - 1L) / 146097L;
01565   j = 4L * j - 1L - 146097L * *y;
01566   *d  = j / 4L;
01567   j = (4L * *d + 3L) / 1461L;
01568   *d = 4L * *d + 3L - 1461L * j;
01569   *d = (*d + 4L) / 4L;
01570   *m = (5L * *d - 3L) / 153L;
01571   *d = 5L * *d - 3 - 153L * *m;
01572   *d = (*d + 5L) / 5L;
01573   *y = 100L * *y + j;
01574   if (*m < 10)
01575     *m += 3;
01576   else {
01577     *m -= 9;
01578     *y += 1;
01579   }
01580   tmp = 3600.0 * (frac * 24.0);
01581   *h = (int) (tmp / 3600.0);
01582   tmp = tmp - *h * 3600.0;
01583 
01584   *mi = (int) (tmp / 60.0);
01585   *sec = tmp - *mi * 60.0;
01586 }

int skip_white FILE *  infile  ) 
 

Skip white space(s) in a file.

Parameters:
infile 
Returns:
success/failure

Definition at line 1717 of file Driver_Utilities.c.

Referenced by get_parmf(), and init_config_file().

01718 {
01719   int ch;
01720   
01721   while( isspace(ch=fgetc(infile)) ) {;}
01722   if(ch==EOF) return 0;
01723   ungetc(ch,infile);
01724   return 1;             
01725 }  

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 1731 of file Driver_Utilities.c.

01732 {
01733   int sLen, i, cnt=0;
01734   char Input_string[100], test;
01735   
01736   sLen = strlen(tstring);
01737   while( ( test = fgetc(infile) ) != EOF ) {
01738     for(i=0; i<(sLen-1); i++) 
01739         Input_string[i] = Input_string[i+1];
01740     Input_string[sLen-1] = test;
01741     Input_string[sLen] = '\0';
01742     if(++cnt >= sLen) {
01743       test =  strcmp(Input_string,tstring);
01744       if( test == 0 ) return 1;
01745     }
01746   }
01747   return(-1);
01748 }

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 1677 of file Driver_Utilities.c.

Referenced by get_Nth_parm(), and goto_index().

01678 {
01679   char test = '1', cchar = '#';
01680   int in_c=0;
01681 
01682   while( test != EOF ) {
01683     test = fgetc(infile);
01684     if(test == tchar && in_c==0 ) { return 1; }
01685     if(test == cchar ) in_c=1;
01686     if(test == '\n' )  in_c=0;
01687   }
01688   return(0);
01689 }

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 1500 of file Driver_Utilities.c.

01501 {
01502   long m = mon, d = day, y = year;
01503   long c, ya, j;
01504   double seconds = h * 3600.0 + mi * 60 + se;
01505 
01506   if (m > 2)
01507     m -= 3;
01508   else {
01509     m += 9;
01510     --y;
01511   }
01512   c = y / 100L;
01513   ya = y - (100L * c);
01514   j = (146097L * c) / 4L + (1461L * ya) / 4L + (153L * m + 2L) / 5L + d + 1721119L;
01515   if (seconds < 12 * 3600.0) {
01516     j--;
01517     seconds += 12.0 * 3600.0;
01518   } 
01519   else {
01520     seconds = seconds - 12.0 * 3600.0;
01521   }
01522   return (j + (seconds / 3600.0) / 24.0);
01523 }

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 1774 of file Driver_Utilities.c.

01775 {
01776   VOIDP rp;
01777 
01778   
01779   if(mem_size == 0) return(NULL);
01780   rp = (VOIDP)malloc( mem_size );
01781   total_memory += mem_size;
01782   fasync(stderr);
01783   if( rp == NULL ) {
01784     fprintf(stderr,"Sorry, out of memory(%d): %s\n",mem_size,var_name);
01785     Exit(0);
01786   }
01787   fmulti(stderr);
01788   return(rp);
01789 }


Variable Documentation

char gSectorChar = '@'
 

delimiter for ecological module (i.e., sector) ID number in reading habitat-specfic database file

Definition at line 43 of file serial.h.

char gHabChar = '^'
 

delimiter for habitat ID number in reading habitat-specfic database file

Definition at line 44 of file serial.h.

Referenced by get_hab_parm().

int habNumTot = 0
 

total number of habitat-types used in model

Definition at line 45 of file serial.h.

Referenced by alloc_hab_hist(), get_hab_parm(), and HabSwitch().

char fileDelimitChar = 'È'
 

Definition at line 47 of file serial.h.

char cTemp[200]
 

A temp char holder

Definition at line 48 of file serial.h.

Referenced by parse_packet(), and writeSeries().

char gTerm[4]
 

Four different characters to denote the format type of the model outlist configuration file

Definition at line 49 of file serial.h.

Referenced by init_config_file(), parse_packet(), and skip_cnfg_space().

char gCArg[kCArgDepth][kCArgWidth]
 

Output command arguments, parsed from the output configuration file

Definition at line 51 of file serial.h.

Referenced by parse_packet(), and readViewParms().

int cell_pts[MAX_TS_FILES]
 

The number of cell point locs per variable (1 var per file) for point time series output (clumsy)

Definition at line 53 of file serial.h.

Referenced by open_point_lists(), and send_point_lists2().

int numPtFiles = 0
 

The number of files (= variables) for point time series output (clumsy)

Definition at line 54 of file serial.h.

Referenced by open_point_lists(), and send_point_lists2().

FILE* dFile
 

File pointer to the low-level (ELM.debug) debug file

Definition at line 56 of file serial.h.

Referenced by get_hab_parm(), get_Nth_parm(), getCombineIndex(), local_setup(), read_header(), readMap(), readSeriesCol(), and write_header().

FILE* Driver_outfile
 

File pointer to (Driver0.out, or DriverX.out (for X'th simulation run)) debug file(s)

Definition at line 57 of file serial.h.

Referenced by open_debug_outFile(), WriteMsg(), and writeSeries().

FILE* * cnfgFile
 

File pointer to the output (Model.outList) configuration file

Definition at line 58 of file serial.h.

Referenced by readOutlist(), and skip_cnfg_space().

struct combo_table ctable[MAXCOMBOS]
 

Combination table for spatial array summaries (debug-related)

Definition at line 61 of file serial.h.

Referenced by Combine(), getCombineIndex(), and local_setup().

UINT max_combos_open
 

Max open map streams for spatial array summaries (debug-related)

Definition at line 62 of file serial.h.

Referenced by getCombineIndex(), and local_setup().

int gSLen[MAX_NHAB]
 

Definition at line 110 of file serial.h.

char* ProjName
 

Environment variables used in model

ModelPath environment variable, base pathname for executable and input data
ProjName environment variable, the name of the model project
DriverPath environment variable, base pathname for source code
OS_TYPE environment variable, the type of operating system being used (informational purpose only, not used in code)

Definition at line 36 of file driver_utilities.h.

char* ModelPath
 

Environment variables used in model

ModelPath environment variable, base pathname for executable and input data
ProjName environment variable, the name of the model project
DriverPath environment variable, base pathname for source code
OS_TYPE environment variable, the type of operating system being used (informational purpose only, not used in code)

Definition at line 36 of file driver_utilities.h.

char* OutputPath
 

base pathname for all model output (user input)

Definition at line 38 of file driver_utilities.h.

char modelName[20]
 

Model name/version (user input)

modelName Name given to model implementation (user input)
modelVers Version given to model implementation (e.g., v.2.1) (user input)

Definition at line 44 of file driver_utilities.h.

char modelVers[10]
 

Model name/version (user input)

modelName Name given to model implementation (user input)
modelVers Version given to model implementation (e.g., v.2.1) (user input)

Definition at line 44 of file driver_utilities.h.

char SimAlt[20]
 

simulation scenario/alterative name

Definition at line 35 of file generic_driver.h.

char SimModif[20]
 

simulation scenario/alterative modifier name/note

Definition at line 36 of file generic_driver.h.

int gbl_size[2]
 

row [0] and column [1] dimensions of model grid domain, serial implementation

Definition at line 39 of file generic_driver.h.

Referenced by read_header(), read_map_dims(), readMap(), setup_grid(), write_header(), and writeMap().

int seed
 

the seed value for (pseudo-) random number generator (unused)

Definition at line 27 of file generic_driver.h.

Referenced by get_parmf(), and local_setup().

int procnum
 

Data for parallel implementation, basically ignore

Lprocnum NA for serial implementation (=1)
procnum NA for serial implementation (also see nodenv struct)
nprocs NA for serial implementation (also see nodenv struct)
recpnum NA for serial implementation
tramType NA for serial implementation
tramNum NA for serial implementation
lcl_size used in serial code, but not really pertinent: in serial implementation, rows lcl_size[0]=s0 and columns lcl_size[1]=s1, dimensions of model grid domain local to one processor (for parallel implementation)
lcl_start used in serial code, but not really pertinent: in serial implementation, starting row lcl_start[0]=0 and starting column lcl_start[1]=0 in model grid domain local to one processor (for parallel implementation)

Definition at line 102 of file generic_driver.h.

Referenced by get_parmf(), local_setup(), main(), read_map_file(), setup_grid(), and setup_platform().

int Lprocnum
 

Data for parallel implementation, basically ignore

Lprocnum NA for serial implementation (=1)
procnum NA for serial implementation (also see nodenv struct)
nprocs NA for serial implementation (also see nodenv struct)
recpnum NA for serial implementation
tramType NA for serial implementation
tramNum NA for serial implementation
lcl_size used in serial code, but not really pertinent: in serial implementation, rows lcl_size[0]=s0 and columns lcl_size[1]=s1, dimensions of model grid domain local to one processor (for parallel implementation)
lcl_start used in serial code, but not really pertinent: in serial implementation, starting row lcl_start[0]=0 and starting column lcl_start[1]=0 in model grid domain local to one processor (for parallel implementation)

Definition at line 102 of file generic_driver.h.

Referenced by local_setup(), PTSL_ReadLists(), and read_map_dims().

int nprocs[2]
 

Data for parallel implementation, basically ignore

Lprocnum NA for serial implementation (=1)
procnum NA for serial implementation (also see nodenv struct)
nprocs NA for serial implementation (also see nodenv struct)
recpnum NA for serial implementation
tramType NA for serial implementation
tramNum NA for serial implementation
lcl_size used in serial code, but not really pertinent: in serial implementation, rows lcl_size[0]=s0 and columns lcl_size[1]=s1, dimensions of model grid domain local to one processor (for parallel implementation)
lcl_start used in serial code, but not really pertinent: in serial implementation, starting row lcl_start[0]=0 and starting column lcl_start[1]=0 in model grid domain local to one processor (for parallel implementation)

Definition at line 102 of file generic_driver.h.

Referenced by exgridsize(), local_setup(), and setup_platform().

int nproc
 

int recpnum[2]
 

Data for parallel implementation, basically ignore

Lprocnum NA for serial implementation (=1)
procnum NA for serial implementation (also see nodenv struct)
nprocs NA for serial implementation (also see nodenv struct)
recpnum NA for serial implementation
tramType NA for serial implementation
tramNum NA for serial implementation
lcl_size used in serial code, but not really pertinent: in serial implementation, rows lcl_size[0]=s0 and columns lcl_size[1]=s1, dimensions of model grid domain local to one processor (for parallel implementation)
lcl_start used in serial code, but not really pertinent: in serial implementation, starting row lcl_start[0]=0 and starting column lcl_start[1]=0 in model grid domain local to one processor (for parallel implementation)

Definition at line 102 of file generic_driver.h.

Referenced by exgridsize(), local_setup(), quick_look(), and setup_platform().

int tramType
 

Data for parallel implementation, basically ignore

Lprocnum NA for serial implementation (=1)
procnum NA for serial implementation (also see nodenv struct)
nprocs NA for serial implementation (also see nodenv struct)
recpnum NA for serial implementation
tramType NA for serial implementation
tramNum NA for serial implementation
lcl_size used in serial code, but not really pertinent: in serial implementation, rows lcl_size[0]=s0 and columns lcl_size[1]=s1, dimensions of model grid domain local to one processor (for parallel implementation)
lcl_start used in serial code, but not really pertinent: in serial implementation, starting row lcl_start[0]=0 and starting column lcl_start[1]=0 in model grid domain local to one processor (for parallel implementation)

Definition at line 102 of file generic_driver.h.

Referenced by local_setup().

int tramNum[2]
 

Data for parallel implementation, basically ignore

Lprocnum NA for serial implementation (=1)
procnum NA for serial implementation (also see nodenv struct)
nprocs NA for serial implementation (also see nodenv struct)
recpnum NA for serial implementation
tramType NA for serial implementation
tramNum NA for serial implementation
lcl_size used in serial code, but not really pertinent: in serial implementation, rows lcl_size[0]=s0 and columns lcl_size[1]=s1, dimensions of model grid domain local to one processor (for parallel implementation)
lcl_start used in serial code, but not really pertinent: in serial implementation, starting row lcl_start[0]=0 and starting column lcl_start[1]=0 in model grid domain local to one processor (for parallel implementation)

Definition at line 102 of file generic_driver.h.

Referenced by exgridcoord().

int PORnumday
 

number of days of simulation Period Of Record (incl. start day)

Definition at line 58 of file generic_driver.h.

double Jdate_init
 

julian day (since epochs ago) of the initialization of model

Definition at line 42 of file generic_driver.h.


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