00001
00025 #include "FireGridData.h"
00026
00027 GridData * GetGridDataFromPropsFireGridData(ChHashTable * proptbl, char * data_keyword) {
00028 GridData * grid = NULL;
00029 EnumGridType grid_type = EnumFltGrid;
00030 int is_ascii = -1;
00031 char * main_fname = NULL;
00032 char * hdr_fname = NULL;
00033 KeyVal * entry = NULL;
00034 char key[FIRE_PROP_MAX_SIZE_KEYWORD];
00035
00036 if ( proptbl == NULL || data_keyword == NULL ) {
00037 ERR_ERROR_CONTINUE("Unable to initialize GridData with table. \n", ERR_EINVAL);
00038 return grid;
00039 }
00040
00041
00042 key[0] = '\0';
00043 strcpy(key, data_keyword);
00044 strcat(key, FIRE_GRIDDATA_RASTER_FORMAT);
00045 if ( ChHashTableRetrieve(proptbl, key, (void *)&entry) ) {
00046 ERR_ERROR_CONTINUE("Unable to retrieve RASTER_FORMAT property for GridData. \n", ERR_EINVAL);
00047 return grid;
00048 }
00049 if ( strcmp(entry->val, GetFireVal(VAL_ASCII)) == 0 ) {
00050 is_ascii = 1;
00051 }
00052 else if ( strcmp(entry->val, GetFireVal(VAL_BINARY)) == 0 ) {
00053 is_ascii = 0;
00054 }
00055 else {
00056 ERR_ERROR_CONTINUE("Unrecognized RASTER_FORMAT property for GridData. \n", ERR_EINVAL);
00057 return grid;
00058 }
00059
00060
00061 key[0] = '\0';
00062 strcpy(key, data_keyword);
00063 strcat(key, FIRE_GRIDDATA_MAIN_FILE);
00064 if ( ChHashTableRetrieve(proptbl, key, (void *)&entry) || strcmp(entry->val, GetFireVal(VAL_NULL)) == 0 ) {
00065 ERR_ERROR_CONTINUE("Unable to retrieve MAIN_FILE property for GridData. \n", ERR_EINVAL);
00066 return grid;
00067 }
00068 main_fname = (char *) entry->val;
00069
00070
00071 if ( is_ascii == 0 ) {
00072
00073 key[0] = '\0';
00074 strcpy(key, data_keyword);
00075 strcat(key, FIRE_GRIDDATA_HEADER_FILE);
00076 if ( ChHashTableRetrieve(proptbl, key, (void *)&entry) || strcmp(entry->val, GetFireVal(VAL_NULL)) == 0 ) {
00077 ERR_ERROR_CONTINUE("Unable to retrieve HDR_FILE property for GridData. \n", ERR_EINVAL);
00078 return grid;
00079 }
00080 hdr_fname = (char *) entry->val;
00081 }
00082
00083
00084 key[0] = '\0';
00085 strcpy(key, data_keyword);
00086 strcat(key, FIRE_GRIDDATA_DATA_TYPE);
00087 if ( ChHashTableRetrieve(proptbl, key, (void *)&entry) ) {
00088 ERR_ERROR_CONTINUE("Unable to retrieve GRID_DATA_TYPE property for GridData. \n", ERR_EINVAL);
00089 return grid;
00090 }
00091 if ( strcmp(entry->val, GetFireVal(VAL_DOUBLE)) == 0 )
00092 grid_type = EnumDblGrid;
00093 else if ( strcmp(entry->val, GetFireVal(VAL_FLOAT)) == 0 )
00094 grid_type = EnumFltGrid;
00095 else if ( strcmp(entry->val, GetFireVal(VAL_LONGINT)) == 0 )
00096 grid_type = EnumLIntGrid;
00097 else if ( strcmp(entry->val, GetFireVal(VAL_INT)) == 0 )
00098 grid_type = EnumIntGrid;
00099 else if ( strcmp(entry->val, GetFireVal(VAL_BYTE)) == 0 )
00100 grid_type = EnumByteGrid;
00101 else {
00102 ERR_ERROR_CONTINUE("Unrecognized GRID_DATA_TYPE property for GridData. \n", ERR_EINVAL);
00103 return grid;
00104 }
00105
00106
00107 switch(is_ascii) {
00108 case 1:
00109 grid = InitGridDataFromAsciiRaster(main_fname, grid_type);
00110 break;
00111 case 0:
00112 grid = InitGridDataFromBinaryRaster(main_fname, hdr_fname, grid_type);
00113 break;
00114 default:
00115 ERR_ERROR_CONTINUE("Raster format specified in config file should be ASCII or BINARY. \n", ERR_EFAILED);
00116 break;
00117 }
00118
00119 return grid;
00120 }
00121
00122 int IsGridDataMatchingFireGridData(GridData * agd, GridData * bgd) {
00123 if ( agd != NULL && bgd != NULL ) {
00124 if ( agd->ghdr->nrows == bgd->ghdr->nrows
00125 && agd->ghdr->ncols == bgd->ghdr->ncols
00126 && agd->ghdr->xllcorner == bgd->ghdr->xllcorner
00127 && agd->ghdr->yllcorner == bgd->ghdr->yllcorner ) {
00128 return 1;
00129 }
00130 }
00131 return 0;
00132 }
00133
00134