00001
00025 #include "Extinction.h"
00026
00027
00028
00029
00030
00031
00032
00033 int IsExtinguishedROS(ChHashTable * proptbl, double mpsros);
00034
00035 int IsExtinguishedHOURS(ChHashTable * proptbl, unsigned char hours);
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054 int IsExtinguishedROS(ChHashTable * proptbl, double mpsros) {
00055
00056 static int ext_ros_enabled = -1;
00057 static double ext_mpsros = -1.0;
00058
00059 KeyVal * entry = NULL;
00060
00061
00062 if ( proptbl == NULL || ext_ros_enabled == 0 ) {
00063 return 0;
00064 }
00065
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
00074 ext_ros_enabled = 0;
00075 return 0;
00076 }
00077 ext_ros_enabled = 1;
00078 ext_mpsros = atof(entry->val);
00079 }
00080
00081 if ( mpsros < ext_mpsros ) {
00082 return 1;
00083 }
00084
00085 return 0;
00086 }
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105 int IsExtinguishedHOURS(ChHashTable * proptbl, unsigned char hours) {
00106
00107 static int ext_hrs_enabled = -1;
00108 static unsigned char ext_hrs = -1.0;
00109
00110 KeyVal * entry = NULL;
00111
00112
00113 if ( proptbl == NULL || ext_hrs_enabled == 0 ) {
00114 return 0;
00115 }
00116
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
00125 ext_hrs_enabled = 0;
00126 return 0;
00127 }
00128 ext_hrs_enabled = 1;
00129 ext_hrs = (unsigned char ) atoi(entry->val);
00130 }
00131
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
00141 static EnumExtinctionType ext_type = EnumExtinctionUnknown;
00142 static int smonth = 0;
00143 static int sday = 0;
00144 static int shour = 0;
00145
00146 KeyVal * entry = NULL;
00147 int domain_rows, domain_cols;
00148 int i,j;
00149
00150
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
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
00172 if ( (smonth != month) || (sday != day) || (shour != hour) ) {
00173
00174 domain_rows = BYTETWODARRAY_SIZE_ROW(cs->state);
00175 domain_cols = BYTETWODARRAY_SIZE_COL(cs->state);
00176
00177
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
00182 BYTETWODARRAY_SET_DATA(hrs_brn, i, j, (BYTETWODARRAY_GET_DATA(hrs_brn, i, j) + 1));
00183
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
00189 BYTETWODARRAY_SET_DATA(cs->state, i, j, EnumUnBurnableCellState);
00190 break;
00191 case EnumExtinctionReignite:
00192
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
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
00215 static EnumExtinctionType ext_type = EnumExtinctionUnknown;
00216
00217 KeyVal * entry = NULL;
00218
00219
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
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
00243 if ( IsExtinguishedROS(proptbl, mpsros) ) {
00244 BYTETWODARRAY_SET_DATA(hrs_brn, i, j, 0);
00245 switch(ext_type) {
00246 case EnumExtinctionConsume:
00247
00248 BYTETWODARRAY_SET_DATA(cs->state, i, j, EnumUnBurnableCellState);
00249 break;
00250 case EnumExtinctionReignite:
00251
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