[GRASS-SVN] r43458 - grass-addons/imagery/i.landsat.toar
svn_grass at osgeo.org
svn_grass at osgeo.org
Tue Sep 14 00:37:13 EDT 2010
Author: hamish
Date: 2010-09-14 04:37:13 +0000 (Tue, 14 Sep 2010)
New Revision: 43458
Modified:
grass-addons/imagery/i.landsat.toar/main.c
Log:
option and i18n cleanup, test for valid date string length
Modified: grass-addons/imagery/i.landsat.toar/main.c
===================================================================
--- grass-addons/imagery/i.landsat.toar/main.c 2010-09-14 01:27:13 UTC (rev 43457)
+++ grass-addons/imagery/i.landsat.toar/main.c 2010-09-14 04:37:13 UTC (rev 43458)
@@ -38,16 +38,16 @@
RASTER_MAP_TYPE in_data_type;
- int verbose = 1;
- struct Option *input, *metfn,
- *adate, *pdate, *elev, *bgain, *metho, *perc, *dark, *satz, *atmo;
+ int verbose = TRUE;
+ struct Option *input, *metfn, *sensor, *adate, *pdate, *elev,
+ *bgain, *metho, *perc, *dark, *satz, *atmo;
char *name, *met;
- struct Flag *sat1, *sat2, *sat3, *sat4, *sat5, *sat7, *msss,
- *verbo, *frad;
+ struct Flag *msss, *verbo, *frad;
lsat_data lsat;
char band_in[127], band_out[127];
int i, j, q, method, pixel, dn_dark[MAX_BANDS], dn_mode[MAX_BANDS];
+ int sensor_id;
double qcal, rad, ref, percent, ref_mode, sat_zenith, rayleigh;
unsigned long hist[256], h_max;
@@ -58,146 +58,120 @@
/* initialize module */
module = G_define_module();
module->description =
- _("Calculates top-of-atmosphere radiance or reflectance and temperature for Landsat MSS/TM/ETM+");
+ _("Calculates top-of-atmosphere radiance or reflectance and temperature for Landsat MSS/TM/ETM+.");
module->keywords =
- _("Top-Of-Atmosphere Radiance or Reflectance.\n Landsat-1 MSS, Landsat-2 MSS, Landsat-3 MSS, Landsat-4 MSS, Landsat-5 MSS,\n Landsat-4 TM, Landsat-5 TM,\n Landsat-7 ETM+");
+ _("imagery, landsat, top-of-atmosphere radiance or reflectance");
/* It defines the different parameters */
input = G_define_option();
- input->key = _("band_prefix");
+ input->key = "band_prefix";
input->type = TYPE_STRING;
input->required = YES;
- input->gisprompt = _("input,cell,raster");
+ input->gisprompt = "input,cell,raster";
input->description = _("Base name of the landsat band rasters (.#)");
metfn = G_define_option();
- metfn->key = _("metfile");
+ metfn->key = "metfile";
metfn->type = TYPE_STRING;
metfn->required = NO;
- metfn->gisprompt = _(".met file");
metfn->description = _("Landsat ETM+ or TM5 header file (.met)");
+ metho = G_define_option();
+ metho->key = "method";
+ metho->type = TYPE_STRING;
+ metho->required = NO;
+ metho->options = "uncorrected,corrected,dos1,dos2,dos2b,dos3,dos4";
+ metho->description = _("Atmospheric correction method");
+ metho->answer = "uncorrected";
+
+ sensor = G_define_option();
+ sensor->key = "sensor";
+ sensor->type = TYPE_INTEGER;
+ sensor->description = _("Spacecraft sensor");
+ sensor->options = "1,2,3,4,5,7";
+ sensor->descriptions =
+ _("1;Landsat-1 MSS;"
+ "2;Landsat-2 MSS;"
+ "3;Landsat-3 MSS;"
+ "4;Landsat-4 TM;"
+ "5;Landsat-5 TM;"
+ "7;Landsat-7 ETM+");
+ sensor->required = NO;
+
adate = G_define_option();
- adate->key = _("date");
+ adate->key = "date";
adate->type = TYPE_STRING;
adate->required = NO;
- adate->gisprompt = _("image acquisition date");
+ adate->key_desc = "yyyy-mm-dd";
adate->description = _("Image acquisition date (yyyy-mm-dd)");
elev = G_define_option();
- elev->key = _("solar_elevation");
+ elev->key = "solar_elevation";
elev->type = TYPE_DOUBLE;
elev->required = NO;
- elev->gisprompt = _("solar elevation");
elev->description = _("Solar elevation in degrees");
bgain = G_define_option();
- bgain->key = _("gain");
+ bgain->key = "gain";
bgain->type = TYPE_STRING;
bgain->required = NO;
- bgain->gisprompt = _("band gain");
bgain->description =
_("Gain (H/L) of all Landsat ETM+ bands (1-5,61,62,7,8)");
pdate = G_define_option();
- pdate->key = _("product_date");
+ pdate->key = "product_date";
pdate->type = TYPE_STRING;
pdate->required = NO;
- pdate->gisprompt = _("image production date");
+ pdate->key_desc = "yyyy-mm-dd";
pdate->description = _("Image creation date (yyyy-mm-dd)");
- metho = G_define_option();
- metho->key = _("method");
- metho->type = TYPE_STRING;
- metho->required = NO;
- metho->options = "uncorrected,corrected,dos1,dos2,dos2b,dos3,dos4";
- metho->gisprompt = _("atmospheric correction method");
- metho->description = _("Atmospheric correction method");
- metho->answer = "uncorrected";
-
perc = G_define_option();
- perc->key = _("percent");
+ perc->key = "percent";
perc->type = TYPE_DOUBLE;
perc->required = NO;
- perc->gisprompt = _("percent of solar radiance in path radiance");
perc->description = _("Percent of solar radiance in path radiance");
perc->answer = "0.01";
dark = G_define_option();
- dark->key = _("pixel");
+ dark->key = "pixel";
dark->type = TYPE_INTEGER;
dark->required = NO;
- dark->gisprompt = _("pixels to dark object");
dark->description =
_("Minimum pixels to consider digital number as dark object");
dark->answer = "1000";
satz = G_define_option();
- satz->key = _("sat_zenith");
+ satz->key = "sat_zenith";
satz->type = TYPE_DOUBLE;
satz->required = NO;
- satz->gisprompt = _("satellite zenith");
satz->description = _("Satellite zenith in degrees");
satz->answer = "8.2000";
atmo = G_define_option();
- atmo->key = _("rayleigh");
+ atmo->key = "rayleigh";
atmo->type = TYPE_DOUBLE;
atmo->required = NO;
- atmo->gisprompt = _("Rayleigh atmosphere");
- atmo->description = _("Rayleigh atmosphere");
+ atmo->description = _("Rayleigh atmosphere"); /* scattering coefficient? */
atmo->answer = "0.0";
- /* It defines the different flags */
+ /* define the different flags */
frad = G_define_flag();
frad->key = 'r';
frad->description = _("Output at-sensor radiance for all bands");
- frad->answer = 0;
- sat1 = G_define_flag();
- sat1->key = '1';
- sat1->description = _("Landsat-1 MSS");
- sat1->answer = 0;
-
- sat2 = G_define_flag();
- sat2->key = '2';
- sat2->description = _("Landsat-2 MSS");
- sat2->answer = 0;
-
- sat3 = G_define_flag();
- sat3->key = '3';
- sat3->description = _("Landsat-3 MSS");
- sat3->answer = 0;
-
- sat4 = G_define_flag();
- sat4->key = '4';
- sat4->description = _("Landsat-4 TM");
- sat4->answer = 0;
-
- sat5 = G_define_flag();
- sat5->key = '5';
- sat5->description = _("Landsat-5 TM");
- sat5->answer = 0;
-
- sat7 = G_define_flag();
- sat7->key = '7';
- sat7->description = _("Landsat-7 ETM+");
- sat7->answer = 0;
-
msss = G_define_flag();
msss->key = 's';
msss->description = _("Set sensor of Landsat-4/5 to MSS");
- msss->answer = 0;
verbo = G_define_flag();
verbo->key = 'v';
verbo->description = _("Show parameters applied");
- verbo->answer = 0;
/* options and afters parser */
if (G_parser(argc, argv))
exit(EXIT_FAILURE);
+
/*****************************************
* ---------- START --------------------
* Stores options and flag to variables
@@ -208,6 +182,8 @@
if (adate->answer != NULL) {
strncpy(lsat.date, adate->answer, 11);
lsat.date[10] = '\0';
+ if (strlen(lsat.date) != 10)
+ G_fatal_error(_("Illegal date format: [%s] (yyyy-mm-dd)"), lsat.date);
}
else
lsat.date[0] = '\0';
@@ -215,6 +191,8 @@
if (pdate->answer != NULL) {
strncpy(lsat.creation, pdate->answer, 11);
lsat.creation[10] = '\0';
+ if (strlen(lsat.date) != 10)
+ G_fatal_error(_("Illegal date format: [%s] (yyyy-mm-dd)"), lsat.date);
}
else
lsat.creation[0] = '\0';
@@ -225,19 +203,22 @@
sat_zenith = atof(satz->answer);
rayleigh = atof(atmo->answer);
- if (met == NULL &&
- (sat1->answer + sat2->answer + sat3->answer +
- sat4->answer + sat5->answer + sat7->answer) != 1)
- G_fatal_error(_("Select one and only one type of satellite"));
+ if (met == NULL) {
+ if (sensor->answer)
+ sensor_id = atoi(sensor->answer);
+ else
+ G_fatal_error(_("Must select type of satellite"));
+ }
/* Data from MET file: only Landsat-7 ETM+ and Landsat-5 TM */
if (met != NULL) {
- if (sat7->answer)
+ if (sensor_id == 7)
met_ETM(met, &lsat);
else
met_TM5(met, &lsat);
- G_message("Landsat-%d %s with data set in met file [%s]", lsat.number,
- lsat.sensor, met);
+
+ G_message(_("Landsat-%d %s with data set in met file [%s]"),
+ lsat.number, lsat.sensor, met);
if (elev->answer != NULL)
lsat.sun_elev = atof(elev->answer); /* Overwrite solar elevation of met file */
}
@@ -246,44 +227,44 @@
G_fatal_error(_("Lacking date or solar elevation for this satellite"));
}
else {
- if (sat7->answer) { /* Need gain */
+ if (sensor_id == 7) { /* Need gain */
if (bgain->answer != NULL && strlen(bgain->answer) == 9) {
set_ETM(&lsat, bgain->answer);
G_message("Landsat 7 ETM+");
}
else {
- G_fatal_error(_("For Landsat-7 is necessary band gain with 9 (H/L) data"));
+ G_fatal_error(_("Landsat-7 requires band gain with 9 (H/L) data"));
}
}
else { /* Not need gain */
- if (sat5->answer) {
+ if (sensor_id == 5) {
if (msss->answer)
set_MSS5(&lsat);
else
set_TM5(&lsat);
G_message("Landsat-5 %s", lsat.sensor);
}
- else if (sat4->answer) {
+ else if (sensor_id == 4) {
if (msss->answer)
set_MSS4(&lsat);
else
set_TM4(&lsat);
G_message("Landsat-4 %s", lsat.sensor);
}
- else if (sat3->answer) {
+ else if (sensor_id == 3) {
set_MSS3(&lsat);
G_message("Landsat-3 MSS");
}
- else if (sat2->answer) {
+ else if (sensor_id == 2) {
set_MSS2(&lsat);
G_message("Landsat-2 MSS");
}
- else if (sat1->answer) {
+ else if (sensor_id == 1) {
set_MSS1(&lsat);
G_message("Landsat-1 MSS");
}
else {
- G_fatal_error(_("Lacking satellite type"));
+ G_fatal_error(_("Unuknown satellite type"));
}
}
}
More information about the grass-commit
mailing list