Go to the documentation of this file.
13 #define PI 3.141592654
14 #define RADEG 57.29577951
24 #define REMM 6371000.000
27 static int firstCall = 1;
30 static grid_info_t* dem_grid = {0};
32 static const char* demNames[] ={
"height",
"z",
"depth",
"elevation",
"altitude",
NULL};
33 static grid_info_t* surfGrid = {0};
35 static const char* surfNames[] = {
"water_surface_height",
NULL};
86 fprintf(
stdout,
"\tSouth = %8.3f\n", tile.
NSEW[1]);
87 fprintf(
stdout,
"\tNorth = %8.3f\n", tile.
NSEW[0]);
92 fprintf(
stdout,
"\tWest = %8.3f\n", tile.
NSEW[3]);
93 fprintf(
stdout,
"\tEast = %8.3f\n", tile.
NSEW[2]);
97 fprintf(
stdout,
"\tvalue (%p) range = {%d,%d}\n",
107 int icol,
ncols, maxcols;
108 double lonborder, latborder =
BORDER;
109 double minlat, maxlat, dlat;
110 double minlon, maxlon, dlon;
113 dlat = 180.0 /
nrows;
117 for (irow = 0; irow <
nrows; irow++) {
120 dem.start_tile[irow] = itile;
124 ncols = (
int) round(maxcols * sin(
PI * latfrac));
138 "-E- %s:%d: Could not allocate memory for %d tiles\n",
139 __FILE__, __LINE__, itile);
146 for (irow = 0; irow <
nrows; irow++) {
149 minlat = dlat * irow - 90.0;
150 maxlat = minlat + dlat;
154 if (minlat < -90.0) minlat = -90.0;
156 if (maxlat > 90.0) maxlat = 90.0;
160 dlon = 360.0 /
ncols;
163 if (
ncols == 1) lonborder = 0;
165 lonborder = latborder / cos(minlat /
RADEG);
166 else lonborder = latborder / cos(maxlat /
RADEG);
169 for (icol = 0; icol <
ncols; icol++) {
172 minlon = dlon * icol - 180.0;
173 maxlon = minlon + dlon;
180 itile =
dem.start_tile[irow] + icol;
181 dem.tiles[itile].NSEW[0] = maxlat;
182 dem.tiles[itile].NSEW[1] = minlat;
183 dem.tiles[itile].NSEW[2] = maxlon;
184 dem.tiles[itile].NSEW[3] = minlon;
185 dem.tiles[itile].number = -1;
186 dem.tiles[itile].height =
NULL;
207 fprintf(
stderr,
"-E- %s line %d: "
208 "Unable to initialize grid for digital elevation \"%s\".\n",
209 __FILE__, __LINE__, demfile);
219 fprintf(
stderr,
"-W- %s line %d: "
220 "Could not read secondary grid info from \"%s\"; continuing.\n",
221 __FILE__, __LINE__, demfile);
236 if (dem_grid !=
NULL) {
239 for (
i = 0;
i <
dem.ntiles;
i++)
241 free(
dem.tiles[
i].height);
250 if (surfGrid !=
NULL) {
262 tile = &
dem.tiles[itile];
269 const int list_size = 30;
270 static int tile_list[30];
271 static int num_in_list = 0;
275 tile_list[num_in_list++] = itile;
276 if(num_in_list == list_size) {
279 for(
int i=0;
i<num_in_list;
i++) {
280 tile_list[
i] = tile_list[
i+1];
295 int irow, icol, itile;
300 double minlat, minlon, maxlon;
301 double minval, maxval;
309 irow = (
int) floor((
lat + 90.) / dlat);
313 dlon = 360.0 /
dem.ncols[irow];
317 icol = (
int) floor((
lon + 180.) / dlon);
319 if (icol >
dem.ncols[irow] - 1) {
320 fprintf(
stderr,
"\nERROR in load_tile():\n");
321 fprintf(
stderr,
"\ticol = %d ncols = %d\n",
322 icol, (
int)
dem.ncols[irow]);
325 itile =
dem.start_tile[irow] + icol;
326 tile = &
dem.tiles[itile];
329 if (tile->
number != itile) {
340 if (surfGrid !=
NULL) {
352 if (maxlon < tile->NSEW[2]) minlon += 360.0;
353 if (minlon > tile->
NSEW[3]) minlon -= 360.0;
373 minval =
fabs(dem_grid->FillValue);
374 maxval = -1 * minval;
375 for (
i = 0;
i < nvalues;
i++) {
378 if ((surfGrid !=
NULL) &&
379 (
fabs(surfArea.
values[
i] - surfGrid->FillValue) > DBL_EPSILON))
394 fprintf(
stderr,
"\nERROR in load_tile():\n");
396 fprintf(
stderr,
"dlat=%f irow=%d dlon=%f icol=%d itile=%d\n",
397 dlat, irow, dlon, icol, itile);
400 fprintf(
stderr,
"elevArea:\n");
419 double normLat, normLon;
422 findex[0] = findex[1] = -999.0;
429 if (normLon < 0.0) normLon += 360.0;
430 if (normLon > 360.0) normLon -= 360.0;
431 findex[0] = normLat / tile.
deltaLat;
432 findex[1] = normLon / tile.
deltaLon;
435 if ((findex[0] >= tile.
numLat) &&
436 ((tile.
endLat + FLT_EPSILON) > 90.0))
445 status = ((0 > findex[0]) || (findex[0] >= tile.
numLat) ||
446 (0 > findex[1]) || (findex[1] >= tile.
numLon));
448 fprintf(
stderr,
"-E- %s:%d: tile_findex():\n",
450 fprintf(
stderr,
"input lat = %7.3f lon = %8.3f\n",
lat,
lon);
451 fprintf(
stderr,
"norm lat = %7.3f lon = %8.3f\n", normLat, normLon);
452 fprintf(
stderr,
"output flat = %7.3f flon = %8.3f\n",
453 findex[0], findex[1]);
454 fprintf(
stderr,
" numLat = %7d Lon = %8d\n",
477 if (findex[0] > tile.
numLat - 1) findex[0] -= FLT_EPSILON;
478 if (findex[1] > tile.
numLon - 1) findex[1] -= FLT_EPSILON;
516 size_t x0, x1, y0, y1;
537 if ((x1 == tile.
numLon) &&
545 fprintf(
stderr,
"-E- %s:%d: interp_tilevalue():\n",
547 fprintf(
stderr,
" lat = %7.3f lon = %8.3f\n",
lat,
lon);
548 fprintf(
stderr,
" flat = %7.3f flon = %8.3f\n",
549 findex[0], findex[1]);
550 fprintf(
stderr,
" ilat = %7d ilon = %8d\n", (
int) y0, (
int) x0);
551 fprintf(
stderr,
"numLat = %7d Lon = %8d\n",
567 = tile.
height[y0 * nx + x0] * (1 -
x)*(1 -
y)
568 + tile.
height[y0 * nx + x1] *
x * (1 -
y)
569 + tile.
height[y1 * nx + x0] * (1 -
x) *
y
570 + tile.
height[y1 * nx + x1] *
x *
y;
589 double tszmin = 0.01;
590 double tansnz, sinsna, cossna, coslat;
591 double lat,
lon, dlat, dlon;
593 double dem_hgt, dem_old, los_hgt, los_old;
594 int stepnum, maxsteps;
606 ddist = step *
REMM * 180.0 / (dem_grid->numLat *
RADEG);
615 if ((itile < 0) || (itile >
dem.ntiles - 1)) {
616 fprintf(
stderr,
"\nERROR from load_tile():");
617 fprintf(
stderr,
"\txlat=%8.3f xlon=%8.3f itile=%d\n",
621 tile =
dem.tiles[itile];
624 if (((
int) tile.
minval == 0) &&
625 ((
int) tile.
maxval == 0)) {
637 if(
fabs(dlon) > 360.0)
643 dist = *height * tansnz *
REMM / (
REMM + *height);
646 else if (tansnz < tszmin) {
648 *height = (
float) dem_hgt;
649 dist = *height * tansnz;
655 maxsteps = tile.
maxval * tansnz / ddist + 2;
666 dist = stepnum * ddist;
673 fprintf(
stderr,
"-E- %s:%d: get_nc_height():\n",
675 fprintf(
stderr,
"\titer = %6d\n", maxsteps - stepnum);
681 * (dist * tansnz / 2.0 +
REMM)
682 / (
REMM * tansnz - dist);
684 }
while (los_hgt > dem_hgt);
687 dd = (dem_hgt - los_hgt) / (dem_hgt - los_hgt + los_old - dem_old);
697 *height = (
float) dem_hgt;
703 if (*
xlon < -180.
f) {
714 }
else if(*
xlat > 90.0) {
744 if ((itile < 0) || (itile >
dem.ntiles - 1)) {
745 fprintf(
stderr,
"\nERROR from load_tile():");
746 fprintf(
stderr,
"\txlat=%8.3f xlon=%8.3f itile=%d\n",
750 tile =
dem.tiles[itile];
752 *height = (
float) dem_hgt;
an array had not been initialized Several spelling and grammar corrections were which is read from the appropriate MCF the above metadata values were hard coded A problem calculating the average background DN for SWIR bands when the moon is in the space view port was corrected The new algorithm used to calculate the average background DN for all reflective bands when the moon is in the space view port is now the same as the algorithm employed by the thermal bands For non SWIR changes in the averages are typically less than Also for non SWIR the black body DNs remain a backup in case the SV DNs are not available For SWIR the changes in computed averages were larger because the old which used the black body suffered from contamination by the micron leak As a consequence of the if SV DNs are not available for the SWIR the EV pixels will not be the granule time is used to identify the appropriate tables within the set given for one LUT the first two or last two tables respectively will be used for the interpolation If there is only one LUT in the set of it will be treated as a constant LUT The manner in which Earth View data is checked for saturation was changed Previously the raw Earth View DNs and Space View DNs were checked against the lookup table values contained in the table dn_sat The change made is to check the raw Earth and Space View DNs to be sure they are less than the maximum saturation value and to check the Space View subtracted Earth View dns against a set of values contained in the new lookup table dn_sat_ev The metadata configuration and ASSOCIATEDINSTRUMENTSHORTNAME from the MOD02HKM product The same metatdata with extensions and were removed from the MOD021KM and MOD02OBC products ASSOCIATEDSENSORSHORTNAME was set to MODIS in all products These changes are reflected in new File Specification which users may consult for exact the pow functions were eliminated in Emissive_Cal and Emissive bands replaced by more efficient code Other calculations throughout the code were also made more efficient Aside from a few round off there was no difference to the product The CPU time decreased by about for a day case and for a night case A minor bug in calculating the uncertainty index for emissive bands was corrected The frame index(0-based) was previously being used the frame number(1-based) should have been used. There were only a few minor changes to the uncertainty index(maximum of 1 digit). 3. Some inefficient arrays(Sigma_RVS_norm_sq) were eliminated and some code lines in Preprocess_L1A_Data were moved into Process_OBCEng_Emiss. There were no changes to the product. Required RAM was reduced by 20 MB. Now
int fix_latlon(float *lat, float *lon)
int interp_nc_height(float *xlon, float *xlat, float *height)
void unload_tile(int itile)
void print_tile(tile_struct tile)
grid_info_t * allocate_gridinfo()
int tile_findex(tile_struct tile, float lat, float lon, double *findex)
void print_area(grid_area_t area)
void load_tile_cache(int itile)
double precision function f(R1)
int init_gridinfo(const char *filename, const char *varnames[], grid_info_t *grid)
int interp_tilevalue(tile_struct tile, float lat, float lon, double *result)
int tile_index(tile_struct tile, float lat, float lon, size_t *index)
void define_tile_geometry()
size_t start_tile[TILE_ROWS]
integer, parameter double
float xlon[LAC_PIXEL_NUM]
int get_grid_area(grid_info_t *grid, float north, float south, float east, float west, grid_area_t *area)
int load_tile(float lat, float lon)
int get_nc_height(float *xlon, float *xlat, float *senz, float *sena, float *height)
int get_tilevalue(tile_struct tile, float lat, float lon, double *value)