Main Page   Compound List   File List   Compound Members   File Members  

FireYear.c

Go to the documentation of this file.
00001 
00025 #include "FireYear.h"
00026 
00027 FireYear * InitFireYearFuels(int year, GridData * fuels, ChHashTable * fmtble)  {
00028     FireYear * fy   = NULL;
00029     FuelModel * fm  = NULL;
00030     int cell_fm_num;
00031     int i, j;
00032     
00033     /* check args */
00034     if ( fuels == NULL )    {
00035         ERR_ERROR_CONTINUE("Unable to initialize FireYear, fuels not initialized. \n", ERR_EINVAL);
00036         return fy;
00037         }
00038     if ( year < 0 ) {
00039         ERR_ERROR_CONTINUE("Unable to intialize FireYear, year cannot be less than 0. \n", ERR_EINVAL);
00040         return fy;
00041         }
00042         
00043     /* allocate memory for structure */
00044     if ( (fy = (FireYear *) malloc(sizeof(FireYear))) == NULL ) {
00045         ERR_ERROR_CONTINUE("Unable to allocate memory for FireYear. \n", ERR_ENOMEM);   
00046         return fy;
00047         }
00048         
00049     /* initialize structure members */
00050     fy->year = year;
00051     fy->num_fires = FIRE_YEAR_ID_DEFAULT;
00052     fy->xllcorner = fuels->ghdr->xllcorner;
00053     fy->yllcorner = fuels->ghdr->yllcorner;
00054     fy->cellsize = fuels->ghdr->cellsize;
00055     
00056     /* allocate memory for fire ids */
00057     fy->id  = InitIntTwoDArraySizeIniValue(fuels->ghdr->nrows, fuels->ghdr->ncols, FIRE_YEAR_ID_DEFAULT);
00058     if ( fy->id == NULL )   {
00059         ERR_ERROR_CONTINUE("Unable to allocate memory for fire ID array underlying FireYear. \n", ERR_ENOMEM);  
00060         if ( fy != NULL )
00061             free(fy);
00062         fy = NULL;
00063         return fy;
00064         }
00065 
00066     /* initialize fire ids */
00067     for(i = 0; i < fuels->ghdr->nrows; i++) {
00068         for(j = 0; j < fuels->ghdr->ncols; j++) {
00069             /* retrieve fuel model attribute data */
00070             GRID_DATA_GET_DATA(fuels, i, j, cell_fm_num);
00071             if ( ChHashTableRetrieve(fmtble, &cell_fm_num, (void *)&fm) )   {
00072                 ERR_ERROR_CONTINUE("Unable to retrieve fuel model from fuels GridData. \n", ERR_EBADFUNC);
00073                 continue;
00074                 }
00075             /* set fire id to unburnable */         
00076             if ( fm->type == EnumRoth && fm->rfm->brntype == EnumRothUnBurnable )   {
00077                 INTTWODARRAY_SET_DATA(fy->id, i, j, FIRE_YEAR_ID_UNBURNABLE);
00078                 }
00079             else if ( fm->type == EnumPhys && fm->pfm->brntype == EnumPhysUnBurnable )  {
00080                 INTTWODARRAY_SET_DATA(fy->id, i, j, FIRE_YEAR_ID_UNBURNABLE);
00081                 }
00082             }
00083         }
00084                 
00085     return fy;
00086     }   
00087 
00088 int FireYearGetCellIDRowCol(FireYear * fy, int i, int j, int * id)  {
00089     /* check args */
00090     if ( fy == NULL || fy->id == NULL ) {
00091         ERR_ERROR("Unable to get FireYear ID at cell, ID array not initialized. \n", ERR_EINVAL);
00092         }
00093         
00094     *id = INTTWODARRAY_GET_DATA(fy->id, i, j);
00095         
00096     return ERR_SUCCESS;
00097     }
00098 
00099 int FireYearGetCellIDRealWorld(FireYear * fy, double rwx, double rwy, int * id) {
00100     int i,j;
00101     
00102     /* check args */
00103     if ( fy == NULL || fy->id == NULL ) {
00104         ERR_ERROR("Unable to get FireYear ID at cell, ID array not initialized. \n", ERR_EINVAL);
00105         }
00106         
00107     /* transform real world coordinates to cell indecies */
00108     if ( CoordTransRealWorldToRaster(rwx, rwy, fy->cellsize, fy->cellsize, 
00109             COORD_TRANS_XLLCORNER_TO_XULCNTR(fy->xllcorner, fy->cellsize), 
00110             COORD_TRANS_YLLCORNER_TO_YULCNTR(fy->yllcorner, fy->cellsize, INTTWODARRAY_SIZE_ROW(fy->id)), &i, &j) ) {
00111         ERR_ERROR("Unable to get FireYear ID at cell, real world coordinates out of range. \n", ERR_ERANGE);
00112         }
00113         
00114     *id = INTTWODARRAY_GET_DATA(fy->id, i, j);
00115         
00116     return ERR_SUCCESS;
00117     }
00118     
00119 int FireYearIsCellBurnedRowCol(FireYear * fy, int i, int j) {
00120     int id;
00121     
00122     /* check args */
00123     if ( fy == NULL || fy->id == NULL ) {
00124         ERR_ERROR_CONTINUE("Unable to determine if cell burned, ID array not initialized. \n", ERR_EINVAL);
00125         return 0;
00126         }
00127         
00128     id = INTTWODARRAY_GET_DATA(fy->id, i, j);
00129     
00130     if ( id == FIRE_YEAR_ID_UNBURNABLE || id == FIRE_YEAR_ID_DEFAULT )  {
00131         return 0;
00132         }
00133         
00134     return 1;
00135     }
00136 
00137 int FireYearIsCellBurnedRealWorld(FireYear * fy, double rwx, double rwy)    {
00138     int id, i, j;
00139     
00140     /* check args */
00141     if ( fy == NULL || fy->id == NULL ) {
00142         ERR_ERROR_CONTINUE("Unable to determine if cell burned, ID array not initialized. \n", ERR_EINVAL);
00143         return 0;
00144         }
00145 
00146     /* transform real world coordinates to cell indecies */
00147     if ( CoordTransRealWorldToRaster(rwx, rwy, fy->cellsize, fy->cellsize, 
00148             COORD_TRANS_XLLCORNER_TO_XULCNTR(fy->xllcorner, fy->cellsize), 
00149             COORD_TRANS_YLLCORNER_TO_YULCNTR(fy->yllcorner, fy->cellsize, INTTWODARRAY_SIZE_ROW(fy->id)), &i, &j) ) {
00150         ERR_ERROR_CONTINUE("Unable to get FireYear ID at cell, real world coordinates out of range. \n", ERR_ERANGE);
00151         return 0;
00152         }       
00153     
00154     id = INTTWODARRAY_GET_DATA(fy->id, i, j);
00155     
00156     if ( id == FIRE_YEAR_ID_UNBURNABLE || id == FIRE_YEAR_ID_DEFAULT )  {
00157         return 0;
00158         }
00159         
00160     return 1;
00161     }
00162 
00163 void FireYearSetCellNewFireIDRowCol(FireYear * fy, int i, int j)    {
00164     /* check args */
00165     if ( fy == NULL || fy->id == NULL ) {
00166         ERR_ERROR_CONTINUE("Unable to set cell fire ID, ID array not initialized. \n", ERR_EINVAL);
00167         return;
00168         }
00169         
00170     /* if cell is burnable, increment num_fires and assign cell new fire id */  
00171     if ( INTTWODARRAY_GET_DATA(fy->id, i, j) != FIRE_YEAR_ID_UNBURNABLE )   {
00172         fy->num_fires += 1;
00173         INTTWODARRAY_SET_DATA(fy->id, i, j, fy->num_fires);
00174         }
00175         
00176     return;
00177     }
00178 
00179 void FireYearSetCellNewFireIDRealWorld(FireYear * fy, double rwx, double rwy)   {
00180     int i, j;
00181     
00182     /* check args */
00183     if ( fy == NULL || fy->id == NULL ) {
00184         ERR_ERROR_CONTINUE("Unable to set cell fire ID, ID array not initialized. \n", ERR_EINVAL);
00185         return;
00186         }
00187 
00188     /* transform real world coordinates to cell indecies */
00189     if ( CoordTransRealWorldToRaster(rwx, rwy, fy->cellsize, fy->cellsize, 
00190             COORD_TRANS_XLLCORNER_TO_XULCNTR(fy->xllcorner, fy->cellsize), 
00191             COORD_TRANS_YLLCORNER_TO_YULCNTR(fy->yllcorner, fy->cellsize, INTTWODARRAY_SIZE_ROW(fy->id)), &i, &j) ) {
00192         ERR_ERROR_CONTINUE("Unable to set cell fire ID, real world coordinates out of range. \n", ERR_ERANGE);
00193         return;
00194         }       
00195 
00196     /* if cell is burnable, increment num_fires and assign cell new fire id */  
00197     if ( INTTWODARRAY_GET_DATA(fy->id, i, j) != FIRE_YEAR_ID_UNBURNABLE )   {
00198         fy->num_fires += 1;
00199         INTTWODARRAY_SET_DATA(fy->id, i, j, fy->num_fires);
00200         }   
00201 
00202     return;
00203     }
00204 
00205 void FreeFireYear(FireYear * fy)    {
00206     if ( fy != NULL )   {
00207         if ( fy->id != NULL )   {
00208             FreeIntTwoDArray(fy->id);
00209             }
00210         free(fy);
00211         }       
00212     fy = NULL;
00213     return;
00214     }
00215     
00216 /* end of FireYear.c */

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