Go to the documentation of this file.
10 #include <geo_normalize.h>
16 static const int itemSize = 500;
17 static const int maxReflBands = 8;
20 static double *xcal_factor =
NULL;
21 static int tile_exist;
22 static uint32_t tileLength = 0;
23 static uint32_t tileWidth = 0;
43 oli_t*
data = (oli_t*) calloc(1,
sizeof (oli_t));
45 fprintf(
stderr,
"-E- %s line %d: unable to allocate private data for OLI\n",
50 data->scale = (
double *) malloc(numBands *
sizeof (
double));
51 data->offset = (
double *) malloc(numBands *
sizeof (
double));
53 fprintf(
stderr,
"-E- %s line %d: unable to allocate scale/offset data for OLI\n",
58 data->refl_scale = (
double *) malloc(numBands *
sizeof (
double));
59 data->refl_offset = (
double *) malloc(numBands *
sizeof (
double));
61 fprintf(
stderr,
"-E- %s line %d: unable to allocate reflectance scale/offset data for OLI\n",
66 for (
i = 0;
i < numBands;
i++) {
73 data->tif = (TIFF**) calloc(numBands,
sizeof (TIFF*));
75 fprintf(
stderr,
"-E- %s line %d: unable to allocate TIFF pointers for OLI\n",
80 data->defn = (GTIFDefn*) malloc(
sizeof (GTIFDefn));
82 fprintf(
stderr,
"-E- %s line %d: unable to allocate GEOTIFF definition structure for OLI\n",
87 data->line_num_cached = -1;
95 free(
data->refl_scale);
96 free(
data->refl_offset);
123 result = strrchr(tag,
'_');
148 char fileName[FILENAME_MAX];
153 printf(
"OLI Level-1B %s\n",
file->name);
156 if ((fp = fopen(
file->name,
"r")) ==
NULL) {
157 fprintf(
stderr,
"-E- %s line %d: unable open %s\n",
158 __FILE__, __LINE__,
file->name);
162 int collectionNumber = 0;
165 int numLinesFound = 0;
166 int numSamplesFound = 0;
167 int sunAzimuthFound = 0;
168 int sunElevationFound = 0;
169 int angleFileFound = 0;
179 if (!strcmp(tag,
"COLLECTION_NUMBER")) {
180 collectionNumber = atoi(
val);
182 printf(
"OLI Level-1B Collection %d\n", collectionNumber);
185 }
else if (!strcmp(tag,
"DATE_ACQUIRED")) {
190 }
else if (!strcmp(tag,
"SCENE_CENTER_TIME")) {
195 }
else if (!strcmp(tag,
"REFLECTIVE_LINES")) {
200 }
else if (!strcmp(tag,
"REFLECTIVE_SAMPLES")) {
205 }
else if (!strncmp(tag,
"FILE_NAME_BAND_", 15)) {
207 if ((
i >= 0 && i < file->
nbands) ||
i == 8) {
209 char dir[FILENAME_MAX];
211 strcpy(fileName, dirname(dir));
212 strcat(fileName,
"/");
213 strcat(fileName,
val);
215 printf(
"OLI Level-1B Band[%d]:%s\n",
i, fileName);
217 data->tif[
i] = XTIFFOpen(fileName,
"r");
219 fprintf(
stderr,
"-E- %s line %d: unable open TIFF file %s\n",
220 __FILE__, __LINE__, fileName);
225 data->tif[
i - 1] = XTIFFOpen(fileName,
"r");
226 if (!
data->tif[
i -1 ]) {
227 fprintf(
stderr,
"-E- %s line %d: unable open TIFF file %s\n",
228 __FILE__, __LINE__, fileName);
235 }
else if (!strcmp(tag,
"ANGLE_COEFFICIENT_FILE_NAME") || !strcmp(tag,
"FILE_NAME_ANGLE_COEFFICIENT")) {
237 if ((
file->geofile ==
NULL) || (
file->geofile[0] == 0)) {
239 char dir[FILENAME_MAX];
241 strcpy(fileName, dirname(dir));
242 strcat(fileName,
"/");
243 strcat(fileName,
val);
246 printf(
"OLI Level-1B Angle File:%s\n", fileName);
250 }
else if (!strcmp(tag,
"SUN_AZIMUTH")) {
255 }
else if (!strcmp(tag,
"SUN_ELEVATION")) {
256 sunElevationFound = 1;
257 data->sunElevation = atof(
val);
260 }
else if (!strncmp(tag,
"REFLECTANCE_MULT_BAND_", 22)) {
262 if (
i >= 0 &&
i < maxReflBands) {
267 }
else if (!strncmp(tag,
"REFLECTANCE_ADD_BAND_", 21)) {
269 if (
i >= 0 &&
i < maxReflBands) {
273 }
else if (!strncmp(tag,
"RADIANCE_MULT_BAND_", 19)) {
275 if (
i >= 0 &&
i < maxReflBands) {
280 }
else if (!strncmp(tag,
"RADIANCE_ADD_BAND_", 18)) {
282 if (
i >= 0 &&
i < maxReflBands) {
292 fprintf(
stderr,
"-E- %s line %d: Did not find DATE_ACQUIRED in %s\n",
293 __FILE__, __LINE__,
file->name);
297 fprintf(
stderr,
"-E- %s line %d: Did not find SCENE_CENTER_TIME in %s\n",
298 __FILE__, __LINE__,
file->name);
301 if (!numLinesFound) {
302 fprintf(
stderr,
"-E- %s line %d: Did not find REFLECTIVE_LINES in %s\n",
303 __FILE__, __LINE__,
file->name);
306 if (!numSamplesFound) {
307 fprintf(
stderr,
"-E- %s line %d: Did not find REFLECTIVE_SAMPLES in %s\n",
308 __FILE__, __LINE__,
file->name);
311 if (!sunAzimuthFound) {
312 fprintf(
stderr,
"-E- %s line %d: Did not find SUN_AZIMUTH in %s\n",
313 __FILE__, __LINE__,
file->name);
316 if (!sunElevationFound) {
317 fprintf(
stderr,
"-E- %s line %d: Did not find SUN_ELEVATION in %s\n",
318 __FILE__, __LINE__,
file->name);
321 if (collectionNumber > 0) {
322 if (!angleFileFound) {
323 fprintf(
stderr,
"-E- %s line %d: Did not find ANGLE_COEFFICIENT_FILE_NAME in %s\n",
324 __FILE__, __LINE__,
file->name);
328 for (
i = 0;
i < maxReflBands;
i++) {
330 fprintf(
stderr,
"-E- %s line %d: Did not find FILE_NAME_BAND_%d in %s\n",
331 __FILE__, __LINE__,
i + 1,
file->name);
335 fprintf(
stderr,
"-E- %s line %d: Did not find RADIANCE_MULT_BAND_%d in %s\n",
336 __FILE__, __LINE__,
i + 1,
file->name);
340 fprintf(
stderr,
"-E- %s line %d: Did not find RADIANCE_ADD_BAND_%d in %s\n",
341 __FILE__, __LINE__,
i + 1,
file->name);
345 fprintf(
stderr,
"-E- %s line %d: Did not find REFLECTANCE_MULT_BAND_%d in %s\n",
346 __FILE__, __LINE__,
i + 1,
file->name);
350 fprintf(
stderr,
"-E- %s line %d: Did not find REFLECTANCE_ADD_BAND_%d in %s\n",
351 __FILE__, __LINE__,
i + 1,
file->name);
357 data->lat = (
double *) malloc(
file->npix * sizeof (
double));
358 data->lon = (
double *) malloc(
file->npix * sizeof (
double));
360 fprintf(
stderr,
"-E- %s line %d: unable to allocate lat/lon data for OLI\n",
368 fprintf(
stderr,
"-E- %s line %d: unable open GEOTIFF file %s\n",
369 __FILE__, __LINE__, fileName);
373 if (!GTIFGetDefn(
data->gtif,
data->defn)) {
374 fprintf(
stderr,
"-E- %s line %d: unable populate GEOTIFF defn structure for %s\n",
375 __FILE__, __LINE__, fileName);
380 int size = TIFFScanlineSize(
data->tif[0]);
382 fprintf(
stderr,
"-E- %s line %d: unexpected pixel data size in %s\n",
383 __FILE__, __LINE__, fileName);
386 data->buf = (uint16_t*) malloc(
size);
389 tile_exist = TIFFGetField(
data->tif[0], TIFFTAG_TILELENGTH, &tileLength);
391 if (tile_exist != 0) {
392 TIFFGetField(
data->tif[0], TIFFTAG_TILEWIDTH, &tileWidth);
395 int size_tile_row = maxReflBands * tileLength *
size;
396 data->buf_tile_row = (uint16_t*) malloc(size_tile_row);
400 int year, month,
day;
401 sscanf(dateStr,
"%d-%d-%d", &year, &month, &
day);
406 sscanf(timeStr,
"%d:%d:%lf", &hour, &minute, &sec);
408 int isec = (
int) sec;
412 data->msec += sec * 1000;
415 printf(
"OLI Start Time: %4d-%02d-%02d %03d %02d:%02d:%f\n",
416 year, month,
day,
data->doy, hour, minute, sec + isec);
418 printf(
"OLI file has %d bands, %d samples, %d lines\n",
422 file->terrain_corrected = 1;
433 oli_t*
data = (oli_t*)
file->private_data;
436 static short *sca_num;
437 static short *det_num;
439 static int firstCall = 1;
445 (
double) (
data->msec / 1000.0));
448 double fsol = pow(1.0 /
esdist, 2);
451 for (ip = 0; ip <
file->npix; ip++) {
454 GTIFImageToPCS(
data->gtif,
data->lon + ip,
data->lat + ip);
458 fprintf(
stderr,
"-E- %s line %d: unable reproject points for scan %d\n",
459 __FILE__, __LINE__,
recnum);
463 for (ip = 0; ip <
file->npix; ip++) {
465 l1rec->pixnum[ip] = ip;
467 if (isnan(
data->lat[ip]))
468 data->lat[ip] = -999.0;
469 if (isnan(
data->lon[ip]))
470 data->lon[ip] = -999.0;
474 if (
l1rec->lon[ip] < -181.0 ||
l1rec->lon[ip] > 181.0 ||
475 l1rec->lat[ip] < -91.0 ||
l1rec->lat[ip] > 91.0)
476 l1rec->navfail[ip] = 1;
494 for (iw = 0; iw <
l1_input->xcal_nwave; iw++)
506 if ((sca_num = (
short *) calloc(
file->npix *
file->nbands, sizeof (
short))) ==
NULL) {
508 "-E- %s line %d: Unable to allocate SCA number array.\n",
513 if ((det_num = (
short *) calloc(
file->npix *
file->nbands, sizeof (
short))) ==
NULL) {
516 "-E- %s line %d: Unable to allocate detector number array.\n",
528 fprintf(
stderr,
"-E- %s line %d: Unable to compute geometries\n",
537 l1rec->geom_per_band->solz,
l1rec->geom_per_band->sola,
538 l1rec->geom_per_band->senz,
l1rec->geom_per_band->sena,
539 sca_num, det_num,
l1_input->geom_per_band) == -1) {
540 fprintf(
stderr,
"-E- %s line %d: Unable to compute geometries\n",
547 printf(
"Exit get_oli_angles with error\n");
548 fprintf(
stderr,
"-E- %s line %d: geofile specified must be an Enhanced Meta-Data file (EMD format)\n",
555 printf(
"Exit get_oli_angles with error\n");
556 fprintf(
stderr,
"-E- %s line %d: Unable to compute geometries\n",
563 l1rec->geom_per_band->solz,
l1rec->geom_per_band->sola,
564 l1rec->geom_per_band->senz,
l1rec->geom_per_band->sena,
566 printf(
"Exit get_oli_angles with error\n");
567 fprintf(
stderr,
"-E- %s line %d: Unable to compute geometries\n",
580 if (tile_exist != 0) {
582 y_in_tile =
recnum % tileLength;
583 if (
data->line_num_cached == -1 || recnum < data->line_num_cached ||
recnum >= (
data->line_num_cached + tileLength)) {
585 data->line_num_cached =
y * tileLength;
586 for (ib = 0; ib < maxReflBands; ib++) {
588 if (TIFFReadTile(
data->tif[ib], (
void*) (
data->buf_tile_row + ib *
imageWidth * tileLength +
x * tileLength),
x,
y * tileLength, 0, 0) == -1) {
589 fprintf(
stderr,
"-E- %s line %d: Failed to read Lt, band %d, recnum %d\n",
590 __FILE__, __LINE__, ib,
recnum);
598 for (ib = 0; ib <
file->nbands; ib++) {
600 if (tile_exist == 0) {
601 if (TIFFReadScanline(
data->tif[ib], (
void*)
data->buf,
recnum, 0) == -1) {
602 fprintf(
stderr,
"-E- %s line %d: Failed to read Lt, band %d, recnum %d\n",
603 __FILE__, __LINE__, ib,
recnum);
609 _TIFFmemcpy((
void*) (
data->buf +
x), (
void*) (
data->buf_tile_row + ib *
imageWidth * tileLength +
x * tileLength + y_in_tile * tileWidth), tileWidth * 2);
612 _TIFFmemcpy((
void*) (
data->buf +
x), (
void*) (
data->buf_tile_row + ib *
imageWidth * tileLength +
x * tileLength + y_in_tile * tileWidth), (
imageWidth -
x) * 2);
616 l1rec->Fo[ib] = Fobar[ib] * fsol;
618 for (ip = 0; ip <
file->npix; ip++) {
619 ipb = ip *
file->nbands + ib;
620 if (
data->buf[ip] == 0) {
622 l1rec->navwarn[ip] = 1;
629 isb = (sca_num[ipb] - 1) *
file->nbands + ib;
630 l1rec->Lt[ipb] *= xcal_factor[isb];
643 if (tile_exist == 0) {
644 if (TIFFReadScanline(
data->tif[ib], (
void*)
data->buf,
recnum, 0) == -1) {
645 fprintf(
stderr,
"-E- %s line %d: Failed to read Lt, band %d, recnum %d\n",
646 __FILE__, __LINE__, ib,
recnum);
652 _TIFFmemcpy((
void*) (
data->buf +
x), (
void*) (
data->buf_tile_row + ib *
imageWidth * tileLength +
x * tileLength + y_in_tile * tileWidth), tileWidth * 2);
655 _TIFFmemcpy((
void*) (
data->buf +
x), (
void*) (
data->buf_tile_row + ib *
imageWidth * tileLength +
x * tileLength + y_in_tile * tileWidth), (
imageWidth -
x) * 2);
659 for (ip = 0; ip <
file->npix; ip++) {
660 if (
data->buf[ip] == 0)
663 l1rec->rho_cirrus[ip] = (
data->buf[ip] *
data->refl_scale[ib] +
data->refl_offset[ib])
672 oli_t*
data = (oli_t*)
file->private_data;
682 if (tile_exist != 0) {
683 free(
data->buf_tile_row);
687 GTIFFree(
data->gtif);
690 for (ib = 0; ib <
file->nbands; ib++) {
691 XTIFFClose(
data->tif[ib]);
696 if (xcal_factor) free(xcal_factor);
int init_geom_per_band(l1str *l1rec)
int get_oli_angles(char *emeta_filename, int32_t npix, int32_t nscan, int32_t iscan, float *solz, float *sola, float *senz, float *sena, int32_t isGeomPerBand)
double yds2unix(int16_t year, int16_t day, double secs)
int openl1_oli(filehandle *file)
int get_oli_nom_angles(char *meta_filename, int32_t npix, int32_t nscan, int32_t iscan, float *solz, float *sola, float *senz, float *sena, short *sca_num, short *det_num, int32_t isGeomPerBand)
void trimBlanks(char *str)
double esdist_(int32_t *year, int32_t *day, int32_t *msec)
no change in intended resolving MODur00064 Corrected handling of bad ephemeris attitude resolving resolving GSFcd00179 Corrected handling of fill values for[Sensor|Solar][Zenith|Azimuth] resolving MODxl01751 Changed to validate LUT version against a value retrieved from the resolving MODxl02056 Changed to calculate Solar Diffuser angles without adjustment for estimated post launch changes in the MODIS orientation relative to incidentally resolving defects MODxl01766 Also resolves MODxl01947 Changed to ignore fill values in SCI_ABNORM and SCI_STATE rather than treating them as resolving MODxl01780 Changed to use spacecraft ancillary data to recognise when the mirror encoder data is being set by side A or side B and to change calculations accordingly This removes the need for seperate LUTs for Side A and Side B data it makes the new LUTs incompatible with older versions of the and vice versa Also resolves MODxl01685 A more robust GRing algorithm is being which will create a non default GRing anytime there s even a single geolocated pixel in a granule Removed obsolete messages from seed file
int bindex_get(int32_t wave)
double * get_fpm_xcal(char *fpm_file)
subroutine lonlat(alon, alat, xlon, ylat)
oli_t * createPrivateData(int numBands)
char * strdup(const char *)
void freePrivateData(oli_t *data)
no change in intended resolving MODur00064 Corrected handling of bad ephemeris attitude data
int readl1_oli(filehandle *file, int recnum, l1str *l1rec, int lonlat)
void ymdhms2ydmsec(int yy, int mm, int dd, int hh, int mn, int sc, int32_t *year, int32_t *day, int32_t *msec)
file_format chk_oli_geo(char *filename)
real *8 function esdist(iyr, iday, msec)
int32_t rdsensorinfo(int32_t, int32_t, const char *, void **)
for(i=0;i< NROOTS;i++) s[i]
int closel1_oli(filehandle *file)
int readNextLine(FILE *fp, char *tag, int *i, char *val)
How many dimensions is the output array Default is Not sure if anything above will work correctly strcpy(l2prod->title, "no title yet")