Main Page   Compound List   File List   Compound Members   File Members  

Extinction.c

Go to the documentation of this file.
00001 
00025 #include "Extinction.h"
00026 
00027 /*
00028  *********************************************************
00029  * NON PUBLIC FUNCTIONS
00030  *********************************************************
00031  */
00032 
00033 int IsExtinguishedROS(ChHashTable * proptbl, double mpsros);
00034 
00035 int IsExtinguishedHOURS(ChHashTable * proptbl, unsigned char hours);
00036 
00037 /*
00038  * Visibility:
00039  * global
00040  *
00041  * Description:
00042  * Tests whether the rate of spread supplied as an argument is less than the extinction threshold.
00043  * This method returns a 1 if the mpsros is less than than the simulation property 
00044  * FIRE_EXTINCTION_ROS_MPS.  If the property FIRE_EXTINCTION_ROS_MPS is NULL or the mpsros is 
00045  * greater or equal, then this method returns 0.
00046  *
00047  * Arguments:
00048  * proptbl- HashTable of simulation properties
00049  * mpsros- rate of spread, in meters per second, being tested
00050  *
00051  * Returns:
00052  * Returns 1 (true) if mpsros less than threshold, or 0 (false) otherwise.
00053  */ 
00054 int IsExtinguishedROS(ChHashTable * proptbl, double mpsros)     {
00055     /* static variables used to store state across function calls */
00056     static int ext_ros_enabled  = -1;
00057     static double ext_mpsros    = -1.0;
00058     /* stack variables */
00059     KeyVal * entry  = NULL;                                 /* key/val entries from table */
00060     
00061     /* check args */
00062     if ( proptbl == NULL || ext_ros_enabled == 0 )  {
00063         return 0;
00064         }
00065     /* determine if extinction threshold enabled, only done once */
00066     if ( ext_ros_enabled == -1 )    {
00067         if ( ChHashTableRetrieve(proptbl, GetFireProp(PROP_FEXROS), (void *)&entry) )   {
00068             ERR_ERROR_CONTINUE("Unable to retrieve FIRE_EXTINCTION_ROS_MPS property. \n", ERR_EINVAL);
00069             ext_ros_enabled = 0;
00070             return 0;
00071             }
00072         if ( strcmp(entry->val, GetFireVal(VAL_NULL)) == 0) {
00073             /* disable extinction via this mechanism */
00074             ext_ros_enabled = 0;
00075             return 0;
00076             }
00077         ext_ros_enabled = 1;
00078         ext_mpsros = atof(entry->val);
00079         }
00080     /* test if extinction occurs */
00081     if ( mpsros < ext_mpsros )  {
00082         return 1;
00083         }
00084         
00085     return 0;
00086     }
00087 
00088 /*
00089  * Visibility:
00090  * global
00091  *
00092  * Description:
00093  * Tests whether the hours supplied as an argument are greater than or equal to the extinction
00094  * threshold. This method returns a 1 if the hours exceed or equal to simulation property
00095  * FIRE_EXTINCTION_HOURS.  If the property FIRE_EXTINCTION_HOURS is NULL or the hours are less
00096  * than the threshold, then this method returns 0.
00097  *
00098  * Arguments:
00099  * proptbl- HashTable of simulation properties
00100  * hours- hours being tested
00101  *
00102  * Returns:
00103  * Returns 1 (true) if hours greater than or equal to threshold, or 0 (false) otherwise.
00104  */ 
00105 int IsExtinguishedHOURS(ChHashTable * proptbl, unsigned char hours) {
00106     /* static variables used to store state across function calls */
00107     static int ext_hrs_enabled      = -1;
00108     static unsigned char ext_hrs    = -1.0;
00109     /* stack variables */
00110     KeyVal * entry  = NULL;                                 /* key/val entries from table */
00111     
00112     /* check args */
00113     if ( proptbl == NULL || ext_hrs_enabled == 0 )  {
00114         return 0;
00115         }
00116     /* determine if extinction threshold enabled, only done once */
00117     if ( ext_hrs_enabled == -1 )    {
00118         if ( ChHashTableRetrieve(proptbl, GetFireProp(PROP_FEXHR), (void *)&entry) )    {
00119             ERR_ERROR_CONTINUE("Unable to retrieve FIRE_EXTINCTION_HOURS property. \n", ERR_EINVAL);
00120             ext_hrs_enabled = 0;
00121             return 0;
00122             }
00123         if ( strcmp(entry->val, GetFireVal(VAL_NULL)) == 0) {
00124             /* disable extinction via this mechanism */
00125             ext_hrs_enabled = 0;
00126             return 0;
00127             }
00128         ext_hrs_enabled = 1;
00129         ext_hrs = (unsigned char ) atoi(entry->val);
00130         }
00131     /* test if extinction occurs */
00132     if ( hours >= ext_hrs ) {
00133         return 1;
00134         }
00135 
00136     return 0;   
00137     }
00138 
00139 int UpdateExtinctionHOURS(ChHashTable * proptbl, int month, int day, int hour, CellState * cs, ByteTwoDArray * hrs_brn){
00140     /* static variables used to store state across function calls */
00141     static EnumExtinctionType ext_type  = EnumExtinctionUnknown;
00142     static int smonth                   = 0;
00143     static int sday                     = 0;
00144     static int shour                    = 0;
00145     /* stack variables */
00146     KeyVal * entry  = NULL;                                 /* key/val entries from table */
00147     int domain_rows, domain_cols;
00148     int i,j;
00149     
00150     /* check args */
00151     if ( proptbl == NULL || cs == NULL || hrs_brn == NULL )     {
00152         ERR_ERROR("Unable to update extinction using hours criteria. \n", ERR_EINVAL);
00153         }
00154 
00155     /* set extinction type, only done once */
00156     if ( ext_type == EnumExtinctionUnknown )    {
00157         if ( ChHashTableRetrieve(proptbl, GetFireProp(PROP_FEXTYP), (void *)&entry) )   {
00158             ERR_ERROR("Unable to retrieve FIRE_EXTINCTION_TYPE property. \n", ERR_EINVAL);
00159             }
00160         if ( strcmp(entry->val, GetFireVal(VAL_CONS)) == 0) {
00161             ext_type = EnumExtinctionConsume;
00162             }
00163         else if ( strcmp(entry->val, GetFireVal(VAL_REIG)) == 0)    {
00164             ext_type = EnumExtinctionReignite;
00165             }
00166         else    {
00167             ERR_ERROR("Unrecognized FIRE_EXTINCTION_TYPE property. \n", ERR_EINVAL);
00168             }
00169         }
00170 
00171     /* determine if at least one hour has passed since last call to this function */
00172     if ( (smonth != month) || (sday != day) || (shour != hour) )    {
00173         /* get domain dimensions */
00174         domain_rows = BYTETWODARRAY_SIZE_ROW(cs->state);
00175         domain_cols = BYTETWODARRAY_SIZE_COL(cs->state);
00176     
00177         /* increment extinction clock */
00178         for(i = 0; i < domain_rows; i++)    {
00179             for(j = 0; j < domain_cols; j++)    {
00180                 if ( BYTETWODARRAY_GET_DATA(cs->state, i, j) == EnumHasFireCellState )  { 
00181                     /* increment the hrs_brned */
00182                     BYTETWODARRAY_SET_DATA(hrs_brn, i, j, (BYTETWODARRAY_GET_DATA(hrs_brn, i, j) + 1));
00183                     /* extinguish the cell if necessary */
00184                     if ( IsExtinguishedHOURS(proptbl, BYTETWODARRAY_GET_DATA(hrs_brn, i, j)) )  {
00185                         BYTETWODARRAY_SET_DATA(hrs_brn, i, j, 0);
00186                         switch(ext_type)    {
00187                             case EnumExtinctionConsume:
00188                                 /* cell cannot burn again this year */
00189                                 BYTETWODARRAY_SET_DATA(cs->state, i, j, EnumUnBurnableCellState);
00190                                 break;
00191                             case EnumExtinctionReignite:
00192                                 /* cell can burn again this year */
00193                                 BYTETWODARRAY_SET_DATA(cs->state, i, j, EnumNoFireCellState);
00194                                 break;
00195                             default:
00196                                 ERR_ERROR("Unable to determine FIRE_EXTINCTION_TYPE property. \n", ERR_ESANITY);
00197                                 break;
00198                             }
00199                         }
00200                     }
00201                 }
00202             }
00203     
00204         /* set {month, day, hour} for future calls */
00205         smonth = month;
00206         sday = day;
00207         shour = hour;
00208         }
00209         
00210     return ERR_SUCCESS;             
00211     }
00212 
00213 int UpdateExtinctionROS(ChHashTable * proptbl, int i, int j, double mpsros, CellState * cs, ByteTwoDArray * hrs_brn){
00214     /* static variables used to store state across function calls */
00215     static EnumExtinctionType ext_type  = EnumExtinctionUnknown;
00216     /* stack variables */
00217     KeyVal * entry  = NULL;                                 /* key/val entries from table */
00218     
00219     /* check args */
00220     if ( proptbl == NULL || cs == NULL || hrs_brn == NULL )     {
00221         ERR_ERROR_CONTINUE("Unable to update extinction using hours criteria. \n", ERR_EINVAL);
00222         return 0;
00223         }
00224 
00225     /* set extinction type, only done once */
00226     if ( ext_type == EnumExtinctionUnknown )    {
00227         if ( ChHashTableRetrieve(proptbl, GetFireProp(PROP_FEXTYP), (void *)&entry) )   {
00228             ERR_ERROR_CONTINUE("Unable to retrieve FIRE_EXTINCTION_TYPE property. \n", ERR_EINVAL);
00229             }
00230         if ( strcmp(entry->val, GetFireVal(VAL_CONS)) == 0) {
00231             ext_type = EnumExtinctionConsume;
00232             }
00233         else if ( strcmp(entry->val, GetFireVal(VAL_REIG)) == 0)    {
00234             ext_type = EnumExtinctionReignite;
00235             }
00236         else    {
00237             ERR_ERROR_CONTINUE("Unrecognized FIRE_EXTINCTION_TYPE property. \n", ERR_EINVAL);
00238             return 0;
00239             }
00240         }
00241 
00242     /* extinguish the cell */
00243     if ( IsExtinguishedROS(proptbl, mpsros) )   {
00244         BYTETWODARRAY_SET_DATA(hrs_brn, i, j, 0);
00245         switch(ext_type)    {
00246             case EnumExtinctionConsume:
00247                 /* cell cannot burn again this year */
00248                 BYTETWODARRAY_SET_DATA(cs->state, i, j, EnumUnBurnableCellState);
00249                 break;
00250             case EnumExtinctionReignite:
00251                 /* cell can burn again this year */
00252                 BYTETWODARRAY_SET_DATA(cs->state, i, j, EnumNoFireCellState);
00253                 break;
00254             default:
00255                 ERR_ERROR_CONTINUE("Unable to determine FIRE_EXTINCTION_TYPE property. \n", ERR_ESANITY);
00256                 break;
00257             }
00258         return 1;
00259         }
00260 
00261     return 0;                           
00262     }
00263      
00264 /* end of Extinction.c */

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