Ecological Landscape Modeling: Models Pages |
#include "gridmap.h"
Go to the source code of this file.
Defines | |
#define | A_NEG_VAL -90 |
Functions | |
void | formatDate (char *sd) |
Do some simple formatting of numeric date to text. | |
int | mapGrids (char *gridmapfilename) |
Populate the elm_OG_map grid struct with values. | |
int | initDataStruct (char *binfilename, applicationStruct *this_struct) |
Initialize data structures. | |
int | processData (char *binfilename, applicationStruct *this_struct) |
Process/acquire the grid_io data (at coarse scale). | |
void | returnData (float *dataSME, applicationStruct *this_struct) |
Map the coarse-scale data from Other-Grid to the ELM grid scale. | |
void | mapELM2Grid_io (applicationStruct *this_struct) |
UNUSED. Re-sample "grid_io" data for input to the ELM grid. | |
void | printGridMap () |
void | cleanUp (float **dataAnyGrid, float *dataELM) |
Variables | |
int | NOT_ELM_NOT_GRIO = -1 |
int | NOT_ELM_IN_GRIO = -2 |
int | IN_ELM_NOT_GRIO = -3 |
This uses the SFWMD "grid_io" functions to acquire/process grid_io data at a scale that is coarser than ELM. These input data are used as boundary conditions for variables such as stage/depth, rainfall & potential ET.
Note: documented with Doxygen, which expects specific syntax within special comments.
The Everglades Landscape Model (ELM).
last updated: Jan 2005
Definition in file gridmap.c.
#define A_NEG_VAL -90 |
void formatDate | ( | char * | sd | ) |
Do some simple formatting of numeric date to text.
The grid_io tag has a strict alphanumeric date format.
sd | starting date requested |
Definition at line 40 of file gridmap.c.
References GRID_TAG_LENGTH, and initDateRead.
Referenced by initDataStruct().
00040 { 00041 00042 char month[12],yr[5],mo[3],da[3], dig1[2], dig2[2], day_str[5] = ""; 00043 char sdate[GRID_TAG_LENGTH]; 00044 00045 sscanf(initDateRead, "%4s/%2s/%2s",yr,mo,da); /* initDateRead fmt= 1999/01/01 */ 00046 if (atoi(mo) == 1) strcpy(month,"January "); 00047 else if (atoi(mo) == 2) strcpy(month,"February "); 00048 else if (atoi(mo) == 3) strcpy(month,"March "); 00049 else if (atoi(mo) == 4) strcpy(month,"April "); 00050 else if (atoi(mo) == 5) strcpy(month,"May "); 00051 else if (atoi(mo) == 6) strcpy(month,"June "); 00052 else if (atoi(mo) == 7) strcpy(month,"July "); 00053 else if (atoi(mo) == 8) strcpy(month,"August "); 00054 else if (atoi(mo) == 9) strcpy(month,"September "); 00055 else if (atoi(mo) == 10) strcpy(month,"October "); 00056 else if (atoi(mo) == 11) strcpy(month,"November "); 00057 else if (atoi(mo) == 12) strcpy(month,"December "); 00058 00059 strcpy(sdate,month); 00060 00061 sscanf(da, "%1s%1s\n",dig1,dig2); 00062 if(strcmp(dig1,"0") != 0 ) 00063 strcpy(day_str,dig1); 00064 else strcat(day_str," "); /* need a blank space for days<10 */ 00065 strcat(day_str,dig2); 00066 strcat(day_str,", "); /* put comma and space after day */ 00067 strcat(sdate,day_str); 00068 strcat(sdate,yr); /* tag in grid_io file is "January 1, 1965", "March 11, 1965" */ 00069 strcpy(sd,sdate); 00070 }
int mapGrids | ( | char * | gridmapfilename | ) |
Populate the elm_OG_map grid struct with values.
The data are read from grmap pre-processor program output file (gridmapping.txt), located in the standard ELM input-data directory.
gridmapfilename | filename of the pre-processed grid-mapping indices |
gridmapfile_ptr Pointer to the text file that maps the relationship between ELM and the other grid
ogid Other-Grid cell ID read from input grid-mapping file
ogr ogc Other-Grid cell row (ogr), column (ogc), read from input grid-mapping file
eid ELM cell ID read from input grid-mapping file
ii Counter that is same as OGidCnt - it is just local to this function
jj Counter for eid
eINog The maximum number of smaller (elm) cells contained IN the bigger (other-grid) cell read from input grid-mapping file
Definition at line 79 of file gridmap.c.
References A_NEG_VAL, eOGMap::eidCnt, elm_OG_map, eOGMap::elmID, gridio_batch_len, eOGMap::index, eOGMap::OGCOL, OGcol_tot, eOGMap::OGID, OGidCnt, eOGMap::OGROW, and OGrow_tot.
Referenced by evap_data_wmm(), rain_data_wmm(), and stage_data_wmm().
00079 { 00080 00081 int i; 00082 int success = 1, fail = -1; 00083 char line[80]; 00085 FILE *gridmapfile_ptr; 00086 00088 int ogid=0; 00090 int ogr=0, ogc=0; 00092 int eid=0; 00094 int ii=0; 00096 int jj=0; 00097 00099 int eINog=0; 00100 for(i=0; i<80; i++) 00101 line[i]=' '; 00102 00103 /* open the file */ 00104 if((gridmapfile_ptr = fopen(gridmapfilename,"r")) == NULL) { 00105 printf( "Can't open the grid-map definition file %s!\n ",gridmapfilename ) ; 00106 exit (fail); 00107 } 00108 00109 00110 /* skip the (5) header lines in the input file, replicated here: 00111 00112 This is coarser grid ids mapped to finer grid ids 00113 Note that the mapped id = -1 means no cell intersect between 2 grids. 00114 ID ROW COL MAPPED_ID 00115 == === === ========= 00116 LINE BELOW IS RESERVED FOR APPLICATION USE, DEFAULT VALUE: 00117 */ 00118 00119 fgets(line,80,gridmapfile_ptr); /* datafile header line 1 */ 00120 fgets(line,80,gridmapfile_ptr); /* datafile header line 2 */ 00121 fgets(line,80,gridmapfile_ptr); /* datafile header line 3 */ 00122 fgets(line,80,gridmapfile_ptr); /* datafile header line 4 */ 00123 fgets(line,80,gridmapfile_ptr); /* datafile header line 5 */ 00124 00125 /* read the cell size mapping, row and col information for initializing arrays */ 00126 fgets(line,80,gridmapfile_ptr); 00127 sscanf(line,"%d %d %d %d",&eINog, &OGrow_tot, &OGcol_tot, &gridio_batch_len); 00128 00129 /* after reading the line, initialize array of struct of size OGrow_tot * OGcol_tot */ 00130 if(elm_OG_map==NULL) elm_OG_map = (struct eOGMap*) malloc(sizeof(struct eOGMap ) * OGrow_tot * OGcol_tot); 00131 if(elm_OG_map==NULL) { 00132 printf("\nFailed to allocate memory for elm_OG_map\n"); 00133 exit (fail); 00134 } 00135 00136 /* read the cell size mapping to initialize the elmID pointer */ 00137 for(ii=0; ii<OGrow_tot*OGcol_tot; ii++) { 00138 /* memory issue? */ 00139 /* if(elm_OG_map[ii].elmID==NULL) */ elm_OG_map[ii].elmID = (int*)malloc(sizeof(int)*eINog); 00140 if(elm_OG_map[ii].elmID==NULL) { 00141 printf("\nFailed to allocate memory for grid-map elmID\n"); 00142 exit (fail); 00143 } 00144 } 00145 for(ii=0; ii<OGrow_tot*OGcol_tot; ii++) { 00146 elm_OG_map[ii].eidCnt=0; 00147 elm_OG_map[ii].OGID=0; 00148 elm_OG_map[ii].OGROW=0; 00149 elm_OG_map[ii].OGCOL=0; 00150 for(jj=0; jj<eINog; jj++) { 00151 elm_OG_map[ii].elmID[jj]= A_NEG_VAL; /* struct has memory issue? */ 00152 } 00153 } 00154 ii=0, jj=0, OGidCnt = 0; /* this count may be smaller or larger than (OGrow_tot*OGcol_tot) 00155 * because it contains Other-Grid cells 00156 * up to elm boundary (i.e., 1-2209 in case of SFWMM grid) 00157 */ 00158 00159 /* Not all the OG cells are included in the gridmapping file. 00160 Only from OG cell 1 to the upper limit of elm. 00161 i.e., in case of SFWMM cell is 2209. 00162 */ 00163 /* this is the first line of data of the cell-by-cell mapping attributes */ 00164 fgets(line,80,gridmapfile_ptr); 00165 sscanf(line,"%d %d %d %d",&elm_OG_map[ii].OGID,&elm_OG_map[ii].OGROW, 00166 &elm_OG_map[ii].OGCOL,&elm_OG_map[ii].elmID[jj]); 00167 00168 elm_OG_map[ii].index = ii; /* init the first index to 0 (value of ii at this point) */ 00169 elm_OG_map[ii].eidCnt++; /* increment to show we've read in one more (actually, just one at this point) elmID */ 00170 OGidCnt++; /* increment to show we've read in one more (actually, just one at this point) OGID */ 00171 ii++; /* increment to show we've read in one more (actually, just one at this point) elm_OG_map struct */ 00172 00173 while(fgets(line,80,gridmapfile_ptr) != NULL) { 00174 sscanf(line,"%d %d %d %d",&ogid,&ogr,&ogc,&eid); 00175 if(ogid == elm_OG_map[ii-1].OGID) { 00176 /* when OGID is same as next line OGID, the structure 00177 only must be updated for the elmID and eidCnt, we do repeat though! 00178 The index will be modified later on according 00179 to how elm cell falls in OG cell. This index 00180 is same as ii and OGidCnt in this loop */ 00181 jj++; /* counter for eid */ 00182 elm_OG_map[ii-1].elmID[jj] = eid; 00183 elm_OG_map[ii-1].OGROW = ogr; 00184 elm_OG_map[ii-1].OGCOL = ogc; 00185 elm_OG_map[ii-1].eidCnt++; 00186 elm_OG_map[ii-1].index = ii-1; 00187 } 00188 else { 00189 jj=0; 00190 elm_OG_map[ii].OGID = ogid; 00191 elm_OG_map[ii].elmID[jj] = eid; 00192 elm_OG_map[ii].OGROW = ogr; 00193 elm_OG_map[ii].OGCOL = ogc; 00194 elm_OG_map[ii].index = ii; 00195 elm_OG_map[ii].eidCnt++; 00196 00197 OGidCnt++; /* counts number of OG cell id's, used as a global variable for later on */ 00198 ii++; /* ii is same as OGidCnt - it is just local to this function */ 00199 } 00200 00201 } /* end of while-reading of data line/records */ 00202 fclose(gridmapfile_ptr); 00203 return success; 00204 }
int initDataStruct | ( | char * | binfilename, | |
applicationStruct * | this_struct | |||
) |
Initialize data structures.
This function at time=0 initializes the data structures for ELM values of size (s0xs1) and 2d([gridio_batch_len][OGrow_tot*OGcol_tot]) array of grid_io data for holding Other-Grid data values. Also reads an grid_io binary file and moves the file pointer to the initial date on the record.
binfilename | file name of grid_io data | |
this_struct | struct of the grid information |
Definition at line 217 of file gridmap.c.
References applicationStruct::binfile_ptr, applicationStruct::dataAnyGrid, applicationStruct::dataELM, applicationStruct::day, formatDate(), applicationStruct::grid, grid_read(), grid_read_header(), grid_skip(), GRID_TAG_LENGTH, gridio_batch_len, GRID::header, nalloc(), GR_HEADER::number_of_nodes, OGcol_tot, OGrow_tot, applicationStruct::recRead, s0, s1, applicationStruct::skip, applicationStruct::step, applicationStruct::tag, and applicationStruct::values.
Referenced by evap_data_wmm(), rain_data_wmm(), and stage_data_wmm().
00217 { 00218 00219 char sdate[GRID_TAG_LENGTH]; 00220 int comp; 00221 00222 int i, j; /* short loop counters */ 00223 int fail = -1, success = 1; 00224 int pos; /* not used except in assignment */ 00225 00226 00227 this_struct->day = this_struct->recRead = this_struct->step = 0; 00228 00229 if(this_struct->dataELM==NULL) this_struct->dataELM = (float*)malloc(sizeof(float)*s0*s1); 00230 if(this_struct->dataELM==NULL) { 00231 printf("\nFailed to allocate memory for grid-map dataELM\n"); 00232 exit (fail); 00233 } 00234 for(i=0;i<s0*s1;i++) { 00235 this_struct->dataELM[i]=0.0; 00236 } 00237 00238 /* initialize the variable for holding multiday data values in GRID grid */ 00239 /* initialize array of pointers; each points to OGrow_tot*OGcol_tot (columns) floats */ 00240 /* v2.8.2 - had improper malloc -- sizeof(float*) -- w/o the array size - caused probs w/ some compilers */ 00241 if(this_struct->dataAnyGrid==NULL) this_struct->dataAnyGrid = (float**)malloc( gridio_batch_len * sizeof(float)*OGrow_tot*OGcol_tot ); 00242 if(this_struct->dataAnyGrid==NULL) { 00243 printf("\nFailed to allocate memory for grid-map dataAnyGrid\n"); 00244 exit (fail); 00245 } 00246 00247 for(i=0; i<gridio_batch_len; i++) { 00248 if(this_struct->dataAnyGrid[i]==NULL) this_struct->dataAnyGrid[i] = (float*) malloc(sizeof(float) * (OGrow_tot * OGcol_tot) ) ; 00249 if(this_struct->dataAnyGrid[i]==NULL) { 00250 printf("\nFailed to allocate memory for grid-map gridio_batch_len[%d]\n",i); 00251 exit (fail); 00252 } 00253 for (j=0; j<OGrow_tot*OGcol_tot; j++) { 00254 this_struct->dataAnyGrid[i][j]=0.0; 00255 } 00256 } 00257 00258 00259 /* open the grid_io data file */ 00260 if((this_struct->binfile_ptr = fopen(binfilename,"rb")) == NULL) { 00261 printf( "Can't open the grid_io binary data %s file!\n ", binfilename) ; 00262 exit (fail); 00263 } 00264 00265 00266 /* read the header and config part of the grid */ 00267 if(grid_read_header(this_struct->binfile_ptr, &this_struct->grid) != 0) { 00268 fprintf(stdout, "Unable to read grid header from grid_io input file %s\n", binfilename); 00269 exit (fail); 00270 } 00271 /* initialize the variable for holding the data values */ 00272 /* this is used by first come first served client. is just a temp storage 00273 that is initialized */ 00274 if(this_struct->values==NULL) this_struct->values = (float*)nalloc(this_struct->grid.header.number_of_nodes*sizeof(float),"values"); 00275 if(this_struct->values==NULL) { 00276 printf("\nFailed to allocate memory for grid_io values array\n"); 00277 exit (fail); 00278 } 00279 for(i=0; i< this_struct->grid.header.number_of_nodes; ++i) { 00280 this_struct->values[i] = 0.0; 00281 } 00282 00283 /* reformat the starting date for comparison with grid_io tag format*/ 00284 formatDate(sdate); 00285 00286 00287 /* keep comparing the dates in binary file and the requested date 00288 by the model. if found, grid_skip to the beginning. */ 00289 comp = 1; 00290 while(comp != 0) { 00291 if(grid_read(this_struct->binfile_ptr, &this_struct->grid, this_struct->tag, this_struct->values ) == -1 ) { 00292 fprintf(stdout, "Couldn't match starting date for date = %s in %s\n",sdate, binfilename); 00293 exit (fail); 00294 } 00295 comp = strncmp(this_struct->tag, sdate, strlen(sdate)); 00296 00297 if(comp == 0) { 00298 pos = grid_skip(this_struct->binfile_ptr, &this_struct->grid, -1); 00299 } 00300 00301 this_struct->skip++; /* number of records skipped to get to starting date */ 00302 00303 } /* end of while */ 00304 00305 return success; 00306 }
int processData | ( | char * | binfilename, | |
applicationStruct * | this_struct | |||
) |
Process/acquire the grid_io data (at coarse scale).
Checks the number of days simulated vs the number of records (arrays) read so far, and puts the data into memory, awaiting for returning the data for use.
binfilename | file name of grid_io data | |
this_struct | struct of the grid information |
Definition at line 318 of file gridmap.c.
References applicationStruct::binfile_ptr, GRID::config, applicationStruct::dataAnyGrid, applicationStruct::grid, grid_read(), grid_read_header(), grid_skip(), gridio_batch_len, OGcol_tot, OGidCnt, PORnumday, applicationStruct::recRead, applicationStruct::skip, applicationStruct::step, applicationStruct::tag, applicationStruct::values, GR_CONFIG::xend, and GR_CONFIG::xstart.
Referenced by evap_data_wmm(), rain_data_wmm(), and stage_data_wmm().
00318 { 00319 00320 int kk=0, ii=0, jj=0; 00321 int jstart = 0; /* starting row of grid_io data */ 00322 int jend = 0; /* ending row of grid_io data */ 00323 int ogid = 0; /* Other-Grid number of cells within elm boundary*/ 00324 int cntr = 0; /* grid_io data node counter*/ 00325 int this_sz = 0; /* only used in assignment statement */ 00326 int row_bound = 0; 00327 00328 float val = 0.0; 00329 00330 int fail = -1, success = 1; 00331 00332 /* TODO: determine what comment below means */ 00333 /* don't use the logic "if(SimTime.TIME>0) condition", does not work if 00334 gridio_batch_len is smaller than N_Itr, and also, SimTime.TIME 00335 gets undefined with very large values after many 00336 iteration when using cc compiler. 00337 */ 00338 if (this_struct->step >= gridio_batch_len) { /* read more records */ 00339 00340 /* reopen this file and skip to the appropriate record */ 00341 if((this_struct->binfile_ptr = fopen(binfilename, "rb")) == NULL) { 00342 printf("Can't open the rainfall binary %s file!\n",binfilename ) ; 00343 exit (fail); 00344 } 00345 00346 if(grid_read_header(this_struct->binfile_ptr, &this_struct->grid) != 0) { 00347 fprintf(stdout, "Unable to read grid header from input file %s\n",binfilename); 00348 exit (fail); 00349 } 00350 00351 this_sz = grid_skip(this_struct->binfile_ptr, &this_struct->grid, (this_struct->skip+this_struct->recRead-1)); 00352 00353 } 00354 00355 this_struct->step = 0; 00356 00357 /* recRead and PORnumday (global, number of days in sim Period of Record) and gridio_batch_len happens once 00358 * per batch reading. This while populates the other grid structure 00359 * with available data read from grid_io. Those Other-Grid (OG) cells that are 00360 * not within grid_io boundary are filled with the boundary cells values. 00361 */ 00362 00363 /* PORnumday is established by user by input to Driver.parm file */ 00364 while(this_struct->recRead < PORnumday && this_struct->step < gridio_batch_len ) { 00365 if(grid_read(this_struct->binfile_ptr, &this_struct->grid, this_struct->tag, this_struct->values ) != 0 ) { 00366 fprintf(stdout, "Unable to read grid value from input file %s\n",binfilename); 00367 exit (fail); 00368 } 00369 00370 ogid = 0; 00371 cntr = 0; 00372 val = 0.0; 00373 00374 /* binary grid_io contains X rows, we need up to 00375 * elm boundary which is number of OG cells within 00376 * elm boundary. Although the elm_OG_map 00377 * is initialized by OGrow_tot*OGcol_tot, by reading the data 00378 * from the gridmapping.txt file, we read only as many as 00379 * OG rows that are within elm boundary. This is 00380 * represented by the row_bound, calculated below. 00381 */ 00382 00383 row_bound = OGidCnt / OGcol_tot; 00384 for(ii=0; ii< row_bound; ++ii) { 00385 jstart = *(this_struct->grid.config.xstart+ii); 00386 jend = *(this_struct->grid.config.xend+ii); 00387 val = this_struct->values[cntr]; 00388 00389 /* fill the OG cells not in grid_io (missings) with the value in jstart 00390 we do this to make sure every elm cell that does not map to grid_io but 00391 maps to OG cells, contains value 00392 */ 00393 for(kk=1; kk<jstart; kk++, ogid++) 00394 this_struct->dataAnyGrid[this_struct->step][ogid] = val; 00395 00396 /* because using the last grid_io cell boundary value 00397 * for the OG adjacent empty cell, we can use 'jj<jend' 00398 * instead if 'jj<=jend' 00399 */ 00400 for(jj=jstart; jj<jend; jj++, ogid++, cntr++) { 00401 this_struct->dataAnyGrid[this_struct->step][ogid] = this_struct->values[cntr]; 00402 } 00403 00404 /* fill the missings with jend value */ 00405 for(kk=jend; kk<OGcol_tot+1; kk++, ogid++) { 00406 this_struct->dataAnyGrid[this_struct->step][ogid] = this_struct->values[cntr]; 00407 } 00408 00409 cntr++; 00410 } 00411 this_struct->recRead = this_struct->recRead + 1; /* increment the total number of records read */ 00412 this_struct->step = this_struct->step +1; /* increment the number of steps taken in reading this batch of records */ 00413 } /* end while for reading records */ 00414 00415 if(this_struct->step > 0 ) 00416 fclose (this_struct->binfile_ptr); /* close the binary file after each group of files read */ 00417 00418 this_struct->step = 0; /* set the step to 0, so that returnData will start at the beginning */ 00419 }
void returnData | ( | float * | dataSME, | |
applicationStruct * | this_struct | |||
) |
Map the coarse-scale data from Other-Grid to the ELM grid scale.
At this time, we have read enough records (data arrays) into memory, and this function remaps the Other-Grid data for the day to the ELM/SME grid data structure (passing it to the caller function in UnitMod.c). This function is called daily; however the data records are already processed up through gridio_batch_len.
dataSME | Data array at the ELM/SME resolution | |
this_struct | struct of the grid information |
Definition at line 433 of file gridmap.c.
References applicationStruct::dataAnyGrid, applicationStruct::dataELM, applicationStruct::day, applicationStruct::dayCntr, debug, eOGMap::eidCnt, elm_OG_map, eOGMap::elmID, eOGMap::index, NOT_ELM_NOT_GRIO, eOGMap::OGCOL, eOGMap::OGID, OGidCnt, eOGMap::OGROW, applicationStruct::recCntr, applicationStruct::recRead, and applicationStruct::step.
Referenced by evap_data_wmm(), rain_data_wmm(), and stage_data_wmm().
00433 { 00434 00435 int i=0, j=0; 00436 int ii=0; 00437 int index=0; 00438 /* int eid=0; */ 00439 00440 this_struct->dayCntr += 1; /* for printing purpose only */ 00441 this_struct->recCntr = this_struct->recRead - this_struct->dayCntr; 00442 00443 00444 /* init for the bottom part of elm that does not have data is done in initData */ 00445 00446 /* map wmm data to elm data */ 00447 for(ii=0; ii<OGidCnt; ++ii) { 00448 00449 if(debug > 4) { 00450 index = elm_OG_map[ii].index; 00451 printf("%d %d %d %d %d %3.3f\n",index, elm_OG_map[ii].OGID, elm_OG_map[ii].OGROW, 00452 elm_OG_map[ii].OGCOL ,elm_OG_map[ii].elmID[0], 00453 this_struct->dataAnyGrid[this_struct->step][ii]); 00454 } 00455 00456 if(elm_OG_map[ii].elmID[0] == NOT_ELM_NOT_GRIO) 00457 continue; 00458 00459 for(i=0; i<elm_OG_map[ii].eidCnt; i++) { 00460 j = elm_OG_map[ii].elmID[i]; 00461 00462 this_struct->dataELM[j] = this_struct->dataAnyGrid[this_struct->step][ii]; /* * 254; */ 00463 } 00464 } 00465 00466 00467 /* put in applxx_inp it is working 00468 for(i = 0; i < s0; i++) { 00469 for(j = 0; j < s1; j++) { 00470 eid = i*s1+j; 00471 dataSME[T((i+1),(j+1))] = (int)(this_struct->dataELM[eid]); 00472 } 00473 } */ 00474 00475 this_struct->step = this_struct->step + 1; /* global, reset for the next run */ 00476 this_struct->day = this_struct->day + 1; 00477 }
void mapELM2Grid_io | ( | applicationStruct * | this_struct | ) |
UNUSED. Re-sample "grid_io" data for input to the ELM grid.
Used for all the ELM cells that fall within some other (coarser-scale) rectangular grid of grid_io-formatted data. Our source of data is the grid_io binary data that usually covers only the clipped area of South Florida Water Management Model (SFWMM) and not the full domain of the SFWMM (or any Other-Grid of grid_io data). Therefore, if ELM cells are within the Other-Grid, but there is no grid_io data available at that ELM grid location (outside of grid_io data domain), we need to estimate data for that portion of the Other-Grid cells as well. This function maps ELM cells to the Other-Grid cells and their data, if data are availabile. The domain of both the ELM and the Other-Grid are rectangular, and the grid_io data is within the Other-Grid boundary area.
Definition at line 524 of file gridmap.c.
References GRID::config, elm_OG_map, eOGMap::elmID, applicationStruct::grid, IN_ELM_NOT_GRIO, eOGMap::index, NOT_ELM_IN_GRIO, NOT_ELM_NOT_GRIO, OGcol_tot, eOGMap::OGID, OGrow_tot, GR_CONFIG::xend, and GR_CONFIG::xstart.
00524 { 00525 00526 int ii=0, tmp_id=0, jstart=0, jend=0, diff=0; 00527 int this_index=0, kk=0,j=0, jj=0; 00528 00529 for(ii=0; ii<OGrow_tot ;ii++) { 00530 jstart = *(this_struct->grid.config.xstart+ii); 00531 jend = *(this_struct->grid.config.xend+ii); 00532 tmp_id = ii * OGcol_tot + jstart; /* running cell id of grid_io wmm grid */ 00533 diff = jend - jstart + 1; /* number of cells in this row */ 00534 00535 this_index = tmp_id - 1; 00536 00537 for(kk=0;kk<jstart-1;kk++){ 00538 j=ii*OGcol_tot+kk; 00539 /* elm cell exists, grid_io does not have data for it we have to patch data */ 00540 if(elm_OG_map[j].elmID[0] == NOT_ELM_NOT_GRIO) 00541 elm_OG_map[j].index = NOT_ELM_NOT_GRIO; /*out of elm boundary*/ 00542 else /* in elm not in grid_io */ 00543 elm_OG_map[j].index = IN_ELM_NOT_GRIO; 00544 } 00545 00546 for(kk=0;kk<diff;++kk) { /* finds corresponding cell ids of wmm to grid_io cell ids for this row */ 00547 if(elm_OG_map[this_index+kk].OGID == tmp_id+kk) { /* found the OG cell in grid_io file */ 00548 if(elm_OG_map[this_index+kk].elmID[0]==NOT_ELM_NOT_GRIO) { 00549 elm_OG_map[this_index+kk].index = NOT_ELM_IN_GRIO; 00550 } 00551 /* found the elm cell in grid_io, keep the index */ 00552 } 00553 /* else within grid_io boundary , leave the default index */ 00554 } /* end of for kk */ 00555 00556 for(kk=jend;kk<OGcol_tot;kk++) { 00557 if(elm_OG_map[ii*OGcol_tot+kk].elmID[0] == NOT_ELM_NOT_GRIO) 00558 elm_OG_map[ii*OGcol_tot+kk].index = NOT_ELM_NOT_GRIO; 00559 else 00560 elm_OG_map[ii*OGcol_tot+kk].index = IN_ELM_NOT_GRIO; 00561 } 00562 } /* end of for ii */ 00563 }
void printGridMap | ( | ) |
Definition at line 570 of file gridmap.c.
References eOGMap::eidCnt, elm_OG_map, eOGMap::elmID, eOGMap::index, eOGMap::OGCOL, OGcol_tot, eOGMap::OGID, eOGMap::OGROW, and OGrow_tot.
Referenced by evap_data_wmm(), rain_data_wmm(), and stage_data_wmm().
00570 { 00571 00572 int i,j; 00573 00574 printf("\ngridmap ==> Printing GridMap .......\n"); 00575 printf("GRID_ID GRID_ROW GRID_COL INDEX ELM_ID ELM_CNT\n"); 00576 printf("-----------------------------------------------\n"); 00577 for(i=0;i<OGrow_tot*OGcol_tot;i++) { 00578 printf("%d\t%d\t%d\t%d\t%d\t%d\n",elm_OG_map[i].OGID,elm_OG_map[i].OGROW, 00579 elm_OG_map[i].OGCOL,elm_OG_map[i].index,elm_OG_map[i].elmID[0],elm_OG_map[i].eidCnt); 00580 for(j=1;j<elm_OG_map[i].eidCnt;j++) 00581 printf("\t\t\t\t%d\n",elm_OG_map[i].elmID[j]); 00582 } 00583 }
void cleanUp | ( | float ** | dataAnyGrid, | |
float * | dataELM | |||
) |
Definition at line 643 of file gridmap.c.
References elm_OG_map, eOGMap::elmID, gridio_batch_len, OGcol_tot, and OGrow_tot.
00643 { 00644 int i; 00645 00646 printf("\ngridmap ==> Cleaning up !\n"); 00647 for(i=0;i<OGrow_tot*OGcol_tot;i++) { 00648 if(elm_OG_map[i].elmID != NULL) 00649 free(elm_OG_map[i].elmID); 00650 } 00651 if(elm_OG_map != NULL) 00652 free(elm_OG_map); 00653 00654 if(dataELM != NULL) 00655 free(dataELM); 00656 00657 for(i=0;i<gridio_batch_len;i++) { 00658 if(dataAnyGrid[i] != NULL) 00659 free(dataAnyGrid[i]); 00660 } 00661 if(dataAnyGrid != NULL) 00662 free(dataAnyGrid); 00663 00664 // if(values != NULL) 00665 // free(values); 00666 }
int NOT_ELM_NOT_GRIO = -1 |
int NOT_ELM_IN_GRIO = -2 |
int IN_ELM_NOT_GRIO = -3 |