[GRASS-SVN] r54844 - grass/branches/releasebranch_6_4/imagery/i.landsat.toar

svn_grass at osgeo.org svn_grass at osgeo.org
Sat Feb 2 10:37:42 PST 2013


Author: neteler
Date: 2013-02-02 10:37:42 -0800 (Sat, 02 Feb 2013)
New Revision: 54844

Modified:
   grass/branches/releasebranch_6_4/imagery/i.landsat.toar/description.html
   grass/branches/releasebranch_6_4/imagery/i.landsat.toar/landsat.h
   grass/branches/releasebranch_6_4/imagery/i.landsat.toar/landsat_met.c
   grass/branches/releasebranch_6_4/imagery/i.landsat.toar/landsat_set.c
   grass/branches/releasebranch_6_4/imagery/i.landsat.toar/local_proto.h
   grass/branches/releasebranch_6_4/imagery/i.landsat.toar/main.c
Log:
Jorge Tizado: better management of metadata file

Modified: grass/branches/releasebranch_6_4/imagery/i.landsat.toar/description.html
===================================================================
--- grass/branches/releasebranch_6_4/imagery/i.landsat.toar/description.html	2013-02-02 18:36:15 UTC (rev 54843)
+++ grass/branches/releasebranch_6_4/imagery/i.landsat.toar/description.html	2013-02-02 18:37:42 UTC (rev 54844)
@@ -15,7 +15,7 @@
 Optionally (recommended), the data can be read from metadata file (.met or MTL.txt) for all
 Landsat MSS, TM and ETM+. However, if the solar elevation or the
 product creation date are given the values of the metadata file are
-overwriten (only with .met files). This is necessary when the data in the .met file is
+overwriten. This is necessary when the data in the .met file is
 incorrect or not accurate.
 
 <p>

Modified: grass/branches/releasebranch_6_4/imagery/i.landsat.toar/landsat.h
===================================================================
--- grass/branches/releasebranch_6_4/imagery/i.landsat.toar/landsat.h	2013-02-02 18:36:15 UTC (rev 54843)
+++ grass/branches/releasebranch_6_4/imagery/i.landsat.toar/landsat.h	2013-02-02 18:37:42 UTC (rev 54844)
@@ -21,7 +21,7 @@
  * Esun in  W / (m^2 * µm)               -> Irradiance
  ****************************************************/
 
-#define MAX_BANDS   9
+#define MAX_BANDS   11
 
 typedef struct
 {
@@ -51,7 +51,7 @@
     double dist_es;		/* Distance Earth-Sun            */
     double sun_elev;		/* Solar elevation               */
 
-    char sensor[5];		/* Type of sensor: MSS, TM, ETM+ */
+    char sensor[10];		/* Type of sensor: MSS, TM, ETM+, OLI/TIRS */
     int bands;			/* Total number of bands         */
     band_data band[MAX_BANDS];	/* Data for each band            */
 } lsat_data;

Modified: grass/branches/releasebranch_6_4/imagery/i.landsat.toar/landsat_met.c
===================================================================
--- grass/branches/releasebranch_6_4/imagery/i.landsat.toar/landsat_met.c	2013-02-02 18:36:15 UTC (rev 54843)
+++ grass/branches/releasebranch_6_4/imagery/i.landsat.toar/landsat_met.c	2013-02-02 18:37:42 UTC (rev 54844)
@@ -16,175 +16,110 @@
 
 inline void chrncpy(char *dest, char src[], int n)
 {
-    if (src == NULL)
-    {
-        dest[0] = '\0';
-    }
-    else
-    {
-        int i;
-        for (i = 0; i < n && src[i] != '\0' && src[i] != '\"'; i++) dest[i] = src[i];
-        dest[i] = '\0';
-    }
+    int i;
+    for( i = 0 ; i < n && src[i] != '\0' && src[i] != '\"'; i++) dest[i] = src[i];
+    dest[i] = '\0';
 }
 
