Go to the documentation of this file.
11 #include <geo_normalize.h>
16 static const int itemSize = 500;
33 l5tm_t*
data = (l5tm_t*)calloc(1,
sizeof(l5tm_t));
35 fprintf(
stderr,
"-E- %s line %d: unable to allocate private data for L5TM\n",
40 data->scale = (
double *) malloc(numBands*
sizeof(
double) );
41 data->offset = (
double *) malloc(numBands*
sizeof(
double) );
43 fprintf(
stderr,
"-E- %s line %d: unable to allocate scale/offset data for L5TM\n",
56 data->tif = (TIFF**) calloc(numBands,
sizeof(TIFF*) );
58 fprintf(
stderr,
"-E- %s line %d: unable to allocate TIFF pointers for L5TM\n",
63 data->defn = (GTIFDefn*) malloc(
sizeof(GTIFDefn) );
65 fprintf(
stderr,
"-E- %s line %d: unable to allocate GEOTIFF definition structure for L5TM\n",
90 fprintf(
stderr,
"-E- %s line %d: unable to read all of the required metadata from L5TM file\n",
106 result = strrchr(tag,
'_');
127 static int firstCall = 1;
131 int xid, yid, varID=-1;
132 size_t geo_npix, geo_nscan;
139 printf(
"Reading path angles from %s.\n",
file);
143 if (retval != NC_NOERR) {
144 fprintf(
stderr,
"-E- %s line %d: nc_open(%s) failed.\n",
145 __FILE__, __LINE__,
file);
150 retval = nc_inq_dimid(
fileID,
"Pixels", &xid);
151 retval = nc_inq_dimid(
fileID,
"Lines" , &yid);
152 retval = nc_inq_dimlen(
fileID, xid, &geo_npix);
153 retval = nc_inq_dimlen(
fileID, yid, &geo_nscan);
155 if (retval != NC_NOERR) {
156 fprintf(
stderr,
"-E- %s line %d: Error reading dimensions from %s.\n",
157 __FILE__, __LINE__,
file);
160 if (geo_npix !=
npix || geo_nscan !=
nscan) {
161 fprintf(
stderr,
"-E- %s line %d: geofile dimensions (%zu,%zu) do not match image dimensions (%d,%d).\n",
162 __FILE__, __LINE__, geo_npix,geo_nscan,
npix,
nscan);
173 retval = nc_inq_varid(
fileID,
"solz", &varID);
174 if (retval == NC_NOERR)
176 if (retval != NC_NOERR) {
178 "-E- %s line %d: Unable to read solz from %s.\n",
179 __FILE__, __LINE__,
file);
183 retval = nc_inq_varid(
fileID,
"sola", &varID);
184 if (retval == NC_NOERR)
186 if (retval != NC_NOERR) {
188 "-E- %s line %d: Unable to read sola from %s.\n",
189 __FILE__, __LINE__,
file);
193 retval = nc_inq_varid(
fileID,
"senz", &varID);
194 if (retval == NC_NOERR)
196 if (retval != NC_NOERR) {
198 "-E- %s line %d: Unable to read senz from %s.\n",
199 __FILE__, __LINE__,
file);
203 retval = nc_inq_varid(
fileID,
"sena", &varID);
204 if (retval == NC_NOERR)
206 if (retval != NC_NOERR) {
208 "-E- %s line %d: Unable to read sena from %s.\n",
209 __FILE__, __LINE__,
file);
224 char fileName[itemSize];
229 printf(
"L5TM Level-1B %s\n",
file->name );
232 if ((fp = fopen(
file->name,
"r")) ==
NULL) {
233 fprintf(
stderr,
"-E- %s line %d: unable open %s\n",
234 __FILE__,__LINE__,
file->name);
241 int numLinesNeeded = 1;
242 int numSamplesNeeded = 1;
243 int sunAzimuthNeeded = 1;
244 int sunElevationNeeded = 1;
246 int offsetNeeded = 1;
257 sunElevationNeeded ||
270 if(!strcmp(tag,
"DATE_ACQUIRED")) {
275 }
else if(!strcmp(tag,
"SCENE_CENTER_TIME")) {
280 }
else if(!strcmp(tag,
"REFLECTIVE_LINES")) {
285 }
else if(!strcmp(tag,
"REFLECTIVE_SAMPLES")) {
286 numSamplesNeeded = 0;
291 }
else if(!strncmp(tag,
"FILE_NAME_BAND_", 15)) {
297 char dir[FILENAME_MAX];
299 strcpy(fileName, dirname(dir));
300 strcat(fileName,
"/");
301 strcat(fileName,
val);
303 printf(
"L5TM Level-1B Band[%d]:%s\n",
i, fileName );
304 data->tif[
i] = XTIFFOpen(fileName,
"r");
306 fprintf(
stderr,
"-E- %s line %d: unable open TIFF file %s\n",
307 __FILE__,__LINE__,fileName);
313 }
else if(!strcmp(tag,
"SUN_AZIMUTH")) {
314 sunAzimuthNeeded = 0;
318 }
else if(!strcmp(tag,
"SUN_ELEVATION")) {
319 sunElevationNeeded = 0;
320 data->sunElevation = atof(
val);
342 else if(!strncmp(tag,
"RADIANCE_MULT_BAND_", 19)) {
351 }
else if(!strncmp(tag,
"RADIANCE_ADD_BAND_", 18)) {
365 data->lat = (
double *) malloc(
file->npix*
sizeof(
double) );
366 data->lon = (
double *) malloc(
file->npix*
sizeof(
double) );
368 fprintf(
stderr,
"-E- %s line %d: unable to allocate lat/lon data for L5TM\n",
376 fprintf(
stderr,
"-E- %s line %d: unable open GEOTIFF file %s\n",
377 __FILE__,__LINE__,fileName);
381 if(!GTIFGetDefn(
data->gtif,
data->defn)) {
382 fprintf(
stderr,
"-E- %s line %d: unable populate GEOTIFF defn structure for %s\n",
383 __FILE__,__LINE__,fileName);
388 int size = TIFFScanlineSize(
data->tif[0]);
391 fprintf(
stderr,
"-E- %s line %d: unexpected pixel data size in %s\n",
392 __FILE__,__LINE__,fileName);
395 data->buf = (uint8_t*) malloc(
size);
399 sscanf(dateStr,
"%d-%d-%d", &
year, &month, &
day);
404 sscanf(timeStr,
"%d:%d:%lf", &hour, &minute, &sec);
410 data->msec += sec * 1000;
413 printf(
"L5TM Start Time: %4d-%02d-%02d %03d %02d:%02d:%f\n",
416 printf(
"L5TM file has %d bands, %d samples, %d lines\n",
426 l5tm_t*
data = (l5tm_t*)
file->private_data;
430 l1rec->l1file->sensorID =
file->sensorID;
432 (
double) (
data->msec / 1000.0 ));
435 for (ip=0; ip<
file->npix; ip++) {
442 fprintf(
stderr,
"-E- %s line %d: unable reproject points for scan %d\n",
443 __FILE__,__LINE__,
recnum);
447 for (ip=0; ip<
file->npix; ip++) {
449 l1rec->pixnum[ip] = ip;
451 if ( isnan(
data->lat[ip]) )
452 data->lat[ip] = -999.0;
453 if ( isnan(
data->lon[ip]) )
454 data->lon[ip] = -999.0;
460 if (
l1rec->lon[ip] < -181.0 ||
l1rec->lon[ip] > 181.0 ||
461 l1rec->lat[ip] < -91.0 ||
l1rec->lat[ip] > 91.0 )
463 l1rec->navfail[ip] = 1;
464 printf(
"ERROR: lat = %f, lon = %f\n",
l1rec->lat[ip],
l1rec->lon[ip]);
478 fprintf(
stderr,
"-E- %s line %d: missing or incompatible geofile\n",
501 for(ib = 0; ib <
file->nbands; ib++)
507 if(TIFFReadScanline(
data->tif[ib+1], (
void*)
data->buf,
recnum, 0) == -1) {
508 fprintf(
stderr,
"-E- %s line %d: Failed to read Lt, band %d, recnum %d\n",
509 __FILE__,__LINE__, ib,
recnum );
515 if(TIFFReadScanline(
data->tif[ib], (
void*)
data->buf,
recnum, 0) == -1) {
516 fprintf(
stderr,
"-E- %s line %d: Failed to read Lt, band %d, recnum %d\n",
517 __FILE__,__LINE__, ib,
recnum );
522 for (ip=0; ip<
file->npix; ip++) {
523 ipb = ip*
file->nbands+ib;
524 if(
data->buf[ip] == 0) {
526 l1rec->navfail[ip] = 1;
532 l1rec->Lt[ipb] = (
data->buf[ip] *
data->scale[ib+1] +
data->offset[ib+1]) / 10.0;
570 l5tm_t*
data = (l5tm_t*)
file->private_data;
580 GTIFFree(
data->gtif);
583 for(ib=0; ib<
file->nbands; ib++) {
584 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)
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)
no change in intended resolving MODur00064 Corrected handling of bad ephemeris attitude data
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)
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)