Go to the documentation of this file.
11 #include <geo_normalize.h>
22 static const int itemSize = 500;
39 l5tm_t*
data = (l5tm_t*)calloc(1,
sizeof(l5tm_t));
41 fprintf(
stderr,
"-E- %s line %d: unable to allocate private data for L5TM\n",
46 data->scale = (
double *) malloc(numBands*
sizeof(
double) );
47 data->offset = (
double *) malloc(numBands*
sizeof(
double) );
49 fprintf(
stderr,
"-E- %s line %d: unable to allocate scale/offset data for L5TM\n",
62 data->tif = (TIFF**) calloc(numBands,
sizeof(TIFF*) );
64 fprintf(
stderr,
"-E- %s line %d: unable to allocate TIFF pointers for L5TM\n",
69 data->defn = (GTIFDefn*) malloc(
sizeof(GTIFDefn) );
71 fprintf(
stderr,
"-E- %s line %d: unable to allocate GEOTIFF definition structure for L5TM\n",
96 fprintf(
stderr,
"-E- %s line %d: unable to read all of the required metadata from L5TM file\n",
112 result = strrchr(tag,
'_');
133 static int firstCall = 1;
137 int xid, yid, varID=-1;
138 size_t geo_npix, geo_nscan;
145 printf(
"Reading path angles from %s.\n",
file);
149 if (retval != NC_NOERR) {
150 fprintf(
stderr,
"-E- %s line %d: nc_open(%s) failed.\n",
151 __FILE__, __LINE__,
file);
156 retval = nc_inq_dimid(
fileID,
"Pixels", &xid);
157 retval = nc_inq_dimid(
fileID,
"Lines" , &yid);
158 retval = nc_inq_dimlen(
fileID, xid, &geo_npix);
159 retval = nc_inq_dimlen(
fileID, yid, &geo_nscan);
161 if (retval != NC_NOERR) {
162 fprintf(
stderr,
"-E- %s line %d: Error reading dimensions from %s.\n",
163 __FILE__, __LINE__,
file);
166 if (geo_npix !=
npix || geo_nscan !=
nscan) {
167 fprintf(
stderr,
"-E- %s line %d: geofile dimensions (%zu,%zu) do not match image dimensions (%d,%d).\n",
168 __FILE__, __LINE__, geo_npix,geo_nscan,
npix,
nscan);
179 retval = nc_inq_varid(
fileID,
"solz", &varID);
180 if (retval == NC_NOERR)
182 if (retval != NC_NOERR) {
184 "-E- %s line %d: Unable to read solz from %s.\n",
185 __FILE__, __LINE__,
file);
189 retval = nc_inq_varid(
fileID,
"sola", &varID);
190 if (retval == NC_NOERR)
192 if (retval != NC_NOERR) {
194 "-E- %s line %d: Unable to read sola from %s.\n",
195 __FILE__, __LINE__,
file);
199 retval = nc_inq_varid(
fileID,
"senz", &varID);
200 if (retval == NC_NOERR)
202 if (retval != NC_NOERR) {
204 "-E- %s line %d: Unable to read senz from %s.\n",
205 __FILE__, __LINE__,
file);
209 retval = nc_inq_varid(
fileID,
"sena", &varID);
210 if (retval == NC_NOERR)
212 if (retval != NC_NOERR) {
214 "-E- %s line %d: Unable to read sena from %s.\n",
215 __FILE__, __LINE__,
file);
230 char fileName[itemSize];
235 printf(
"L5TM Level-1B %s\n",
file->name );
238 if ((fp = fopen(
file->name,
"r")) ==
NULL) {
239 fprintf(
stderr,
"-E- %s line %d: unable open %s\n",
240 __FILE__,__LINE__,
file->name);
247 int numLinesNeeded = 1;
248 int numSamplesNeeded = 1;
249 int sunAzimuthNeeded = 1;
250 int sunElevationNeeded = 1;
252 int offsetNeeded = 1;
263 sunElevationNeeded ||
276 if(!strcmp(tag,
"DATE_ACQUIRED")) {
281 }
else if(!strcmp(tag,
"SCENE_CENTER_TIME")) {
286 }
else if(!strcmp(tag,
"REFLECTIVE_LINES")) {
291 }
else if(!strcmp(tag,
"REFLECTIVE_SAMPLES")) {
292 numSamplesNeeded = 0;
297 }
else if(!strncmp(tag,
"FILE_NAME_BAND_", 15)) {
303 char dir[FILENAME_MAX];
305 strcpy(fileName, dirname(dir));
306 strcat(fileName,
"/");
307 strcat(fileName,
val);
309 printf(
"L5TM Level-1B Band[%d]:%s\n",
i, fileName );
310 data->tif[
i] = XTIFFOpen(fileName,
"r");
312 fprintf(
stderr,
"-E- %s line %d: unable open TIFF file %s\n",
313 __FILE__,__LINE__,fileName);
319 }
else if(!strcmp(tag,
"SUN_AZIMUTH")) {
320 sunAzimuthNeeded = 0;
324 }
else if(!strcmp(tag,
"SUN_ELEVATION")) {
325 sunElevationNeeded = 0;
326 data->sunElevation = atof(
val);
348 else if(!strncmp(tag,
"RADIANCE_MULT_BAND_", 19)) {
357 }
else if(!strncmp(tag,
"RADIANCE_ADD_BAND_", 18)) {
371 data->lat = (
double *) malloc(
file->npix*
sizeof(
double) );
372 data->lon = (
double *) malloc(
file->npix*
sizeof(
double) );
374 fprintf(
stderr,
"-E- %s line %d: unable to allocate lat/lon data for L5TM\n",
382 fprintf(
stderr,
"-E- %s line %d: unable open GEOTIFF file %s\n",
383 __FILE__,__LINE__,fileName);
387 if(!GTIFGetDefn(
data->gtif,
data->defn)) {
388 fprintf(
stderr,
"-E- %s line %d: unable populate GEOTIFF defn structure for %s\n",
389 __FILE__,__LINE__,fileName);
394 int size = TIFFScanlineSize(
data->tif[0]);
397 fprintf(
stderr,
"-E- %s line %d: unexpected pixel data size in %s\n",
398 __FILE__,__LINE__,fileName);
401 data->buf = (uint8_t*) malloc(
size);
404 int year, month,
day;
405 sscanf(dateStr,
"%d-%d-%d", &year, &month, &
day);
410 sscanf(timeStr,
"%d:%d:%lf", &hour, &minute, &sec);
416 data->msec += sec * 1000;
419 printf(
"L5TM Start Time: %4d-%02d-%02d %03d %02d:%02d:%f\n",
420 year, month,
day,
data->doy, hour, minute, sec);
422 printf(
"L5TM file has %d bands, %d samples, %d lines\n",
432 l5tm_t*
data = (l5tm_t*)
file->private_data;
436 l1rec->l1file->sensorID =
file->sensorID;
438 (
double) (
data->msec / 1000.0 ));
441 for (ip=0; ip<
file->npix; 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;
466 if (
l1rec->lon[ip] < -181.0 ||
l1rec->lon[ip] > 181.0 ||
467 l1rec->lat[ip] < -91.0 ||
l1rec->lat[ip] > 91.0 )
469 l1rec->navfail[ip] = 1;
470 printf(
"ERROR: lat = %f, lon = %f\n",
l1rec->lat[ip],
l1rec->lon[ip]);
481 fprintf(
stderr,
"-E- %s line %d: missing or incompatible geofile\n",
508 for(ib = 0; ib <
file->nbands; ib++)
514 if(TIFFReadScanline(
data->tif[ib+1], (
void*)
data->buf,
recnum, 0) == -1) {
515 fprintf(
stderr,
"-E- %s line %d: Failed to read Lt, band %d, recnum %d\n",
516 __FILE__,__LINE__, ib,
recnum );
522 if(TIFFReadScanline(
data->tif[ib], (
void*)
data->buf,
recnum, 0) == -1) {
523 fprintf(
stderr,
"-E- %s line %d: Failed to read Lt, band %d, recnum %d\n",
524 __FILE__,__LINE__, ib,
recnum );
529 for (ip=0; ip<
file->npix; ip++) {
530 ipb = ip*
file->nbands+ib;
531 if(
data->buf[ip] == 0) {
533 l1rec->navfail[ip] = 1;
539 l1rec->Lt[ipb] = (
data->buf[ip] *
data->scale[ib+1] +
data->offset[ib+1]) / 10.0;
577 l5tm_t*
data = (l5tm_t*)
file->private_data;
587 GTIFFree(
data->gtif);
590 for(ib=0; ib<
file->nbands; ib++) {
591 XTIFFClose(
data->tif[ib]);
void freePrivateData_l5tm(l5tm_t *data)
double yds2unix(int16_t year, int16_t day, double secs)
void readNextLine_l5tm(FILE *fp, char *tag, int *i, char *val)
int closel1_l5tm(filehandle *file)
void trimBlanks(char *str)
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
subroutine lonlat(alon, alat, xlon, ylat)
int read_l5tm_angles(char *file, int32_t npix, int32_t nscan, int32_t iscan, float *solz, float *sola, float *senz, float *sena)
no change in intended resolving MODur00064 Corrected handling of bad ephemeris attitude data
int32_t chk_l5tm_geo(char *fname)
int readl1_l5tm(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)
int get_l5tm_angles(char *emeta_filename, int32_t npix, int32_t nscan, int32_t iscan, float *solz, float *sola, float *senz, float *sena)
int get_l57tm_nom_angles(char *meta_filename, int32_t npix, int32_t nscan, int32_t iscan, float *solz, float *sola, float *senz, float *sena)
l5tm_t * createPrivateData_l5tm(int numBands)
How many dimensions is the output array Default is Not sure if anything above will work correctly strcpy(l2prod->title, "no title yet")
int openl1_l5tm(filehandle *file)