Go to the documentation of this file.
10 #include <geo_normalize.h>
15 static const int itemSize = 500;
17 static const int maxReflBands = 7;
33 l7etm_t*
data = (l7etm_t*)calloc(1,
sizeof(l7etm_t));
35 fprintf(
stderr,
"-E- %s line %d: unable to allocate private data for l7etm\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 L7ETM\n",
48 data->refl_scale = (
double *) malloc(numBands*
sizeof(
double) );
49 data->refl_offset = (
double *) malloc(numBands*
sizeof(
double) );
51 fprintf(
stderr,
"-E- %s line %d: unable to allocate reflectance scale/offset data for L7ETM\n",
56 data->tif = (TIFF**) calloc(numBands,
sizeof(TIFF*) );
58 fprintf(
stderr,
"-E- %s line %d: unable to allocate TIFF pointers for L7ETM\n",
63 data->defn = (GTIFDefn*) malloc(
sizeof(GTIFDefn) );
65 fprintf(
stderr,
"-E- %s line %d: unable to allocate GEOTIFF definition structure for L7ETM\n",
76 free(
data->refl_scale);
77 free(
data->refl_offset);
90 fprintf(
stderr,
"-E- %s line %d: unable to read all of the required metadata from L7ETM file\n",
106 result = strrchr(tag,
'_');
130 char fileName[itemSize];
135 printf(
"L7ETM Level-1B %s\n",
file->name );
138 if ((fp = fopen(
file->name,
"r")) ==
NULL) {
139 fprintf(
stderr,
"-E- %s line %d: unable open %s\n",
140 __FILE__,__LINE__,
file->name);
147 int numLinesNeeded = 1;
148 int numSamplesNeeded = 1;
149 int sunAzimuthNeeded = 1;
150 int sunElevationNeeded = 1;
152 int offsetNeeded = 1;
163 sunElevationNeeded ||
176 if(!strcmp(tag,
"DATE_ACQUIRED")) {
181 }
else if(!strcmp(tag,
"SCENE_CENTER_TIME")) {
186 }
else if(!strcmp(tag,
"REFLECTIVE_LINES")) {
191 }
else if(!strcmp(tag,
"REFLECTIVE_SAMPLES")) {
192 numSamplesNeeded = 0;
197 }
else if(!strncmp(tag,
"FILE_NAME_BAND_", 15)) {
203 if (!strncmp(tag,
"FILE_NAME_BAND_6_VCID_2", 23))
206 if (!strncmp(tag,
"FILE_NAME_BAND_6_VCID_1", 23))
209 char dir[FILENAME_MAX];
211 strcpy(fileName, dirname(dir));
212 strcat(fileName,
"/");
213 strcat(fileName,
val);
215 printf(
"L7ETM Level-1B Band[%d]:%s\n\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,
"SUN_AZIMUTH")) {
226 sunAzimuthNeeded = 0;
230 }
else if(!strcmp(tag,
"SUN_ELEVATION")) {
231 sunElevationNeeded = 0;
232 data->sunElevation = atof(
val);
235 else if(!strncmp(tag,
"REFLECTANCE_MULT_BAND_", 22)) {
239 if(
i>=0 &&
i<maxReflBands) {
244 }
else if(!strncmp(tag,
"REFLECTANCE_ADD_BAND_", 21)) {
248 if(
i>=0 &&
i<maxReflBands) {
254 else if(!strncmp(tag,
"RADIANCE_MULT_BAND_", 19)) {
263 }
else if(!strncmp(tag,
"RADIANCE_ADD_BAND_", 18)) {
277 data->lat = (
double *) malloc(
file->npix*
sizeof(
double) );
278 data->lon = (
double *) malloc(
file->npix*
sizeof(
double) );
280 fprintf(
stderr,
"-E- %s line %d: unable to allocate lat/lon data for L7ETM\n",
288 fprintf(
stderr,
"-E- %s line %d: unable open GEOTIFF file %s\n",
289 __FILE__,__LINE__,fileName);
293 if(!GTIFGetDefn(
data->gtif,
data->defn)) {
294 fprintf(
stderr,
"-E- %s line %d: unable populate GEOTIFF defn structure for %s\n",
295 __FILE__,__LINE__,fileName);
300 int size = TIFFScanlineSize(
data->tif[0]);
303 fprintf(
stderr,
"-E- %s line %d: unexpected pixel data size in %s\n",
304 __FILE__,__LINE__,fileName);
307 data->buf = (uint8_t*) malloc(
size);
311 sscanf(dateStr,
"%d-%d-%d", &
year, &month, &
day);
316 sscanf(timeStr,
"%d:%d:%lf", &hour, &minute, &sec);
322 data->msec += sec * 1000;
325 printf(
"L7ETM Start Time: %4d-%02d-%02d %03d %02d:%02d:%f\n",
328 printf(
"L7ETM file has %d bands, %d samples, %d lines\n",
338 l7etm_t*
data = (l7etm_t*)
file->private_data;
342 l1rec->l1file->sensorID =
file->sensorID;
344 (
double) (
data->msec / 1000.0 ));
347 for (ip=0; ip<
file->npix; ip++) {
354 fprintf(
stderr,
"-E- %s line %d: unable reproject points for scan %d\n",
355 __FILE__,__LINE__,
recnum);
359 for (ip=0; ip<
file->npix; ip++) {
361 l1rec->pixnum[ip] = ip;
363 if ( isnan(
data->lat[ip]) )
364 data->lat[ip] = -999.0;
365 if ( isnan(
data->lon[ip]) )
366 data->lon[ip] = -999.0;
372 if (
l1rec->lon[ip] < -181.0 ||
l1rec->lon[ip] > 181.0 ||
373 l1rec->lat[ip] < -91.0 ||
l1rec->lat[ip] > 91.0 )
375 l1rec->navfail[ip] = 1;
376 printf(
"ERROR: lat = %f, lon = %f\n",
l1rec->lat[ip],
l1rec->lon[ip]);
390 fprintf(
stderr,
"-E- %s line %d: missing or incompatible geofile\n",
398 for(ib = 0; ib <
file->nbands; ib++)
404 if(TIFFReadScanline(
data->tif[ib+1], (
void*)
data->buf,
recnum, 0) == -1) {
405 fprintf(
stderr,
"-E- %s line %d: Failed to read Lt, band %d, recnum %d\n",
406 __FILE__,__LINE__, ib,
recnum );
412 if(TIFFReadScanline(
data->tif[ib], (
void*)
data->buf,
recnum, 0) == -1) {
413 fprintf(
stderr,
"-E- %s line %d: Failed to read Lt, band %d, recnum %d\n",
414 __FILE__,__LINE__, ib,
recnum );
419 for (ip=0; ip<
file->npix; ip++) {
420 ipb = ip*
file->nbands+ib;
421 if(
data->buf[ip] == 0) {
423 l1rec->navfail[ip] = 1;
429 l1rec->Lt[ipb] = (
data->buf[ip] *
data->scale[ib+1] +
data->offset[ib+1]) / 10.0;
467 l7etm_t*
data = (l7etm_t*)
file->private_data;
477 GTIFFree(
data->gtif);
480 for(ib=0; ib<
file->nbands; ib++) {
481 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 closel1_l7etm(filehandle *file)
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
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")