Main Page   Compound List   File List   Compound Members   File Members  

CellState.c

Go to the documentation of this file.
00001 
00025 #include "CellState.h"
00026 
00027 CellState * InitCellStateFuels(GridData * fuels, ChHashTable * fmtble)  {
00028     CellState * cs  = 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 CellState, fuels not initialized. \n", ERR_EINVAL);
00036         return cs;
00037         }
00038         
00039     /* allocate memory for structure */
00040     if ( (cs = (CellState *) malloc(sizeof(CellState))) == NULL )   {
00041         ERR_ERROR_CONTINUE("Unable to allocate memory for CellState. \n", ERR_ENOMEM);  
00042         return cs;
00043         }
00044         
00045     /* initialize structure members */
00046     cs->xllcorner = fuels->ghdr->xllcorner;
00047     cs->yllcorner = fuels->ghdr->yllcorner;
00048     cs->cellsize = fuels->ghdr->cellsize;
00049     
00050     /* allocate memory for cell state */
00051     cs->state = InitByteTwoDArraySizeIniValue(fuels->ghdr->nrows, fuels->ghdr->ncols, EnumNoFireCellState);
00052     if ( cs->state == NULL )    {
00053         ERR_ERROR_CONTINUE("Unable to allocate memory for state array underlying CellState. \n", ERR_ENOMEM);   
00054         if ( cs != NULL )
00055             free(cs);
00056         cs = NULL;
00057         return cs;
00058         }
00059 
00060     /* initialize state */
00061     for(i = 0; i < fuels->ghdr->nrows; i++) {
00062         for(j = 0; j < fuels->ghdr->ncols; j++) {
00063             /* retrieve fuel model attribute data */
00064             GRID_DATA_GET_DATA(fuels, i, j, cell_fm_num);
00065             if ( ChHashTableRetrieve(fmtble, &cell_fm_num, (void *)&fm) )   {
00066                 ERR_ERROR_CONTINUE("Unable to retrieve fuel model from fuels GridData. \n", ERR_EBADFUNC);
00067                 continue;
00068                 }
00069             /* set cell state to unburnable */      
00070             if ( fm->type == EnumRoth && fm->rfm->brntype == EnumRothUnBurnable )   {
00071                 BYTETWODARRAY_SET_DATA(cs->state, i, j, EnumUnBurnableCellState);
00072                 }
00073             else if ( fm->type == EnumPhys && fm->pfm->brntype == EnumPhysUnBurnable )  {
00074                 BYTETWODARRAY_SET_DATA(cs->state, i, j, EnumUnBurnableCellState);
00075                 }
00076             }
00077         }
00078                 
00079     return cs;
00080     }
00081 
00082 int CellStateSetCellStateRowCol(CellState * cs, int i, int j, EnumCellState state)  {
00083     /* check args */
00084     if ( cs == NULL )   {
00085         ERR_ERROR("Unable to set cell state, ByteTwoDArray not initialized. \n", ERR_EINVAL);
00086         }
00087 
00088     /* set the cell state */
00089     if ( BYTETWODARRAY_GET_DATA(cs->state, i, j) != EnumUnBurnableCellState )   {
00090         BYTETWODARRAY_SET_DATA(cs->state, i, j, state);
00091         }       
00092             
00093     return ERR_SUCCESS;     
00094     }
00095         
00096 int CellStateSetCellStateRealWorld(CellState * cs, double rwx, double rwy, EnumCellState state) {
00097     int i,j;
00098     
00099     /* check args */
00100     if ( cs == NULL )   {
00101         ERR_ERROR("Unable to set cell state, ByteTwoDArray not initialized. \n", ERR_EINVAL);
00102         }
00103         
00104     /* retrieve array row and column indecies from real world coordinates */
00105     if ( CoordTransRealWorldToRaster(rwx, rwy, cs->cellsize, cs->cellsize,
00106             COORD_TRANS_XLLCORNER_TO_XULCNTR(cs->xllcorner, cs->cellsize), 
00107             COORD_TRANS_YLLCORNER_TO_YULCNTR(cs->yllcorner, cs->cellsize, BYTETWODARRAY_SIZE_ROW(cs->state)), &i, &j) )     {
00108         ERR_ERROR("Unable to set cell state, real world coordinates not inside domain. \n", ERR_ERANGE);
00109         }
00110         
00111     /* set the cell state */
00112     if ( BYTETWODARRAY_GET_DATA(cs->state, i, j) != EnumUnBurnableCellState )   {
00113         BYTETWODARRAY_SET_DATA(cs->state, i, j, state);
00114         }       
00115             
00116     return ERR_SUCCESS;
00117     }
00118 
00119 void FreeCellState(CellState * cs)  {
00120     if ( cs != NULL )   {
00121         if ( cs->state != NULL )    {
00122             FreeByteTwoDArray(cs->state);
00123             }
00124         free(cs);
00125         }       
00126     cs = NULL;
00127     return;
00128     }
00129     
00130 /* end of CellState.c */

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