-
-/****************************************************************************
- * PURPOSE:     Read values of Landsat MSS/TM from header (.met) file
- *****************************************************************************/
-void get_metdata(const char mettext[], char *text, char value[])
+void get_oldformat( const char metadata[], char * key, char value[] )
 {
-    char *ptr;
-
-
-
-    ptr = strstr(mettext, text);
-    if (ptr == NULL)
+    int i = 0;
+    char * ptr = strstr(metadata, key);
+    if (ptr != NULL)
     {
-        value[0] = 0;
-        return;
+        ptr = strstr(ptr, " VALUE ");
+        if (ptr != NULL)
+        {
+            while (*ptr++ != '=') ;
+            while (*ptr <= ' ' || *ptr == '\"') *ptr++;
+            while (i < MAX_STR && *ptr != '\"' && *ptr >= ' ') value[i++] = *ptr++;
+        }
     }
-
-    ptr = strstr(ptr, " VALUE ");
-    if (ptr == NULL) return;
-
-    while (*ptr++ != '\"') ;
-    int i = 0;
-    while (*ptr != '\"' && i < MAX_STR) value[i++] = *ptr++;
     value[i] = '\0';
-
-    return;
 }
 
-void lsat_metdata(char *metfile, lsat_data * lsat)
+void get_newformat( const char metadata[], char * key, char value[] )
 {
-    FILE *f;
-    char mettext[TM5_MET_SIZE];
-    char name[MAX_STR], value[MAX_STR];
-
-    /* char metdate[MAX_STR]; */
-
-    if ((f = fopen(metfile, "r")) == NULL)
-    G_fatal_error(_("Metadata file <%s> not found"), metfile);
-
-    fread(mettext, TM5_MET_SIZE, 1, f);
-
-    /* --------------------------------------- */
-    get_metdata(mettext, "PLATFORMSHORTNAME", value);
-    chrncpy(name, value + 8, 1);
-    lsat->number = atoi(name);
-
-    get_metdata(mettext, "SENSORSHORTNAME", value);
-    chrncpy(lsat->sensor, value + 1, 4);
-
-    get_metdata(mettext, "CALENDARDATE", value);
-    chrncpy(lsat->date, value, 10);
-
-    if (lsat->creation[0] == 0)
+    int i = 0;
+    char * ptr = strstr(metadata, key);
+    if (ptr != NULL)
     {
-        get_metdata(mettext, "PRODUCTIONDATETIME", value);
-        if (!value[0])
-            G_fatal_error(_("Product creation date not in metadata file <%s>, input this data in the command line parameters"), metfile);
-        chrncpy(lsat->creation, value, 10);
+        while (*ptr++ != '=') ;
+        while (*ptr <= ' ' || *ptr == '\"') *ptr++;
+        while (i < MAX_STR && *ptr != '\"' && *ptr > ' ') value[i++] = *ptr++;
     }
-
-    if (lsat->sun_elev == 0)
-    {
-        get_metdata(mettext, "SolarElevation", value);
-        if (!value[0])
-           G_fatal_error(_("Unable to read solar elevation from metadata file in metadata file <%s>, input this data in the command line parameters"), metfile);
-        lsat->sun_elev = atof(value);
-    }
-
-    /* Fill data with the sensor_XXX functions */
-    switch(lsat->number)
-    {
-        case 1:
-            set_MSS1(lsat);
-            break;
-        case 2:
-            set_MSS2(lsat);
-            break;
-        case 3:
-            set_MSS3(lsat);
-            break;
-        case 4:
-            if (lsat->sensor[0] == 'M')
-                set_MSS4(lsat);
-            else
-                set_TM4(lsat);
-            break;
-        case 5:
-            if (lsat->sensor[0] == 'M')
-                set_MSS5(lsat);
-            else
-                set_TM5(lsat);
-            break;
-        default:
-            G_warning("Unable to recognize satellite platform [%d]", lsat->number);
-            break;
-    }
-
-    /* --------------------------------------- */
-    (void)fclose(f);
-    return;
+    value[i] = '\0';
 }
 
 
 /****************************************************************************
- * PURPOSE:     Read values of Landsat from MTL metadata (MTL.txt) file
+ * PURPOSE:     Read parameters from Landsat metadata files
  *****************************************************************************/
 
