Go to the documentation of this file.
10 #include <geo_normalize.h>
18 static const int itemSize = 500;
20 static const int maxReflBands = 7;
36 l7etm_t*
data = (l7etm_t*)calloc(1,
sizeof(l7etm_t));
38 fprintf(
stderr,
"-E- %s line %d: unable to allocate private data for l7etm\n",
43 data->scale = (
double *) malloc(numBands*
sizeof(
double) );
44 data->offset = (
double *) malloc(numBands*
sizeof(
double) );
46 fprintf(
stderr,
"-E- %s line %d: unable to allocate scale/offset data for L7ETM\n",
51 data->refl_scale = (
double *) malloc(numBands*
sizeof(
double) );
52 data->refl_offset = (
double *) malloc(numBands*
sizeof(
double) );
54 fprintf(
stderr,
"-E- %s line %d: unable to allocate reflectance scale/offset data for L7ETM\n",
59 data->tif = (TIFF**) calloc(numBands,
sizeof(TIFF*) );
61 fprintf(
stderr,
"-E- %s line %d: unable to allocate TIFF pointers for L7ETM\n",
66 data->defn = (GTIFDefn*) malloc(
sizeof(GTIFDefn) );
68 fprintf(
stderr,
"-E- %s line %d: unable to allocate GEOTIFF definition structure for L7ETM\n",
79 free(
data->refl_scale);
80 free(
data->refl_offset);
93 fprintf(
stderr,
"-E- %s line %d: unable to read all of the required metadata from L7ETM file\n",
109 result = strrchr(tag,
'_');
133 char fileName[itemSize];
138 printf(
"L7ETM Level-1B %s\n",
file->name );
141 if ((fp = fopen(
file->name,
"r")) ==
NULL) {
142 fprintf(
stderr,
"-E- %s line %d: unable open %s\n",
143 __FILE__,__LINE__,
file->name);
150 int numLinesNeeded = 1;
151 int numSamplesNeeded = 1;
152 int sunAzimuthNeeded = 1;
153 int sunElevationNeeded = 1;
155 int offsetNeeded = 1;
166 sunElevationNeeded ||
179 if(!strcmp(tag,
"DATE_ACQUIRED")) {
184 }
else if(!strcmp(tag,
"SCENE_CENTER_TIME")) {
189 }
else if(!strcmp(tag,
"REFLECTIVE_LINES")) {
194 }
else if(!strcmp(tag,
"REFLECTIVE_SAMPLES")) {
195 numSamplesNeeded = 0;
200 }
else if(!strncmp(tag,
"FILE_NAME_BAND_", 15)) {
206 if (!strncmp(tag,
"FILE_NAME_BAND_6_VCID_2", 23))
209 if (!strncmp(tag,
"FILE_NAME_BAND_6_VCID_1", 23))
212 char dir[FILENAME_MAX];
214 strcpy(fileName, dirname(dir));
215 strcat(fileName,
"/");
216 strcat(fileName,
val);
218 printf(
"L7ETM Level-1B Band[%d]:%s\n\n",
i, fileName );
219 data->tif[
i] = XTIFFOpen(fileName,
"r");
221 fprintf(
stderr,
"-E- %s line %d: unable open TIFF file %s\n",
222 __FILE__,__LINE__,fileName);
228 }
else if(!strcmp(tag,
"SUN_AZIMUTH")) {
229 sunAzimuthNeeded = 0;
233 }
else if(!strcmp(tag,
"SUN_ELEVATION")) {
234 sunElevationNeeded = 0;
235 data->sunElevation = atof(
val);
238 else if(!strncmp(tag,
"REFLECTANCE_MULT_BAND_", 22)) {
242 if(
i>=0 &&
i<maxReflBands) {
247 }
else if(!strncmp(tag,
"REFLECTANCE_ADD_BAND_", 21)) {
251 if(
i>=0 &&
i<maxReflBands) {
257 else if(!strncmp(tag,
"RADIANCE_MULT_BAND_", 19)) {
266 }
else if(!strncmp(tag,
"RADIANCE_ADD_BAND_", 18)) {
280 data->lat = (
double *) malloc(
file->npix*
sizeof(
double) );
281 data->lon = (
double *) malloc(
file->npix*
sizeof(
double) );
283 fprintf(
stderr,
"-E- %s line %d: unable to allocate lat/lon data for L7ETM\n",
291 fprintf(
stderr,
"-E- %s line %d: unable open GEOTIFF file %s\n",
292 __FILE__,__LINE__,fileName);
296 if(!GTIFGetDefn(
data->gtif,
data->defn)) {
297 fprintf(
stderr,
"-E- %s line %d: unable populate GEOTIFF defn structure for %s\n",
298 __FILE__,__LINE__,fileName);
303 int size = TIFFScanlineSize(
data->tif[0]);
306 fprintf(
stderr,
"-E- %s line %d: unexpected pixel data size in %s\n",
307 __FILE__,__LINE__,fileName);
310 data->buf = (uint8_t*) malloc(
size);
313 int year, month,
day;
314 sscanf(dateStr,
"%d-%d-%d", &year, &month, &
day);
319 sscanf(timeStr,
"%d:%d:%lf", &hour, &minute, &sec);
325 data->msec += sec * 1000;
328 printf(
"L7ETM Start Time: %4d-%02d-%02d %03d %02d:%02d:%f\n",
329 year, month,
day,
data->doy, hour, minute, sec);
331 printf(
"L7ETM file has %d bands, %d samples, %d lines\n",
341 l7etm_t*
data = (l7etm_t*)
file->private_data;
345 l1rec->l1file->sensorID =
file->sensorID;
347 (
double) (
data->msec / 1000.0 ));
350 for (ip=0; ip<
file->npix; ip++) {
357 fprintf(
stderr,
"-E- %s line %d: unable reproject points for scan %d\n",
358 __FILE__,__LINE__,
recnum);
362 for (ip=0; ip<
file->npix; ip++) {
364 l1rec->pixnum[ip] = ip;
366 if ( isnan(
data->lat[ip]) )
367 data->lat[ip] = -999.0;
368 if ( isnan(
data->lon[ip]) )
369 data->lon[ip] = -999.0;
375 if (
l1rec->lon[ip] < -181.0 ||
l1rec->lon[ip] > 181.0 ||
376 l1rec->lat[ip] < -91.0 ||
l1rec->lat[ip] > 91.0 )
378 l1rec->navfail[ip] = 1;
379 printf(
"ERROR: lat = %f, lon = %f\n",
l1rec->lat[ip],
l1rec->lon[ip]);
386 fprintf(
stderr,
"-E- %s line %d: missing or incompatible geofile\n",
395 for(ib = 0; ib <
file->nbands; ib++)
401 if(TIFFReadScanline(
data->tif[ib+1], (
void*)
data->buf,
recnum, 0) == -1) {
402 fprintf(
stderr,
"-E- %s line %d: Failed to read Lt, band %d, recnum %d\n",
403 __FILE__,__LINE__, ib,
recnum );
409 if(TIFFReadScanline(
data->tif[ib], (
void*)
data->buf,
recnum, 0) == -1) {
410 fprintf(
stderr,
"-E- %s line %d: Failed to read Lt, band %d, recnum %d\n",
411 __FILE__,__LINE__, ib,
recnum );
416 for (ip=0; ip<
file->npix; ip++) {
417 ipb = ip*
file->nbands+ib;
418 if(
data->buf[ip] == 0) {
420 l1rec->navfail[ip] = 1;
426 l1rec->Lt[ipb] = (
data->buf[ip] *
data->scale[ib+1] +
data->offset[ib+1]) / 10.0;
464 l7etm_t*
data = (l7etm_t*)
file->private_data;
474 GTIFFree(
data->gtif);
477 for(ib=0; ib<
file->nbands; ib++) {
478 XTIFFClose(
data->tif[ib]);
double yds2unix(int16_t year, int16_t day, double secs)
void trimBlanks(char *str)
l7etm_t * createPrivateData_l7etm(int numBands)
int openl1_l7etm(filehandle *file)
void freePrivateData_l7etm(l7etm_t *data)
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
void readNextLine_l7etm(FILE *fp, char *tag, int *i, char *val)
subroutine lonlat(alon, alat, xlon, ylat)
int readl1_l7etm(filehandle *file, int recnum, l1str *l1rec, int lonlat)
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)
int closel1_l7etm(filehandle *file)
no change in intended resolving MODur00064 Corrected handling of bad ephemeris attitude data
void ymdhms2ydmsec(int yy, int mm, int dd, int hh, int mn, int sc, int32_t *year, int32_t *day, int32_t *msec)
How many dimensions is the output array Default is Not sure if anything above will work correctly strcpy(l2prod->title, "no title yet")