Go to the documentation of this file.
   17 #define REMM 6371000.000 
   20 static int firstCall = 1;
 
   23 static grid_info_t* dem_grid = {0};
 
   25 static const char* demNames[] ={
"height", 
"z", 
"depth", 
"elevation", 
"altitude", 
NULL};
 
   26 static grid_info_t* surfGrid = {0};
 
   28 static const char* surfNames[] = {
"water_surface_height", 
NULL};
 
   79     fprintf(
stdout, 
"\tSouth    = %8.3f\n", tile.
NSEW[1]);
 
   80     fprintf(
stdout, 
"\tNorth    = %8.3f\n", tile.
NSEW[0]);
 
   85     fprintf(
stdout, 
"\tWest     = %8.3f\n", tile.
NSEW[3]);
 
   86     fprintf(
stdout, 
"\tEast     = %8.3f\n", tile.
NSEW[2]);
 
   90     fprintf(
stdout, 
"\tvalue (%p) range = {%d,%d}\n",
 
  100     int icol, 
ncols, maxcols;
 
  101     double lonborder, latborder = 
BORDER;
 
  102     double minlat, maxlat, dlat;
 
  103     double minlon, maxlon, dlon;
 
  106     dlat = 180.0 / 
nrows; 
 
  110     for (irow = 0; irow < 
nrows; irow++) {
 
  113         dem.start_tile[irow] = itile;
 
  117         ncols = (
int) round(maxcols * sin(
PI * latfrac));
 
  131                 "-E- %s:%d: Could not allocate memory for %d tiles\n",
 
  132                 __FILE__, __LINE__, itile);
 
  139     for (irow = 0; irow < 
nrows; irow++) {
 
  142         minlat = dlat * irow - 90.0;
 
  143         maxlat = minlat + dlat;
 
  147         if (minlat < -90.0) minlat = -90.0;
 
  149         if (maxlat > 90.0) maxlat = 90.0;
 
  153         dlon = 360.0 / 
ncols;
 
  156         if (
ncols == 1) lonborder = 0; 
 
  158             lonborder = latborder / cos(minlat / 
RADEG);
 
  159         else lonborder = latborder / cos(maxlat / 
RADEG);
 
  162         for (icol = 0; icol < 
ncols; icol++) {
 
  165             minlon = dlon * icol - 180.0;
 
  166             maxlon = minlon + dlon;
 
  173             itile = 
dem.start_tile[irow] + icol;
 
  174             dem.tiles[itile].NSEW[0] = maxlat;
 
  175             dem.tiles[itile].NSEW[1] = minlat;
 
  176             dem.tiles[itile].NSEW[2] = maxlon;
 
  177             dem.tiles[itile].NSEW[3] = minlon;
 
  178             dem.tiles[itile].number = -1; 
 
  179             dem.tiles[itile].height = 
NULL; 
 
  200         fprintf(
stderr, 
"-E- %s line %d: " 
  201                 "Unable to initialize grid for digital elevation \"%s\".\n",
 
  202                 __FILE__, __LINE__, 
input->demfile);
 
  212         fprintf(
stderr, 
"-W- %s line %d: " 
  213                 "Could not read secondary grid info from \"%s\"; continuing.\n",
 
  214                 __FILE__, __LINE__, 
input->demfile);
 
  229     if (dem_grid != 
NULL) {
 
  232         for (
i = 0; 
i < 
dem.ntiles; 
i++)
 
  234                 free(
dem.tiles[
i].height);
 
  243         if (surfGrid != 
NULL) {
 
  255     tile = &
dem.tiles[itile];
 
  262     const int list_size = 30;
 
  263     static int tile_list[30];
 
  264     static int num_in_list = 0;
 
  268     tile_list[num_in_list++] = itile;
 
  269     if(num_in_list == list_size) {
 
  272         for(
int i=0; 
i<num_in_list; 
i++) {
 
  273             tile_list[
i] = tile_list[
i+1];
 
  288     int irow, icol, itile;
 
  293     double minlat, minlon, maxlon;
 
  294     double minval, maxval;
 
  302     irow = (
int) floor((
lat + 90.) / dlat); 
 
  306     dlon = 360.0 / 
dem.ncols[irow]; 
 
  310         icol = (
int) floor((
lon + 180.) / dlon); 
 
  312     if (icol > 
dem.ncols[irow] - 1) {
 
  313         fprintf(
stderr, 
"\nERROR in load_tile():\n");
 
  314         fprintf(
stderr, 
"\ticol = %d ncols = %d\n",
 
  315                 icol, (
int) 
dem.ncols[irow]);
 
  318     itile = 
dem.start_tile[irow] + icol; 
 
  319     tile = &
dem.tiles[itile];
 
  322     if (tile->
number != itile) {
 
  333         if (surfGrid != 
NULL) {
 
  345         if (maxlon < tile->NSEW[2]) minlon += 360.0;
 
  346         if (minlon > tile->
NSEW[3]) minlon -= 360.0;
 
  364         minval = 
fabs(dem_grid->FillValue);
 
  365         maxval = -1 * minval;
 
  366         for (
i = 0; 
i < nvalues; 
i++) {
 
  369             if ((surfGrid != 
NULL) &&
 
  370                     (
fabs(surfArea.
values[
i] - surfGrid->FillValue) > DBL_EPSILON))
 
  385         fprintf(
stderr, 
"\nERROR in load_tile():\n");
 
  387         fprintf(
stderr, 
"dlat=%f irow=%d dlon=%f icol=%d itile=%d\n",
 
  388                 dlat, irow, dlon, icol, itile);
 
  391         fprintf(
stderr, 
"elevArea:\n");
 
  410     double normLat, normLon;
 
  413     findex[0] = findex[1] = -999.0;
 
  420     if (normLon < 0.0) normLon += 360.0; 
 
  421     if (normLon > 360.0) normLon -= 360.0; 
 
  422     findex[0] = normLat / tile.
deltaLat;
 
  423     findex[1] = normLon / tile.
deltaLon;
 
  426     if ((findex[0] >= tile.
numLat) &&
 
  427             ((tile.
endLat + FLT_EPSILON) > 90.0))
 
  436     status = ((0 > findex[0]) || (findex[0] >= tile.
numLat) ||
 
  437             (0 > findex[1]) || (findex[1] >= tile.
numLon));
 
  439         fprintf(
stderr, 
"-E- %s:%d: tile_findex():\n",
 
  441         fprintf(
stderr, 
"input    lat = %7.3f   lon = %8.3f\n", 
lat, 
lon);
 
  442         fprintf(
stderr, 
"norm     lat = %7.3f   lon = %8.3f\n", normLat, normLon);
 
  443         fprintf(
stderr, 
"output  flat = %7.3f  flon = %8.3f\n",
 
  444                 findex[0], findex[1]);
 
  445         fprintf(
stderr, 
"      numLat = %7d   Lon = %8d\n",
 
  468     if (findex[0] > tile.
numLat - 1) findex[0] -= FLT_EPSILON;
 
  469     if (findex[1] > tile.
numLon - 1) findex[1] -= FLT_EPSILON;
 
  507     size_t x0, x1, y0, y1;
 
  528     if ((x1 == tile.
numLon) &&
 
  536         fprintf(
stderr, 
"-E- %s:%d: interp_tilevalue():\n",
 
  538         fprintf(
stderr, 
"   lat = %7.3f   lon = %8.3f\n", 
lat, 
lon);
 
  539         fprintf(
stderr, 
"  flat = %7.3f  flon = %8.3f\n",
 
  540                 findex[0], findex[1]);
 
  541         fprintf(
stderr, 
"  ilat = %7d  ilon = %8d\n", (
int) y0, (
int) x0);
 
  542         fprintf(
stderr, 
"numLat = %7d   Lon = %8d\n",
 
  558             = tile.
height[y0 * nx + x0] * (1 - 
x)*(1 - 
y) 
 
  559             + tile.
height[y0 * nx + x1] * 
x * (1 - 
y) 
 
  560             + tile.
height[y1 * nx + x0] * (1 - 
x) * 
y  
  561             + tile.
height[y1 * nx + x1] * 
x * 
y; 
 
  580     double tszmin = 0.01;
 
  581     double tansnz, sinsna, cossna, coslat;
 
  582     double lat, 
lon, dlat, dlon;
 
  584     double dem_hgt, dem_old, los_hgt, los_old;
 
  585     int stepnum, maxsteps;
 
  597         ddist = step * 
REMM * 180.0 / (dem_grid->numLat * 
RADEG);
 
  606     if ((itile < 0) || (itile > 
dem.ntiles - 1)) {
 
  607             fprintf(
stderr, 
"\nERROR from load_tile():");
 
  608             fprintf(
stderr, 
"\txlat=%8.3f  xlon=%8.3f  itile=%d\n",
 
  612     tile = 
dem.tiles[itile];
 
  615     if (((
int) tile.
minval == 0) &&
 
  616             ((
int) tile.
maxval == 0)) {
 
  632         dist = *height * tansnz * 
REMM / (
REMM + *height);
 
  635     else if (tansnz < tszmin) {
 
  637         *height = (
float) dem_hgt;
 
  638         dist = *height * tansnz;
 
  644         maxsteps = tile.
maxval * tansnz / ddist + 2;
 
  655             dist = stepnum * ddist;
 
  662                 fprintf(
stderr, 
"-E- %s:%d: get_nc_height():\n",
 
  664                 fprintf(
stderr, 
"\titer = %6d\n", maxsteps - stepnum);
 
  670                     * (dist * tansnz / 2.0 + 
REMM)
 
  671                     / (
REMM * tansnz - dist);
 
  673         } 
while (los_hgt > dem_hgt);
 
  676         dd = (dem_hgt - los_hgt) / (dem_hgt - los_hgt + los_old - dem_old);
 
  686     *height = (
float) dem_hgt;
 
  692     if (*
xlon < -180.
f) {
 
  717     if ((itile < 0) || (itile > 
dem.ntiles - 1)) {
 
  718         fprintf(
stderr, 
"\nERROR from load_tile():");
 
  719         fprintf(
stderr, 
"\txlat=%8.3f  xlon=%8.3f  itile=%d\n",
 
  723     tile = 
dem.tiles[itile];
 
  725     *height = (
float) dem_hgt;
 
  747     if ((itile < 0) || (itile > 
dem.ntiles - 1)) {
 
  748         fprintf(
stderr, 
"\nERROR from load_tile():");
 
  749         fprintf(
stderr, 
"\txlat=%8.3f  xlon=%8.3f  itile=%d\n",
 
  753     tile = 
dem.tiles[itile];
 
  755     *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 lookup_nc_height(float *xlon, float *xlat, float *height)
 
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)