-void get_mtldata(const char mtltext[], char *text, char value[])
+void lsat_metadata( char * metafile, lsat_data * lsat)
 {
-    char *ptr;
-
-    ptr = strstr(mtltext, text);
-    if (ptr == NULL)
-    {
-        value[0] = '\0';
-        return;
-    }
-
-    while (*ptr++ != '=') ;
-    while (*ptr <= ' ' || *ptr == '\"') *ptr++;
-    int i = 0;
-    while (i < MAX_STR && *ptr != '\"' && *ptr > ' ') value[i++] = *ptr++;
-    value[i] = '\0';
-
-    return;
-}
-
-void lsat_mtldata(char *mtlfile, lsat_data * lsat)
-{
     FILE *f;
     char mtldata[METADATA_SIZE];
-    char name[MAX_STR], value[MAX_STR];
-    int i;
+    char key[MAX_STR], value[MAX_STR];
+    void (*get_mtldata)( const char [], char *, char [] );
+    int i, j, version;
 
-    if ((f = fopen(mtlfile, "r")) == NULL)
-       G_fatal_error(_("Metadata file <%s> not found"), mtlfile);
+    if ((f = fopen(metafile, "r")) == NULL)
+       G_fatal_error(_("Metadata file <%s> not found"), metafile);
 
-    fread(mtldata, METADATA_SIZE, 1, f);
-
-    /* --------------------------------------- */
+    i = fread(mtldata, METADATA_SIZE, 1, f);
+    get_mtldata = (strstr(mtldata, " VALUE ") != NULL) ? get_oldformat : get_newformat;
+    version = (strstr(mtldata, "QCALMAX_BAND") != NULL) ? 0 : 1;
+    
+    /* Fill with product metadata */
     get_mtldata(mtldata, "SPACECRAFT_ID", value);
-    chrncpy(name, value + 7, 1);
-    lsat->number = atoi(name);
+    if( value[0] == '\0' )
+    {
+        get_mtldata(mtldata, "PLATFORMSHORTNAME", value);
+    }
+    
+    i = 0; while( value[i] && (value[i] < '0' || value[i] > '9') ) i++;
+    lsat->number = atoi(value + i);
 
     get_mtldata(mtldata, "SENSOR_ID", value);
-    chrncpy(lsat->sensor, value, 4);
+    if( value[0] == '\0' )
+    {
+        get_mtldata(mtldata, "SENSORSHORTNAME", value);
+    }
+    chrncpy(lsat->sensor, value, 8);
 
-    get_mtldata(mtldata, "ACQUISITION_DATE", value);
+    get_mtldata(mtldata, "DATE_ACQUIRED", value);
+    if( value[0] == '\0' )
+    {
+        get_mtldata(mtldata, "ACQUISITION_DATE", value);
+        if( value[0] == '\0' )
+        {
+            get_mtldata(mtldata, "CALENDARDATE", value);
+        }
+    }
     chrncpy(lsat->date, value, 10);
 
-    get_mtldata(mtldata, "CREATION_TIME", value);
+    get_mtldata(mtldata, "FILE_DATE", value);
+    if( value[0] == '\0' )
+    {
+        get_mtldata(mtldata, "CREATION_TIME", value);
+        if( value[0] == '\0' )
+        {
+            get_mtldata(mtldata, "PRODUCTIONDATETIME", value);
+        }
+    }
     chrncpy(lsat->creation, value, 10);
 
     get_mtldata(mtldata, "SUN_ELEVATION", value);
+    if( value[0] == '\0' )
+    {
+        get_mtldata(mtldata, "SolarElevation", value);
+    }
     lsat->sun_elev = atof(value);
+    if( lsat->sun_elev == 0. )
+        G_warning("Sun elevation is %f", lsat->sun_elev);
 
-    /* Fill data with the sensor_XXX functions */
+    /* Fill data with the basic sensor parameters */
     switch(lsat->number)
     {
         case 1:
@@ -209,41 +144,54 @@
                 set_TM5(lsat);
             break;
         case 7:
-            get_mtldata(mtldata, "BAND1_GAIN",  value);
-            get_mtldata(mtldata, "BAND2_GAIN",  value + 1);
-            get_mtldata(mtldata, "BAND3_GAIN",  value + 2);
-            get_mtldata(mtldata, "BAND4_GAIN",  value + 3);
-            get_mtldata(mtldata, "BAND5_GAIN",  value + 4);
-            get_mtldata(mtldata, "BAND6_GAIN1", value + 5);
-            get_mtldata(mtldata, "BAND6_GAIN2", value + 6);
-            get_mtldata(mtldata, "BAND7_GAIN",  value + 7);
-            get_mtldata(mtldata, "BAND8_GAIN",  value + 8);
-            value[9] = '\0';
+        {
+            char * fmt_gain[] = { "BAND%d_GAIN%d ", " GAIN_BAND_%d_VCID_%d" };
+            for( i = 1, j = 0; i < 9; i++ )
+            {
+                sprintf(key, fmt_gain[version], i, 1);
+                if (i != 6) key[version == 0 ? 10 : 12] = '\0';
+                get_mtldata(mtldata, key,  value + j++);
+                if (i == 6)
+                {
+                    sprintf(key, fmt_gain[version], i, 2);
+                    get_mtldata(mtldata, key,  value + j++);
+                }
+            }
+            value[j] = '\0';
+            G_debug(1, "ETM+ gain = [%s]", value);
             set_ETM(lsat, value);
             break;
+        }
         default:
             G_warning("Unable to recognize satellite platform [%d]", lsat->number);
             break;
     }
 
-    /* Update the information from metadata file */
-    for (i = 0; i < lsat->bands; i++) {
-        snprintf(name, MAX_STR, "LMAX_BAND%d", lsat->band[i].code);
-        get_mtldata(mtldata, name, value);
-        lsat->band[i].lmax = atof(value);
-        snprintf(name, MAX_STR, "LMIN_BAND%d", lsat->band[i].code);
-        get_mtldata(mtldata, name, value);
-        lsat->band[i].lmin = atof(value);
-        snprintf(name, MAX_STR, "QCALMAX_BAND%d", lsat->band[i].code);
-        get_mtldata(mtldata, name, value);
-        lsat->band[i].qcalmax = atof(value);
-        snprintf(name, MAX_STR, "QCALMIN_BAND%d", lsat->band[i].code);
-        get_mtldata(mtldata, name, value);
-        lsat->band[i].qcalmin = atof(value);
+    /* Update the information from metadata file, if infile */
+//     if( format == NEW_FORMAT )
+    if( get_mtldata == get_newformat )
+    {
+        char * fmt_lmax[]     = { "LMAX_BAND%d",    "RADIANCE_MAXIMUM_BAND_%d" };
+        char * fmt_lmin[]     = { "LMIN_BAND%d",    "RADIANCE_MINIMUM_BAND_%d" };
+        char * fmt_qcalmax[]  = { "QCALMAX_BAND%d", "QUANTIZE_CAL_MAX_BAND_%d" };
+        char * fmt_qcalmin[]  = { "QCALMIN_BAND%d", "QUANTIZE_CAL_MIN_BAND_%d" };
+
+        for (i = 0; i < lsat->bands; i++) {
+            sprintf(key, fmt_lmax[version], lsat->band[i].code);
+            get_mtldata(mtldata, key, value);
+            lsat->band[i].lmax = atof(value);
+            sprintf(key, fmt_lmin[version], lsat->band[i].code);
+            get_mtldata(mtldata, key, value);
+            lsat->band[i].lmin = atof(value);
+            sprintf(key, fmt_qcalmax[version], lsat->band[i].code);
+            get_mtldata(mtldata, key, value);
+            lsat->band[i].qcalmax = atof(value);
+            sprintf(key, fmt_qcalmin[version], lsat->band[i].code);
+            get_mtldata(mtldata, key, value);
+            lsat->band[i].qcalmin = atof(value);
+        }
     }
-    /* --------------------------------------- */
 
     (void)fclose(f);
     return;
 }
-

Modified: grass/branches/releasebranch_6_4/imagery/i.landsat.toar/landsat_set.c
===================================================================
--- grass/branches/releasebranch_6_4/imagery/i.landsat.toar/landsat_set.c	2013-02-02 18:36:15 UTC (rev 54843)
+++ grass/branches/releasebranch_6_4/imagery/i.landsat.toar/landsat_set.c	2013-02-02 18:37:42 UTC (rev 54844)
@@ -16,9 +16,9 @@
     /* green, red, near infrared, near infrared */
     int band[] = { 1, 2, 3, 4 };
     int code[] = { 4, 5, 6, 7 };
+    double wmin[] = { 0.5, 0.6, 0.7, 0.8 };
     double wmax[] = { 0.6, 0.7, 0.8, 1.1 };
-    double wmin[] = { 0.5, 0.6, 0.7, 0.8 };
-    /* 68x83, 68x83, 68x83, 68x83 */
+    /* original: 79x57, now all 60 */
 
     strcpy(lsat->sensor, "MSS");
 
@@ -41,9 +41,9 @@
 
     /* blue, green red, near infrared, shortwave IR, thermal IR, shortwave IR */
     int band[] = { 1, 2, 3, 4, 5, 6, 7 };
+    double wmin[] = { 0.45, 0.52, 0.63, 0.76, 1.55, 10.40, 2.08 };
     double wmax[] = { 0.52, 0.60, 0.69, 0.90, 1.75, 12.50, 2.35 };
-    double wmin[] = { 0.45, 0.52, 0.63, 0.76, 1.55, 10.40, 2.08 };
-    /* 30, 30, 30, 30, 30, 120, 30 */
+    /* 30, 30, 30, 30, 30, 120 original, 60 resamples before Feb 25, 2010 and 30 after, 30 */
 
     if (!lsat->sensor)
       strcpy(lsat->sensor, "TM");
@@ -68,9 +68,9 @@
     /* blue, green red, near infrared, shortwave IR, thermal IR, shortwave IR, panchromatic */
     int band[] = { 1, 2, 3, 4, 5, 6, 6, 7, 8 };
     int code[] = { 1, 2, 3, 4, 5, 61, 62, 7, 8 };
+    double wmin[] = { 0.450, 0.525, 0.630, 0.75, 1.55, 10.40, 2.09, 0.52 };
     double wmax[] = { 0.515, 0.605, 0.690, 0.90, 1.75, 12.50, 2.35, 0.90 };
-    double wmin[] = { 0.450, 0.525, 0.630, 0.75, 1.55, 10.40, 2.09, 0.52 };
-    /* 30, 30, 30, 30, 30, 60, 30, 15 */
+    /* 30, 30, 30, 30, 30, 60 (after Feb. 25, 2010: 30), 30, 15 */
 
     strcpy(lsat->sensor, "ETM+");
 
@@ -87,7 +87,33 @@
     return;
 }
 
