|
@@ -35,6 +35,7 @@ static void date_replace_slash(char *str)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+/* OLD Metadata Files */
|
|
|
void get_metformat(const char metadata[], char *key, char value[])
|
|
|
{
|
|
|
int i = 0;
|
|
@@ -56,6 +57,17 @@ void get_metformat(const char metadata[], char *key, char value[])
|
|
|
value[i] = '\0';
|
|
|
}
|
|
|
|
|
|
+double get_metdouble(const char metadata[], char *format, int code, char value[])
|
|
|
+{
|
|
|
+ char key[MAX_STR];
|
|
|
+
|
|
|
+ sprintf(key, format, code);
|
|
|
+ get_metformat(metadata, key, value);
|
|
|
+ return atof(value);
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+/* NEW Metadata Files */
|
|
|
void get_mtlformat(const char metadata[], char *key, char value[])
|
|
|
{
|
|
|
int i = 0;
|
|
@@ -73,6 +85,16 @@ void get_mtlformat(const char metadata[], char *key, char value[])
|
|
|
value[i] = '\0';
|
|
|
}
|
|
|
|
|
|
+double get_mtldouble(const char metadata[], char *format, int code, char value[])
|
|
|
+{
|
|
|
+ char key[MAX_STR];
|
|
|
+
|
|
|
+ sprintf(key, format, code);
|
|
|
+ get_mtlformat(metadata, key, value);
|
|
|
+ return atof(value);
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
|
|
|
/****************************************************************************
|
|
|
* PURPOSE: Read parameters from Landsat metadata files
|
|
@@ -84,7 +106,9 @@ void lsat_metadata(char *metafile, lsat_data * lsat)
|
|
|
char mtldata[METADATA_SIZE];
|
|
|
char key[MAX_STR], value[MAX_STR];
|
|
|
void (*get_mtldata) (const char[], char *, char[]);
|
|
|
+ void (*get_mtlreal) (const char[], char *, int, char[]);
|
|
|
int i, j, ver_mtl;
|
|
|
+ double X2;
|
|
|
|
|
|
/* store metadata in ram */
|
|
|
if ((f = fopen(metafile, "r")) == NULL)
|
|
@@ -93,8 +117,17 @@ void lsat_metadata(char *metafile, lsat_data * lsat)
|
|
|
(void)fclose(f);
|
|
|
|
|
|
/* set version of the metadata file */
|
|
|
- get_mtldata =
|
|
|
- (strstr(mtldata, " VALUE ") != NULL) ? get_metformat : get_mtlformat;
|
|
|
+ /* get_mtldata = (strstr(mtldata, " VALUE ") != NULL) ? get_metformat : get_mtlformat; */
|
|
|
+ if (strstr(mtldata, " VALUE ") != NULL)
|
|
|
+ {
|
|
|
+ get_mtldata = get_metformat;
|
|
|
+ get_mtlreal = get_metdouble;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ get_mtldata = get_mtlformat;
|
|
|
+ get_mtlreal = get_mtldouble;
|
|
|
+ }
|
|
|
ver_mtl = (strstr(mtldata, "QCALMAX_BAND") != NULL) ? 0 : 1;
|
|
|
|
|
|
/* Fill with product metadata */
|
|
@@ -238,120 +271,93 @@ void lsat_metadata(char *metafile, lsat_data * lsat)
|
|
|
else {
|
|
|
G_verbose_message("Metada file is MTL file: new format");
|
|
|
/* Other possible values in the metadata file */
|
|
|
- get_mtldata(mtldata, "EARTH_SUN_DISTANCE", value); /* used after in calculus after */
|
|
|
+ get_mtldata(mtldata, "EARTH_SUN_DISTANCE", value); /* Necessary after */
|
|
|
if (value[0] != '\0')
|
|
|
lsat->dist_es = atof(value);
|
|
|
- /* ----- */
|
|
|
- char *fmt_radmu[] =
|
|
|
- { "RADIANCE_MULTIPLICATIVE_FACTOR_BAND%d",
|
|
|
- "RADIANCE_MULT_BAND_%d" };
|
|
|
- char *fmt_radad[] =
|
|
|
- { "RADIANCE_ADDITIVE_FACTOR_BAND%d", "RADIANCE_ADD_BAND_%d" };
|
|
|
- char *fmt_k1cte[] =
|
|
|
- { "K1_CONSTANT_BAND%d", "K1_CONSTANT_BAND_%d" };
|
|
|
- char *fmt_k2cte[] =
|
|
|
- { "K2_CONSTANT_BAND%d", "K2_CONSTANT_BAND_%d" };
|
|
|
- char *fmt_refmu[] =
|
|
|
- { "REFLECTANCE_MULTIPLICATIVE_FACTOR_BAND%d",
|
|
|
- "REFLECTANCE_MULT_BAND_%d" };
|
|
|
- char *fmt_refad[] =
|
|
|
- { "REFLECTANCE_ADDITIVE_FACTOR_BAND%d",
|
|
|
- "REFLECTANCE_ADD_BAND_%d" };
|
|
|
- /* --NASA-- LDCM sample file: mode = 0; LDCM-DFCB-004.pdf file: mode = 1 */
|
|
|
- int mode =
|
|
|
- (strstr(mtldata, "RADIANCE_MULTIPLICATIVE_FACTOR_BAND") !=
|
|
|
- NULL) ? 0 : 1;
|
|
|
- /* ----- */
|
|
|
- if (strstr(mtldata, "RADIANCE_MAXIMUM_BAND") != NULL) {
|
|
|
- G_verbose_message
|
|
|
- ("RADIANCE & QUANTIZE from data of the metadata file");
|
|
|
+ if (strstr(mtldata, "RADIANCE_MAXIMUM_BAND") != NULL)
|
|
|
+ {
|
|
|
+ G_verbose_message("RADIANCE & QUANTIZE from MIN_MAX_(RADIANCE|PIXEL_VALUE)");
|
|
|
for (i = 0; i < lsat->bands; i++) {
|
|
|
if (lsat->number == 7 && lsat->band[i].thermal) {
|
|
|
- sprintf(key, "RADIANCE_MAXIMUM_BAND_6_VCID_%d",
|
|
|
- lsat->band[i].code - 60);
|
|
|
+ sprintf(key, "RADIANCE_MAXIMUM_BAND_6_VCID_%d", lsat->band[i].code - 60);
|
|
|
get_mtldata(mtldata, key, value);
|
|
|
lsat->band[i].lmax = atof(value);
|
|
|
- sprintf(key, "RADIANCE_MINIMUM_BAND_6_VCID_%d",
|
|
|
- lsat->band[i].code - 60);
|
|
|
+ sprintf(key, "RADIANCE_MINIMUM_BAND_6_VCID_%d", lsat->band[i].code - 60);
|
|
|
get_mtldata(mtldata, key, value);
|
|
|
lsat->band[i].lmin = atof(value);
|
|
|
- sprintf(key, "QUANTIZE_CAL_MAX_BAND_6_VCID_%d",
|
|
|
- lsat->band[i].code - 60);
|
|
|
+ sprintf(key, "QUANTIZE_CAL_MAX_BAND_6_VCID_%d", lsat->band[i].code - 60);
|
|
|
get_mtldata(mtldata, key, value);
|
|
|
lsat->band[i].qcalmax = atof(value);
|
|
|
- sprintf(key, "QUANTIZE_CAL_MIN_BAND_6_VCID_%d",
|
|
|
- lsat->band[i].code - 60);
|
|
|
+ sprintf(key, "QUANTIZE_CAL_MIN_BAND_6_VCID_%d", lsat->band[i].code - 60);
|
|
|
get_mtldata(mtldata, key, value);
|
|
|
lsat->band[i].qcalmin = atof(value);
|
|
|
}
|
|
|
else {
|
|
|
- sprintf(key, "RADIANCE_MAXIMUM_BAND_%d",
|
|
|
- lsat->band[i].code);
|
|
|
+ sprintf(key, "RADIANCE_MAXIMUM_BAND_%d", lsat->band[i].code);
|
|
|
get_mtldata(mtldata, key, value);
|
|
|
lsat->band[i].lmax = atof(value);
|
|
|
- sprintf(key, "RADIANCE_MINIMUM_BAND_%d",
|
|
|
- lsat->band[i].code);
|
|
|
+ sprintf(key, "RADIANCE_MINIMUM_BAND_%d", lsat->band[i].code);
|
|
|
get_mtldata(mtldata, key, value);
|
|
|
lsat->band[i].lmin = atof(value);
|
|
|
- sprintf(key, "QUANTIZE_CAL_MAX_BAND_%d",
|
|
|
- lsat->band[i].code);
|
|
|
+ sprintf(key, "QUANTIZE_CAL_MAX_BAND_%d", lsat->band[i].code);
|
|
|
get_mtldata(mtldata, key, value);
|
|
|
lsat->band[i].qcalmax = atof(value);
|
|
|
- sprintf(key, "QUANTIZE_CAL_MIN_BAND_%d",
|
|
|
- lsat->band[i].code);
|
|
|
+ sprintf(key, "QUANTIZE_CAL_MIN_BAND_%d", lsat->band[i].code);
|
|
|
get_mtldata(mtldata, key, value);
|
|
|
lsat->band[i].qcalmin = atof(value);
|
|
|
}
|
|
|
/* other possible values of each band */
|
|
|
if (lsat->band[i].thermal) {
|
|
|
- sprintf(key, fmt_k1cte[mode], lsat->band[i].code);
|
|
|
+ sprintf(key, "K1_CONSTANT_BAND_%d", lsat->band[i].code);
|
|
|
get_mtldata(mtldata, key, value);
|
|
|
lsat->band[i].K1 = atof(value);
|
|
|
- sprintf(key, fmt_k2cte[mode], lsat->band[i].code);
|
|
|
+ sprintf(key, "K2_CONSTANT_BAND_%d", lsat->band[i].code);
|
|
|
get_mtldata(mtldata, key, value);
|
|
|
lsat->band[i].K2 = atof(value);
|
|
|
}
|
|
|
+ else if (lsat->number == 8)
|
|
|
+ {
|
|
|
+ /* ESUN from REFLECTANCE and RADIANCE ADD_BAND */
|
|
|
+ sprintf(key, "REFLECTANCE_MAXIMUM_BAND_%d", lsat->band[i].code);
|
|
|
+ get_mtldata(mtldata, key, value);
|
|
|
+ X2 = atof(value);
|
|
|
+ lsat->band[i].esun = (double)(PI * lsat->dist_es * lsat->dist_es * lsat->band[i].lmax) / X2;
|
|
|
+ }
|
|
|
}
|
|
|
+ if (lsat->number == 8)
|
|
|
+ G_warning("ESUN evaluated from REFLECTANCE_MAXIMUM_BAND");
|
|
|
}
|
|
|
else {
|
|
|
- G_verbose_message
|
|
|
- ("RADIANCE & QUANTIZE from radiometric rescaling group of the metadata file");
|
|
|
+ G_verbose_message("RADIANCE & QUANTIZE from RADIOMETRIC_RESCALING");
|
|
|
for (i = 0; i < lsat->bands; i++) {
|
|
|
- sprintf(key, fmt_radmu[mode], lsat->band[i].code);
|
|
|
+ sprintf(key, "RADIANCE_MULT_BAND_%d", lsat->band[i].code);
|
|
|
get_mtldata(mtldata, key, value);
|
|
|
lsat->band[i].gain = atof(value);
|
|
|
- sprintf(key, fmt_radad[mode], lsat->band[i].code);
|
|
|
+ sprintf(key, "RADIANCE_ADD_BAND_%d", lsat->band[i].code);
|
|
|
get_mtldata(mtldata, key, value);
|
|
|
lsat->band[i].bias = atof(value);
|
|
|
/* reversing to calculate the values of Lmin and Lmax ... */
|
|
|
- lsat->band[i].lmin =
|
|
|
- lsat->band[i].gain * lsat->band[i].qcalmin +
|
|
|
- lsat->band[i].bias;
|
|
|
- lsat->band[i].lmax =
|
|
|
- lsat->band[i].gain * lsat->band[i].qcalmax +
|
|
|
- lsat->band[i].bias;
|
|
|
+ lsat->band[i].lmin = lsat->band[i].gain * lsat->band[i].qcalmin + lsat->band[i].bias;
|
|
|
+ lsat->band[i].lmax = lsat->band[i].gain * lsat->band[i].qcalmax + lsat->band[i].bias;
|
|
|
/* ... qcalmax and qcalmin loaded in previous sensor_ function */
|
|
|
if (lsat->number == 8) {
|
|
|
if (lsat->band[i].thermal) {
|
|
|
- sprintf(key, fmt_k1cte[mode], lsat->band[i].code);
|
|
|
+ sprintf(key, "K1_CONSTANT_BAND_%d", lsat->band[i].code);
|
|
|
get_mtldata(mtldata, key, value);
|
|
|
lsat->band[i].K1 = atof(value);
|
|
|
- sprintf(key, fmt_k2cte[mode], lsat->band[i].code);
|
|
|
+ sprintf(key, "K2_CONSTANT_BAND_%d", lsat->band[i].code);
|
|
|
get_mtldata(mtldata, key, value);
|
|
|
lsat->band[i].K2 = atof(value);
|
|
|
}
|
|
|
else {
|
|
|
- sprintf(key, fmt_refmu[mode], lsat->band[i].code);
|
|
|
+ sprintf(key, "REFLECTANCE_MULT_BAND_%d", lsat->band[i].code);
|
|
|
get_mtldata(mtldata, key, value);
|
|
|
lsat->band[i].K1 = atof(value);
|
|
|
- sprintf(key, fmt_refad[mode], lsat->band[i].code);
|
|
|
+ sprintf(key, "REFLECTANCE_ADD_BAND_%d", lsat->band[i].code);
|
|
|
get_mtldata(mtldata, key, value);
|
|
|
- lsat->band[i].K2 = atof(value);
|
|
|
- /* ESUN evaluates from metadafa file */
|
|
|
- lsat->band[i].esun =
|
|
|
- (double)(PI * lsat->dist_es * lsat->dist_es *
|
|
|
- lsat->band[i].bias) /
|
|
|
- lsat->band[i].K2;
|
|
|
+ lsat->band[i].K2 = atof(value);
|
|
|
+ /* ESUN from REFLECTANCE_ADD_BAND */
|
|
|
+ lsat->band[i].esun = (double)(PI * lsat->dist_es * lsat->dist_es * lsat->band[i].bias) / lsat->band[i].K2;
|
|
|
/*
|
|
|
double esun1 = (double) (PI * lsat->dist_es * lsat->dist_es * lsat->band[i].bias) / lsat->band[i].K2;
|
|
|
double esun2 = (double) (PI * lsat->dist_es * lsat->dist_es * lsat->band[i].gain) / lsat->band[i].K1;
|
|
@@ -360,8 +366,7 @@ void lsat_metadata(char *metafile, lsat_data * lsat)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- G_warning
|
|
|
- ("ESUN evaluate from REFLECTANCE_ADDITIVE_FACTOR_BAND of the metadata file");
|
|
|
+ G_warning("ESUN evaluated from REFLECTANCE_ADDITIVE_FACTOR_BAND");
|
|
|
}
|
|
|
}
|
|
|
}
|