Main Page   Compound List   File List   Compound Members   File Members  

DeadFuelMoist.c

Go to the documentation of this file.
00001 
00025 #include "DeadFuelMoist.h"
00026 
00027 int GetDeadFuelMoistFIXEDFromProps(ChHashTable * proptbl, int month, int day, int hour, 
00028                                             unsigned int row, unsigned int col,
00029                                             double * d1hfm, double * d10hfm, double * d100hfm)      {
00030     /* static variables used to store state across function calls */
00031     static int smonth               = 0;
00032     static int sday                 = 0;
00033     static int shour                = 0;
00034     static double sd1hfm            = 0.0;
00035     static double sd10hfm           = 0.0;
00036     static double sd100hfm          = 0.0;
00037     static DblTwoDArray * sd10h_tbl = NULL;
00038     /* stack variables */
00039     KeyVal * entry                  = NULL;             /* key/val instances from table */
00040     FILE * fstream                  = NULL;             /* file stream */
00041     int rec;
00042 
00043     if ( (smonth != month) || (sday != day) || (shour != hour) )    {
00044         /* new dead fuel moistures table needed */
00045         if (sd10h_tbl == NULL ) {
00046             /* initialize returned vars in case table not created */
00047             *d1hfm = sd1hfm;
00048             *d10hfm = sd10hfm;
00049             *d100hfm = sd100hfm;
00050             /* table of fixed values only needs to be initialized once */
00051             if ( ChHashTableRetrieve(proptbl, GetFireProp(PROP_DFMFFILE), (void *)&entry) ) {
00052                 ERR_ERROR("Unable to retrieve DEAD_FUEL_MOIST_FIXED_FILE property. \n", ERR_EINVAL);
00053                 }
00054             /* open fixed dead fuel moisture file */
00055             if ( (fstream = fopen((char *) entry->val, "r")) == NULL )  {       
00056                 ERR_ERROR("Unable to open file containing fixed Dead Fuel Moisture. \n", ERR_EIOFAIL);
00057                 }
00058             /* create the table of values */
00059             if ( (sd10h_tbl = GetDblTwoDArrayTableFStreamIO(fstream, 
00060                     DEAD_FUEL_MOIST_10H_SEP_CHARS, DEAD_FUEL_MOIST_10H_COMMENT_CHAR)) == NULL ) {
00061                 fclose(fstream);
00062                 ERR_ERROR("Unable to initialize fixed Dead Fuel Moisture table. \n", ERR_EFAILED);
00063                 }
00064             fclose(fstream);
00065             }
00066         /* find record in table */
00067         row = DBLTWODARRAY_SIZE_ROW(sd10h_tbl);
00068         for(rec = 0; rec < row; rec++)  {
00069             /* find matching month and day */
00070             if ( DBLTWODARRAY_GET_DATA(sd10h_tbl, rec, DEAD_FUEL_MOIST_MO_10H_TBL_INDEX) == month 
00071                  && DBLTWODARRAY_GET_DATA(sd10h_tbl, rec, DEAD_FUEL_MOIST_DY_10H_TBL_INDEX) == day )    {
00072                 /* retrieve dfm on that month and day */
00073                 col = DEAD_FUEL_MOIST_HR_TO_10H_TBL_INDEX(hour);
00074                 sd10hfm = DBLTWODARRAY_GET_DATA(sd10h_tbl, rec, col) / 100;
00075                 if ( !UNITS_FP_GT_ZERO(sd10hfm) )
00076                     sd10hfm = 0.01;
00077                 sd1hfm = sd10hfm - 0.02;
00078                 if ( !UNITS_FP_GT_ZERO(sd1hfm) )
00079                     sd1hfm = 0.01;
00080                 sd100hfm = sd10hfm + 0.02;
00081                 if ( !UNITS_FP_GT_ZERO(sd100hfm) )
00082                     sd100hfm = 0.01;
00083                 break;
00084                 }
00085             }
00086         /* set {month, day, hour} for future calls */
00087         smonth = month;
00088         sday = day;
00089         shour = hour;
00090         }
00091 
00092     *d1hfm = sd1hfm;
00093     *d10hfm = sd10hfm;
00094     *d100hfm = sd100hfm;
00095                     
00096     return ERR_SUCCESS;
00097     }
00098 
00099                                                                                     
00100 int GetDeadFuelMoistRANDHFromProps(ChHashTable * proptbl, int month, int day, int hour, 
00101                                             unsigned int row, unsigned int col,
00102                                             double * d1hfm, double * d10hfm, double * d100hfm)      {
00103     /* static variables used to store state across function calls */
00104     static int smonth               = 0;
00105     static int sday                 = 0;
00106     static int shour                = 0;
00107     static int srec                 = 0;
00108     static double sd1hfm            = 0.0;
00109     static double sd10hfm           = 0.0;
00110     static double sd100hfm          = 0.0;
00111     static DblTwoDArray * sd10h_tbl = NULL;
00112     /* stack variables */
00113     KeyVal * entry                  = NULL;             /* key/val instances from table */
00114     FILE * fstream                  = NULL;             /* file stream */
00115 
00116     if ( (smonth != month) || (sday != day) || (shour != hour) )    {
00117         /* new dead fuel moistures table needed */
00118         if (sd10h_tbl == NULL ) {
00119             /* initialize returned vars in case table not created */
00120             *d1hfm = sd1hfm;
00121             *d10hfm = sd10hfm;
00122             *d100hfm = sd100hfm;        
00123             /* table of fixed values only needs to be initialized once */
00124             if ( ChHashTableRetrieve(proptbl, GetFireProp(PROP_DFMHFILE), (void *)&entry) ) {
00125                 ERR_ERROR("Unable to retrieve DEAD_FUEL_MOIST_HISTORICAL_FILE property. \n", ERR_EINVAL);
00126                 }
00127             /* open fixed azimuth file */
00128             if ( (fstream = fopen((char *) entry->val, "r")) == NULL )  {
00129                 ERR_ERROR("Unable to open file containing historical Dead Fuel Moisture. \n", ERR_EIOFAIL);
00130                 }
00131             /* create the table of values */
00132             if ( (sd10h_tbl = GetDblTwoDArrayTableFStreamIO(fstream, 
00133                     DEAD_FUEL_MOIST_10H_SEP_CHARS, DEAD_FUEL_MOIST_10H_COMMENT_CHAR)) == NULL ) {
00134                 fclose(fstream);
00135                 ERR_ERROR("Unable to initialize historical Dead Fuel Moisture table. \n", ERR_EFAILED);
00136                 }
00137             fclose(fstream);                    
00138             }
00139         /* new random record number (day) from table needed */
00140         if ( (smonth != month) || (sday != day) )   {
00141             /* retrieve new record at random from table within range 0 to num_recs */
00142             srec = randi(0) % DBLTWODARRAY_SIZE_ROW(sd10h_tbl);
00143             }
00144         /* retrieve dead fuel moisture at hour from current day, otherwise use last value */
00145         col = DEAD_FUEL_MOIST_HR_TO_10H_TBL_INDEX(hour);
00146         if ( (row = DBLTWODARRAY_GET_DATA(sd10h_tbl, srec, col)) != DEAD_FUEL_MOIST_10H_NO_DATA_VALUE ) {
00147             sd10hfm = row / 100;
00148             if ( !UNITS_FP_GT_ZERO(sd10hfm) )
00149                 sd10hfm = 0.01;
00150             sd1hfm = sd10hfm - 0.02;
00151             if ( !UNITS_FP_GT_ZERO(sd1hfm) )
00152                 sd1hfm = 0.01;
00153             sd100hfm = sd10hfm + 0.02;
00154             if ( !UNITS_FP_GT_ZERO(sd100hfm) )
00155                 sd100hfm = 0.01;
00156             }
00157         
00158         /* set {month, day, hour} for future calls */
00159         smonth = month;
00160         sday = day;
00161         shour = hour;
00162         }
00163         
00164     *d1hfm = sd1hfm;
00165     *d10hfm = sd10hfm;
00166     *d100hfm = sd100hfm;
00167                     
00168     return ERR_SUCCESS; 
00169     }
00170 
00171 int GetDeadFuelMoistSPATIALFromProps(ChHashTable * proptbl, int month, int day, int hour, 
00172                                             unsigned int row, unsigned int col,
00173                                             double * d1hfm, double * d10hfm, double * d100hfm)      {
00174     /* WA: stop warnings from unused vars */    
00175     month = day = hour = row = col = 0;
00176     *d1hfm = *d10hfm = *d100hfm = 0.0;  
00177     if ( proptbl == NULL )  
00178         ERR_ERROR("Simulation properties table not initialized. \n", ERR_EINVAL);
00179     ERR_ERROR("SPATIAL option for DEAD_FUEL_MOIST_TYPE not yet implemented. \n", ERR_EUNIMPL);
00180     }
00181 
00182 /* end of DeadFuelMoist.c */

Generated at Fri Jun 22 00:46:50 2001 for HFire by doxygen1.2.3 written by Dimitri van Heesch, © 1997-2000