+void sensor_OLI(lsat_data * lsat)
+{
+    int i;
 
+    /* coastal aerosol, blue, green, red, near infrared, shortwave IR (SWIR) 1, SWIR 2, panchromatic,
+     * cirrus, thermal infrared (TIR) 1, TIR 2 */
+    int band[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
+    int code[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
+    double wmin[] = { 0.433, 0.450, 0.525, 0.630, 0.845, 1.560, 2.100, 0.500, 1.360, 10.3, 11.5 };
+    double wmax[] = { 0.453, 0.515, 0.600, 0.680, 0.885, 1.660, 2.300, 0.680, 1.390, 11.3, 12.5 };
+    /* 30, 30, 30, 30, 30, 30, 30, 15, 30, 100, 100 */
+
+    strcpy(lsat->sensor, "OLI/TIRS");
+
+    lsat->bands = 11;
+    for (i = 0; i < lsat->bands; i++) {
+        lsat->band[i].number = *(band + i);
+        lsat->band[i].code = *(code + i);
+        lsat->band[i].wavemax = *(wmax + i);
+        lsat->band[i].wavemin = *(wmin + i);
+        lsat->band[i].qcalmax = 255.;
+        lsat->band[i].qcalmin = 1.;
+        lsat->band[i].thermal = (lsat->band[i].number > 9 ? 1 : 0);
+    }
+    return;
+}
+
 /** **********************************************
  ** Before access to these functions ...
  ** store previously
@@ -154,9 +180,10 @@
 
     julian = julian_char(lsat->creation);
     if (julian < julian_char("1975-07-16"))
-	i = 0;
+        i = 0;
     else
-	i = 1;
+        i = 1;
+
     lmax = Lmax[i];
     lmin = Lmin[i];
 
@@ -205,6 +232,7 @@
 	i = 0;
     else
 	i = 1;
+
     lmax = Lmax[i];
     lmin = Lmin[i];
 
@@ -256,6 +284,7 @@
 	    i = 1;
     else
 	    i = 2;
+
     lmax = Lmax[i];
     lmin = Lmin[i];
 
@@ -305,6 +334,7 @@
 	    i = 1;
     else
 	    i = 2;
+
     lmax = Lmax[i];
     lmin = Lmin[i];
 
@@ -361,6 +391,7 @@
 	i = 1;
     else
 	i = 2;
+
     lmax = Lmax[i];
     lmin = Lmin[i];
 
@@ -410,6 +441,7 @@
 	    i = 1;
     else
 	    i = 2;
+
     lmax = Lmax[i];
     lmin = Lmin[i];
     if (i == 2) {		/* in Chander, Markham and Barsi 2007 */
@@ -515,3 +547,47 @@
     G_debug(1, "Landsat-7 ETM+");
     return;
 }
+
+/****************************************************************************
+ * PURPOSE:     Store values of Landsat-8 OLI/TIRS
+ *              February 14, 2013
+ *****************************************************************************/
+void set_OLI(lsat_data * lsat)
+{
+    int i, j;
+    double julian, *lmax, *lmin;
+
+    /* Spectral radiances at detector
+    double Lmax[][4] = {
+        {220., 175., 145., 147.},
+        {259., 179., 149., 128.}
+    };
+    double Lmin[][4] = {
+        {4., 3., 3., 1.},
+        {4., 3., 3., 1.}
+    };
+    * Solar exoatmospheric spectral irradiances
+    double esun[] = { 1824., 1570., 1249., 853.4 };
+
+    lmax = Lmax[i];
+    lmin = Lmin[i];
+
+    lsat->number = 3;
+    sensor_MSS(lsat);
+
+    lsat->dist_es = earth_sun(lsat->date);
+
+    for (i = 0; i < lsat->bands; i++) {
+        j = lsat->band[i].number - 1;
+        lsat->band[i].esun = *(esun + j);
+        lsat->band[i].lmax = *(lmax + j);
+        lsat->band[i].lmin = *(lmin + j);
+        if (lsat->band[i].thermal) {
+            lsat->band[i].K1 = 0;
+            lsat->band[i].K2 = 0;
+        }
+    }
+    */
+    G_debug(1, "Landsat-8 LDCM");
+    return;
+}

Modified: grass/branches/releasebranch_6_4/imagery/i.landsat.toar/local_proto.h
===================================================================
--- grass/branches/releasebranch_6_4/imagery/i.landsat.toar/local_proto.h	2013-02-02 18:36:15 UTC (rev 54843)
+++ grass/branches/releasebranch_6_4/imagery/i.landsat.toar/local_proto.h	2013-02-02 18:37:42 UTC (rev 54844)
@@ -4,8 +4,7 @@
 #include <string.h>
 #include "landsat.h"
 
-void lsat_mtldata(char *, lsat_data *);
-void lsat_metdata(char *, lsat_data *);
+void lsat_metadata(char *, lsat_data *);
 
 void set_MSS1(lsat_data *);
 void set_MSS2(lsat_data *);

Modified: grass/branches/releasebranch_6_4/imagery/i.landsat.toar/main.c
===================================================================
--- grass/branches/releasebranch_6_4/imagery/i.landsat.toar/main.c	2013-02-02 18:36:15 UTC (rev 54843)
+++ grass/branches/releasebranch_6_4/imagery/i.landsat.toar/main.c	2013-02-02 18:37:42 UTC (rev 54844)
@@ -200,10 +200,6 @@
 	    G_fatal_error(_("Illegal date format: [%s] (yyyy-mm-dd)"),
 			  lsat.date);
     }
