Go to the documentation of this file.
10 #include <geo_normalize.h>
16 static const int itemSize = 500;
17 static const int maxReflBands = 9;
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 < maxReflBands) {
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);
216 data->tif[
i] = XTIFFOpen(fileName,
"r");
218 fprintf(
stderr,
"-E- %s line %d: unable open TIFF file %s\n",
219 __FILE__, __LINE__, fileName);
225 }
else if (!strcmp(tag,
"ANGLE_COEFFICIENT_FILE_NAME") || !strcmp(tag,
"FILE_NAME_ANGLE_COEFFICIENT")) {
227 if ((
file->geofile ==
NULL) || (
file->geofile[0] == 0)) {
229 char dir[FILENAME_MAX];
231 strcpy(fileName, dirname(dir));
232 strcat(fileName,
"/");
233 strcat(fileName,
val);
236 printf(
"OLI Level-1B Angle File:%s\n", fileName);
240 }
else if (!strcmp(tag,
"SUN_AZIMUTH")) {
245 }
else if (!strcmp(tag,
"SUN_ELEVATION")) {
246 sunElevationFound = 1;
247 data->sunElevation = atof(
val);
250 }
else if (!strncmp(tag,
"REFLECTANCE_MULT_BAND_", 22)) {
252 if (
i >= 0 &&
i < maxReflBands) {
257 }
else if (!strncmp(tag,
"REFLECTANCE_ADD_BAND_", 21)) {
259 if (
i >= 0 &&
i < maxReflBands) {
263 }
else if (!strncmp(tag,
"RADIANCE_MULT_BAND_", 19)) {
265 if (
i >= 0 &&
i < maxReflBands) {
270 }
else if (!strncmp(tag,
"RADIANCE_ADD_BAND_", 18)) {
272 if (
i >= 0 &&
i < maxReflBands) {
282 fprintf(
stderr,
"-E- %s line %d: Did not find DATE_ACQUIRED in %s\n",
283 __FILE__, __LINE__,
file->name);
287 fprintf(
stderr,
"-E- %s line %d: Did not find SCENE_CENTER_TIME in %s\n",
288 __FILE__, __LINE__,
file->name);
291 if (!numLinesFound) {
292 fprintf(
stderr,
"-E- %s line %d: Did not find REFLECTIVE_LINES in %s\n",
293 __FILE__, __LINE__,
file->name);
296 if (!numSamplesFound) {
297 fprintf(
stderr,
"-E- %s line %d: Did not find REFLECTIVE_SAMPLES in %s\n",
298 __FILE__, __LINE__,
file->name);
301 if (!sunAzimuthFound) {
302 fprintf(
stderr,
"-E- %s line %d: Did not find SUN_AZIMUTH in %s\n",
303 __FILE__, __LINE__,
file->name);
306 if (!sunElevationFound) {
307 fprintf(
stderr,
"-E- %s line %d: Did not find SUN_ELEVATION in %s\n",
308 __FILE__, __LINE__,
file->name);
311 if (collectionNumber > 0) {
312 if (!angleFileFound) {
313 fprintf(
stderr,
"-E- %s line %d: Did not find ANGLE_COEFFICIENT_FILE_NAME in %s\n",
314 __FILE__, __LINE__,
file->name);
318 for (
i = 0;
i < maxReflBands;
i++) {
320 fprintf(
stderr,
"-E- %s line %d: Did not find FILE_NAME_BAND_%d in %s\n",
321 __FILE__, __LINE__,
i + 1,
file->name);
325 fprintf(
stderr,
"-E- %s line %d: Did not find RADIANCE_MULT_BAND_%d in %s\n",
326 __FILE__, __LINE__,
i + 1,
file->name);
330 fprintf(
stderr,
"-E- %s line %d: Did not find RADIANCE_ADD_BAND_%d in %s\n",
331 __FILE__, __LINE__,
i + 1,
file->name);
335 fprintf(
stderr,
"-E- %s line %d: Did not find REFLECTANCE_MULT_BAND_%d in %s\n",
336 __FILE__, __LINE__,
i + 1,
file->name);
340 fprintf(
stderr,
"-E- %s line %d: Did not find REFLECTANCE_ADD_BAND_%d in %s\n",
341 __FILE__, __LINE__,
i + 1,
file->name);
347 data->lat = (
double *) malloc(
file->npix * sizeof (
double));
348 data->lon = (
double *) malloc(
file->npix * sizeof (
double));
350 fprintf(
stderr,
"-E- %s line %d: unable to allocate lat/lon data for OLI\n",
358 fprintf(
stderr,
"-E- %s line %d: unable open GEOTIFF file %s\n",
359 __FILE__, __LINE__, fileName);
363 if (!GTIFGetDefn(
data->gtif,
data->defn)) {
364 fprintf(
stderr,
"-E- %s line %d: unable populate GEOTIFF defn structure for %s\n",
365 __FILE__, __LINE__, fileName);
370 int size = TIFFScanlineSize(
data->tif[0]);
372 fprintf(
stderr,
"-E- %s line %d: unexpected pixel data size in %s\n",
373 __FILE__, __LINE__, fileName);
376 data->buf = (uint16_t*) malloc(
size);
379 tile_exist = TIFFGetField(
data->tif[0], TIFFTAG_TILELENGTH, &tileLength);
381 if (tile_exist != 0) {
382 TIFFGetField(
data->tif[0], TIFFTAG_TILEWIDTH, &tileWidth);
385 int size_tile_row = 9 * tileLength *
size;
386 data->buf_tile_row = (uint16_t*) malloc(size_tile_row);
391 sscanf(dateStr,
"%d-%d-%d", &
year, &month, &
day);
396 sscanf(timeStr,
"%d:%d:%lf", &hour, &minute, &sec);
398 int isec = (
int) sec;
402 data->msec += sec * 1000;
405 printf(
"OLI Start Time: %4d-%02d-%02d %03d %02d:%02d:%f\n",
406 year, month,
day,
data->doy, hour, minute, sec + isec);
408 printf(
"OLI file has %d bands, %d samples, %d lines\n",
412 file->terrain_corrected = 1;
423 oli_t*
data = (oli_t*)
file->private_data;
426 static short *sca_num;
427 static short *det_num;
429 static int firstCall = 1;
435 (
double) (
data->msec / 1000.0));
438 double fsol = pow(1.0 /
esdist, 2);
441 for (ip = 0; ip <
file->npix; ip++) {
444 GTIFImageToPCS(
data->gtif,
data->lon + ip,
data->lat + ip);
448 fprintf(
stderr,
"-E- %s line %d: unable reproject points for scan %d\n",
449 __FILE__, __LINE__,
recnum);
453 for (ip = 0; ip <
file->npix; ip++) {
455 l1rec->pixnum[ip] = ip;
457 if (isnan(
data->lat[ip]))
458 data->lat[ip] = -999.0;
459 if (isnan(
data->lon[ip]))
460 data->lon[ip] = -999.0;
464 if (
l1rec->lon[ip] < -181.0 ||
l1rec->lon[ip] > 181.0 ||
465 l1rec->lat[ip] < -91.0 ||
l1rec->lat[ip] > 91.0)
466 l1rec->navfail[ip] = 1;
487 for (iw = 0; iw <
l1_input->xcal_nwave; iw++)
499 if ((sca_num = (
short *) calloc(
file->npix *
file->nbands, sizeof (
short))) ==
NULL) {
501 "-E- %s line %d: Unable to allocate SCA number array.\n",
506 if ((det_num = (
short *) calloc(
file->npix *
file->nbands, sizeof (
short))) ==
NULL) {
509 "-E- %s line %d: Unable to allocate detector number array.\n",
521 fprintf(
stderr,
"-E- %s line %d: Unable to compute geometries\n",
530 l1rec->geom_per_band->solz,
l1rec->geom_per_band->sola,
531 l1rec->geom_per_band->senz,
l1rec->geom_per_band->sena,
532 sca_num, det_num,
l1_input->geom_per_band) == -1) {
533 fprintf(
stderr,
"-E- %s line %d: Unable to compute geometries\n",
540 printf(
"Exit get_oli_angles with error\n");
541 fprintf(
stderr,
"-E- %s line %d: geofile specified must be an Enhanced Meta-Data file (EMD format)\n",
548 printf(
"Exit get_oli_angles with error\n");
549 fprintf(
stderr,
"-E- %s line %d: Unable to compute geometries\n",
556 l1rec->geom_per_band->solz,
l1rec->geom_per_band->sola,
557 l1rec->geom_per_band->senz,
l1rec->geom_per_band->sena,
559 printf(
"Exit get_oli_angles with error\n");
560 fprintf(
stderr,
"-E- %s line %d: Unable to compute geometries\n",
570 if (tile_exist != 0) {
572 y_in_tile =
recnum % tileLength;
573 if (
data->line_num_cached == -1 || recnum < data->line_num_cached ||
recnum >= (
data->line_num_cached + tileLength)) {
575 data->line_num_cached =
y * tileLength;
576 for (ib = 0; ib <=
file->nbands; ib++) {
578 if (TIFFReadTile(
data->tif[ib], (
void*) (
data->buf_tile_row + ib *
imageWidth * tileLength +
x * tileLength),
x,
y * tileLength, 0, 0) == -1) {
579 fprintf(
stderr,
"-E- %s line %d: Failed to read Lt, band %d, recnum %d\n",
580 __FILE__, __LINE__, ib,
recnum);
588 for (ib = 0; ib <
file->nbands; ib++) {
590 if (tile_exist == 0) {
591 if (TIFFReadScanline(
data->tif[ib], (
void*)
data->buf,
recnum, 0) == -1) {
592 fprintf(
stderr,
"-E- %s line %d: Failed to read Lt, band %d, recnum %d\n",
593 __FILE__, __LINE__, ib,
recnum);
599 _TIFFmemcpy((
void*) (
data->buf +
x), (
void*) (
data->buf_tile_row + ib *
imageWidth * tileLength +
x * tileLength + y_in_tile * tileWidth), tileWidth * 2);
602 _TIFFmemcpy((
void*) (
data->buf +
x), (
void*) (
data->buf_tile_row + ib *
imageWidth * tileLength +
x * tileLength + y_in_tile * tileWidth), (
imageWidth -
x) * 2);
606 l1rec->Fo[ib] = Fobar[ib] * fsol;
608 for (ip = 0; ip <
file->npix; ip++) {
609 ipb = ip *
file->nbands + ib;
610 if (
data->buf[ip] == 0) {
612 l1rec->navwarn[ip] = 1;
619 isb = (sca_num[ipb] - 1) *
file->nbands + ib;
620 l1rec->Lt[ipb] *= xcal_factor[isb];
633 if (tile_exist == 0) {
634 if (TIFFReadScanline(
data->tif[ib], (
void*)
data->buf,
recnum, 0) == -1) {
635 fprintf(
stderr,
"-E- %s line %d: Failed to read Lt, band %d, recnum %d\n",
636 __FILE__, __LINE__, ib,
recnum);
642 _TIFFmemcpy((
void*) (
data->buf +
x), (
void*) (
data->buf_tile_row + ib *
imageWidth * tileLength +
x * tileLength + y_in_tile * tileWidth), tileWidth * 2);
645 _TIFFmemcpy((
void*) (
data->buf +
x), (
void*) (
data->buf_tile_row + ib *
imageWidth * tileLength +
x * tileLength + y_in_tile * tileWidth), (
imageWidth -
x) * 2);
649 for (ip = 0; ip <
file->npix; ip++) {
650 if (
data->buf[ip] == 0)
653 l1rec->rho_cirrus[ip] = (
data->buf[ip] *
data->refl_scale[ib] +
data->refl_offset[ib])
662 oli_t*
data = (oli_t*)
file->private_data;
672 if (tile_exist != 0) {
673 free(
data->buf_tile_row);
677 GTIFFree(
data->gtif);
680 for (ib = 0; ib <
file->nbands; ib++) {
681 XTIFFClose(
data->tif[ib]);
686 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")