-    /* Unnecessary because G_zero filled
-    else
-	lsat.date[0] = '\0';
-	*/
 
     if (pdate->answer != NULL) {
 	strncpy(lsat.creation, pdate->answer, 11);
@@ -212,36 +208,21 @@
 	    G_fatal_error(_("Illegal date format: [%s] (yyyy-mm-dd)"),
 			  lsat.creation);
     }
-    /* Unnecessary because G_zero filled
-    else
-	lsat.creation[0] = '\0';
-	*/
 
     lsat.sun_elev = elev->answer == NULL ? 0. : atof(elev->answer);
     percent = atof(perc->answer);
     pixel = atoi(dark->answer);
     rayleigh = atof(atmo->answer);
 
-    /* Unnecessary because G_zero filled
-    lsat.flag = NOMETADATAFILE;
-     */
     /* Data from metadata file */
+    /* Unnecessary because G_zero filled, but sanity */
+    lsat.flag = NOMETADATAFILE;
     if (met != NULL)
     {
         lsat.flag = METADATAFILE;
-        i = strlen(met);
-        if (strcmp(met + i - 7, "MTL.txt") == 0)
-        {
-            lsat_mtldata(met, &lsat);
-        }
-        else if (strcmp(met + i - 4, ".met") == 0)
-        {
-            if (strcmp(sensorname, "tm7") == 0)
-                lsat_mtldata(met, &lsat);  /* old .met of Landsat-7 = new MTL file */
-            else
-                lsat_metdata(met, &lsat);
-        }
+        lsat_metadata( met, &lsat );
         G_debug(1, "lsat.number = %d, lsat.sensor = [%s]", lsat.number, lsat.sensor);
+        
         if (!lsat.sensor || lsat.number > 7 || lsat.number < 1)
             G_fatal_error(_("Failed to identify satellite"));
 
@@ -257,17 +238,14 @@
 		      adate->key, elev->key);
     }
     else {
-	if (strcmp(sensorname, "tm7") == 0) {	/* Need gain */
-        if (bgain->answer != NULL && strlen(bgain->answer) == 9) {
+        /* Need gain */
+	if (strcmp(sensorname, "tm7") == 0) {
+            if (bgain->answer == NULL || strlen(bgain->answer) != 9)
+                G_fatal_error(_("Landsat-7 requires band gain with 9 (H/L) data"));
             set_ETM(&lsat, bgain->answer);
-            G_debug(1, "Landsat 7 ETM+");
         }
-        else {
-            G_fatal_error(_("Landsat-7 requires band gain with 9 (H/L) data"));
-        }
-    }
-	else {  /* Not need gain */
-        if (strcmp(sensorname, "tm5") == 0)
+        /* Not need gain */
+        else if (strcmp(sensorname, "tm5") == 0)
             set_TM5(&lsat);
         else if (strcmp(sensorname, "tm4") == 0)
             set_TM4(&lsat);
@@ -283,23 +261,22 @@
             set_MSS1(&lsat);
         else
             G_fatal_error(_("Unknown satellite type (defined by '%s')"), sensor->key);
-        }
     }
 
 	/*****************************************
 	* ------------ PREPARATION --------------
 	*****************************************/
-    if (G_strcasecmp(metho->answer, "corrected") == 0)
+    if (strcasecmp(metho->answer, "corrected") == 0)
 	method = CORRECTED;
-    else if (G_strcasecmp(metho->answer, "dos1") == 0)
+    else if (strcasecmp(metho->answer, "dos1") == 0)
 	method = DOS1;
-    else if (G_strcasecmp(metho->answer, "dos2") == 0)
+    else if (strcasecmp(metho->answer, "dos2") == 0)
 	method = DOS2;
-    else if (G_strcasecmp(metho->answer, "dos2b") == 0)
+    else if (strcasecmp(metho->answer, "dos2b") == 0)
 	method = DOS2b;
-    else if (G_strcasecmp(metho->answer, "dos3") == 0)
+    else if (strcasecmp(metho->answer, "dos3") == 0)
 	method = DOS3;
-    else if (G_strcasecmp(metho->answer, "dos4") == 0)
+    else if (strcasecmp(metho->answer, "dos4") == 0)
 	method = DOS4;
     else
 	method = UNCORRECTED;



More information about the grass-commit mailing list