[GRASS-SVN] r44567 - in grass/trunk: gui/wxpython/xml imagery imagery/i.aster.toar

svn_grass at osgeo.org svn_grass at osgeo.org
Wed Dec 8 22:58:39 EST 2010


Author: ychemin
Date: 2010-12-08 19:58:39 -0800 (Wed, 08 Dec 2010)
New Revision: 44567

Added:
   grass/trunk/imagery/i.aster.toar/
   grass/trunk/imagery/i.aster.toar/gain_aster.c
   grass/trunk/imagery/i.aster.toar/i.aster.toar.html
Removed:
   grass/trunk/imagery/i.aster.toar/description.html
Modified:
   grass/trunk/gui/wxpython/xml/menudata.xml
   grass/trunk/imagery/Makefile
   grass/trunk/imagery/i.aster.toar/Makefile
   grass/trunk/imagery/i.aster.toar/main.c
   grass/trunk/imagery/i.aster.toar/rad2ref_aster.c
Log:
Upgraded then svn mv from Add-ons i.dn2ref.ast->i.aster.toar->grass_trunk/imagery

Modified: grass/trunk/gui/wxpython/xml/menudata.xml
===================================================================
--- grass/trunk/gui/wxpython/xml/menudata.xml	2010-12-09 03:51:48 UTC (rev 44566)
+++ grass/trunk/gui/wxpython/xml/menudata.xml	2010-12-09 03:58:39 UTC (rev 44567)
@@ -2621,6 +2621,13 @@
 	  <label>Satellite images tools</label>
 	  <items>
 	    <menuitem>
+	      <label>Aster DN to radiance/reflectance</label>
+	      <help>Calculates top-of-atmosphere radiance or reflectance and temperature for Aster.</help>
+	      <keywords>imagery,Terra-ASTER,top-of-atmosphere reflectance</keywords>
+	      <handler>OnMenuCmd</handler>
+	      <command>i.aster.toar</command>
+	    </menuitem>
+	    <menuitem>
 	      <label>Landsat DN to radiance/reflectance</label>
 	      <help>Calculates top-of-atmosphere radiance or reflectance and temperature for Landsat MSS/TM/ETM+.</help>
 	      <keywords>imagery,landsat,top-of-atmosphere reflectance,dos-type simple atmospheric correction</keywords>

Modified: grass/trunk/imagery/Makefile
===================================================================
--- grass/trunk/imagery/Makefile	2010-12-09 03:51:48 UTC (rev 44566)
+++ grass/trunk/imagery/Makefile	2010-12-09 03:58:39 UTC (rev 44567)
@@ -2,6 +2,7 @@
 
 SUBDIRS = \
 	i.albedo \
+	i.aster.toar \
 	i.atcorr \
 	i.biomass \
 	i.cca \

Modified: grass/trunk/imagery/i.aster.toar/Makefile
===================================================================
--- grass-addons/imagery/gipe/i.dn2ref.ast/Makefile	2010-12-08 23:19:08 UTC (rev 44565)
+++ grass/trunk/imagery/i.aster.toar/Makefile	2010-12-09 03:58:39 UTC (rev 44567)
@@ -1,9 +1,9 @@
 MODULE_TOPDIR = ../..
 
-PGM = i.dn2ref.ast
+PGM = i.aster.toar
 
-LIBES = $(GISLIB)
-DEPENDENCIES = $(GISDEP)
+LIBES = $(GISLIB) $(RASTERLIB)
+DEPENDENCIES = $(GISDEP) $(RASTERDEP)
 
 include $(MODULE_TOPDIR)/include/Make/Module.make
 

Deleted: grass/trunk/imagery/i.aster.toar/description.html
===================================================================
--- grass-addons/imagery/gipe/i.dn2ref.ast/description.html	2010-12-08 23:19:08 UTC (rev 44565)
+++ grass/trunk/imagery/i.aster.toar/description.html	2010-12-09 03:58:39 UTC (rev 44567)
@@ -1,23 +0,0 @@
-<H2>DESCRIPTION</H2>
-
-<EM>i.dn2ref.ast</EM> calculates the Top Of Atmosphere (TOA) reflectance for Terra-Aster visible, NIR and SWIR bands (9 layers) from DN values. 
-It is useful after importing your Aster imagery from storage format that is generally in standard DN values range.
-
-<H2>NOTES</H2>
-
-<H2>TODO</H2>
-
-<H2>SEE ALSO</H2>
-
-<em>
-<A HREF="r.in.gdal.html">r.in.gdal</A><br>
-</em>
-
-
-<H2>AUTHORS</H2>
-
-Yann Chemin, AIT, Thailand<BR>
-
-
-<p>
-<i>Last changed: $Date$</i>

Added: grass/trunk/imagery/i.aster.toar/gain_aster.c
===================================================================
--- grass/trunk/imagery/i.aster.toar/gain_aster.c	                        (rev 0)
+++ grass/trunk/imagery/i.aster.toar/gain_aster.c	2010-12-09 03:58:39 UTC (rev 44567)
@@ -0,0 +1,152 @@
+#include<stdio.h>
+#include<stdlib.h>
+
+
+/* Gain values LUT for ASTER */
+double gain_aster(int band_number, int gain_code)
+{
+    /*Gain Code */
+    /*0 - High (Not Applicable for band 10-14: TIR) */
+    /*1 - Normal */
+    /*2 - Low 1(Not Applicable for band 10-14: TIR) */
+    /*3 - Low 2(Not Applicable for Band 1-3N/B & 10-14) */
+    double result;
+
+    /* HIGH GAIN */
+    if (gain_code == 0) {
+	/* Band 1 */
+	if (band_number == 0)
+	    result = 0.676;
+	/* Band 2 */
+	if (band_number == 1)
+	    result = 0.708;
+	/* Band 3N */
+	if (band_number == 2)
+	    result = 0.423;
+	/* Band 3B */
+	if (band_number == 3)
+	    result = 0.423;
+	/* Band 4 */
+	if (band_number == 4)
+	    result = 0.1087;
+	/* Band 5 */
+	if (band_number == 5)
+	    result = 0.0348;
+	/* Band 6 */
+	if (band_number == 6)
+	    result = 0.0313;
+	/* Band 7 */
+	if (band_number == 7)
+	    result = 0.0299;
+	/* Band 8 */
+	if (band_number == 8)
+	    result = 0.0209;
+	/* Band 9 */
+	if (band_number == 9)
+	    result = 0.0159;
+    }
+    /* NORMAL GAIN */
+    if (gain_code == 1) {
+	/* Band 1 */
+	if (band_number == 0)
+	    result = 1.688;
+	/* Band 2 */
+	if (band_number == 1)
+	    result = 1.415;
+	/* Band 3N */
+	if (band_number == 2)
+	    result = 0.862;
+	/* Band 3B */
+	if (band_number == 3)
+	    result = 0.862;
+	/* Band 4 */
+	if (band_number == 4)
+	    result = 0.2174;
+	/* Band 5 */
+	if (band_number == 5)
+	    result = 0.0696;
+	/* Band 6 */
+	if (band_number == 6)
+	    result = 0.0625;
+	/* Band 7 */
+	if (band_number == 7)
+	    result = 0.0597;
+	/* Band 8 */
+	if (band_number == 8)
+	    result = 0.0417;
+	/* Band 9 */
+	if (band_number == 9)
+	    result = 0.0318;
+	/* Band 10 */
+	if (band_number == 10)
+	    result = 0.006822;
+	/* Band 11 */
+	if (band_number == 11)
+	    result = 0.006780;
+	/* Band 12 */
+	if (band_number == 12)
+	    result = 0.006590;
+	/* Band 13 */
+	if (band_number == 13)
+	    result = 0.005693;
+	/* Band 14 */
+	if (band_number == 14)
+	    result = 0.005225;
+    }
+
+    /* LOW GAIN 1 */
+    if (gain_code == 2) {
+	/* Band 1 */
+	if (band_number == 0)
+	    result = 2.25;
+	/* Band 2 */
+	if (band_number == 1)
+	    result = 1.89;
+	/* Band 3N */
+	if (band_number == 2)
+	    result = 1.15;
+	/* Band 3B */
+	if (band_number == 3)
+	    result = 1.15;
+	/* Band 4 */
+	if (band_number == 4)
+	    result = 0.290;
+	/* Band 5 */
+	if (band_number == 5)
+	    result = 0.0925;
+	/* Band 6 */
+	if (band_number == 6)
+	    result = 0.0830;
+	/* Band 7 */
+	if (band_number == 7)
+	    result = 0.0795;
+	/* Band 8 */
+	if (band_number == 8)
+	    result = 0.0556;
+	/* Band 9 */
+	if (band_number == 9)
+	    result = 0.0424;
+    }
+    /* LOW GAIN 2 */
+    if (gain_code == 3) {
+	/* Band 4 */
+	if (band_number == 4)
+	    result = 0.290;
+	/* Band 5 */
+	if (band_number == 5)
+	    result = 0.409;
+	/* Band 6 */
+	if (band_number == 6)
+	    result = 0.390;
+	/* Band 7 */
+	if (band_number == 7)
+	    result = 0.332;
+	/* Band 8 */
+	if (band_number == 8)
+	    result = 0.245;
+	/* Band 9 */
+	if (band_number == 9)
+	    result = 0.265;
+    }
+    return result;
+}

Added: grass/trunk/imagery/i.aster.toar/i.aster.toar.html
===================================================================
--- grass/trunk/imagery/i.aster.toar/i.aster.toar.html	                        (rev 0)
+++ grass/trunk/imagery/i.aster.toar/i.aster.toar.html	2010-12-09 03:58:39 UTC (rev 44567)
@@ -0,0 +1,33 @@
+<H2>DESCRIPTION</H2>
+
+<EM>i.aster.toar</EM> calculates the Top Of Atmosphere (TOA) reflectance for Terra-Aster L1B in the visible, NIR and SWIR bands (9 layers) and brigthness temperature for the TIR bands, all from L1B DN values. 
+It is useful after importing your Aster imagery from storage format that is generally in standard DN values range.
+
+<H2>NOTES</H2>
+Internally, a gain code is defined to modify gains according to spectral bands following the GeoSystems GmbH ATCOR Ver. 2.0 Calibration Files. The function is defined in gain_aster.c file.
+
+<div class="code"><pre>
+/*Gain Code*/
+    /*0 - High (Not Applicable for band 10-14: TIR)*/
+    /*1 - Normal*/
+    /*2 - Low 1(Not Applicable for band 10-14: TIR)*/
+    /*3 - Low 2(Not Applicable for Band 1-3N/B and 10-14)*/
+</pre></div>
+
+<H2>TODO</H2>
+
+<H2>SEE ALSO</H2>
+
+<em>
+<A HREF="i.landsat.toar.html">i.landsat.toar</A><br>
+<A HREF="r.in.aster.html">r.in.aster</A><br>
+</em>
+
+
+<H2>AUTHORS</H2>
+
+Yann Chemin, CSU, Australia<BR>
+
+
+<p>
+<i>Last changed: $Date: 2010-04-03 19:49:00 +1100 (Sat, 03 Apr 2010) $</i>

Modified: grass/trunk/imagery/i.aster.toar/main.c
===================================================================
--- grass-addons/imagery/gipe/i.dn2ref.ast/main.c	2010-12-08 23:19:08 UTC (rev 44565)
+++ grass/trunk/imagery/i.aster.toar/main.c	2010-12-09 03:58:39 UTC (rev 44567)
@@ -1,47 +1,36 @@
 
 /****************************************************************************
  *
- * MODULE:       i.dn2ref.ast
+ * MODULE:       i.aster.toar
  * AUTHOR(S):    Yann Chemin - yann.chemin at gmail.com
  * PURPOSE:      Calculate TOA Reflectance for Aster from DN.
  * 		 Input 9 bands (VNIR and SWIR).
  *
- * COPYRIGHT:    (C) 2002-2008 by the GRASS Development Team
+ * COPYRIGHT:    (C) 2002-2010 by the GRASS Development Team
  *
  *               This program is free software under the GNU Lesser General Public
  *   	    	 License. Read the file COPYING that comes with GRASS for details.
  *
  *****************************************************************************/
 
-
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <grass/gis.h>
+#include <grass/raster.h>
 #include <grass/glocale.h>
 
-#define MAXFILES 9
+#define MAXFILES 14
 
 /* DN to radiance conversion factors */
-#define L1GAIN 0.676
-#define L1OFFS -0.676
-#define L2GAIN 0.862
-#define L2OFFS -0.862
-#define L3GAIN 0.217
-#define L3OFFS -0.217
-#define L4GAIN 0.0696
-#define L4OFFS -0.0696
-#define L5GAIN 0.0696
-#define L5OFFS -0.0696
-#define L6GAIN 0.0696
-#define L6OFFS -0.0696
-#define L7GAIN 0.0696
-#define L7OFFS -0.0696
-#define L8GAIN 0.0696
-#define L8OFFS -0.0696
-#define L9GAIN 0.0318
-#define L9OFFS -0.0318
+double gain_aster(int band_number, int gain_code);
 
+    /*Gain Code */
+    /*0 - High (Not Applicable for band 10-14: TIR) */
+    /*1 - Normal */
+    /*2 - Low 1(Not Applicable for band 10-14: TIR) */
+    /*3 - Low 2(Not Applicable for Band 1-3N/B & 10-14) */
+
 /*sun exo-atmospheric irradiance */
 #define KEXO1 1828.0
 #define KEXO2 1559.0
@@ -61,78 +50,54 @@
 int main(int argc, char *argv[])
 {
     struct Cell_head cellhd;	/*region+header info */
-
     char *mapset;		/*mapset name */
-
     int nrows, ncols;
-
     int row, col;
-
     struct GModule *module;
-
     struct Option *input, *output;
-
     struct Option *input1, *input2;
-
-    struct Flag *flag1, *flag2;
-
+    struct Flag *flag0, *flag1, *flag2;
+    struct Flag *flag3, *flag4, *flag5;
     struct History history;	/*metadata */
 
-	/************************************/
-    /* FMEO Declarations**************** */
+    /************************************/
     char *name;			/*input raster name */
-
     char *result;		/*output raster name */
 
     /*Prepare new names for output files */
     char *result0, *result1, *result2, *result3, *result4;
+    char *result5, *result6, *result7, *result8, *result9;
+    char *result10, *result11, *result12, *result13, *result14;
 
-    char *result5, *result6, *result7, *result8;
-
     /*File Descriptors */
-    int nfiles;
-
     int infd[MAXFILES];
-
     int outfd[MAXFILES];
-
-    char **names;
-
     char **ptr;
-
-    int ok;
-
+    int nfiles = 0;
     int i = 0, j = 0;
-
     int radiance = 0;
-
     void *inrast[MAXFILES];
-
     DCELL *outrast[MAXFILES];
-
     int data_format;		/* 0=double  1=float  2=32bit signed int  5=8bit unsigned int (ie text) */
-
     RASTER_MAP_TYPE in_data_type[MAXFILES];
-
     RASTER_MAP_TYPE out_data_type = DCELL_TYPE;	/* 0=numbers  1=text */
-
     double gain[MAXFILES], offset[MAXFILES];
-
     double kexo[MAXFILES];
-
     double doy, sun_elevation;
 
-	/************************************/
-
+    /************************************/
     G_gisinit(argv[0]);
-
     module = G_define_module();
-    module->keywords = _("DN, radiance, reflectance, import");
+    G_add_keyword(_("imagery"));
+    G_add_keyword(_("Terra-ASTER"));
+    G_add_keyword(_("DN"));
+    G_add_keyword(_("radiance"));
+    G_add_keyword(_("reflectance"));
+    G_add_keyword(_("brightness temperature"));
     module->description =
-	_("Calculates Top of Atmosphere Reflectance from ASTER DN.\n");
+	_("Calculates Top of Atmosphere Radiance/Reflectance/Brightness Temperature from ASTER DN.\n");
 
     /* Define the different options */
-
     input = G_define_standard_option(G_OPT_R_INPUTS);
     input->description = _("Names of ASTER DN layers (9 layers)");
 
@@ -154,32 +119,45 @@
     output->description = _("Base name of the output layers (will add .x)");
 
     /* Define the different flags */
+    flag0 = G_define_flag();
+    flag0->key = _('r');
+    flag0->description = _("output is radiance (W/m2)");
 
     flag1 = G_define_flag();
-    flag1->key = _('r');
-    flag1->description = _("output is radiance (W/m2)");
+    flag1->key = _('a');
+    flag1->description = _("VNIR is High Gain");
 
-    /* FMEO init nfiles */
-    nfiles = 1;
+    flag2 = G_define_flag();
+    flag2->key = _('b');
+    flag2->description = _("SWIR is High Gain");
 
-	/********************/
+    flag3 = G_define_flag();
+    flag3->key = _('c');
+    flag3->description = _("VNIR is Low Gain 1");
+
+    flag4 = G_define_flag();
+    flag4->key = _('d');
+    flag4->description = _("SWIR is Low Gain 1");
+
+    flag5 = G_define_flag();
+    flag5->key = _('e');
+    flag5->description = _("SWIR is Low Gain 2");
+
+    /********************/
     if (G_parser(argc, argv))
-	exit(-1);
+	exit(EXIT_FAILURE);
 
-    ok = 1;
-    names = input->answers;
     ptr = input->answers;
     doy = atof(input1->answer);
     sun_elevation = atof(input2->answer);
     result = output->answer;
 
-    radiance = (flag1->answer);
+    radiance = (flag0->answer);
 
-	/********************/
+    /********************/
     /*Prepare the ouput file names */
 
-	/********************/
-
+    /********************/
     result0 = result;
     result1 = result;
     result2 = result;
@@ -189,143 +167,129 @@
     result6 = result;
     result7 = result;
     result8 = result;
+    result9 = result;
+    result10 = result;
+    result11 = result;
+    result12 = result;
+    result13 = result;
+    result14 = result;
 
     result0 = strcat(result0, ".1");
     result1 = strcat(result1, ".2");
-    result2 = strcat(result2, ".3");
-    result3 = strcat(result3, ".4");
-    result4 = strcat(result4, ".5");
-    result5 = strcat(result5, ".6");
-    result6 = strcat(result6, ".7");
-    result7 = strcat(result7, ".8");
-    result8 = strcat(result8, ".9");
+    result2 = strcat(result2, ".3N");
+    result3 = strcat(result3, ".3B");
+    result4 = strcat(result4, ".4");
+    result5 = strcat(result5, ".5");
+    result6 = strcat(result6, ".6");
+    result7 = strcat(result7, ".7");
+    result8 = strcat(result8, ".8");
+    result9 = strcat(result9, ".9");
+    result10 = strcat(result10, ".10");
+    result11 = strcat(result11, ".11");
+    result12 = strcat(result12, ".12");
+    result13 = strcat(result13, ".13");
+    result14 = strcat(result14, ".14");
 
-	/********************/
+    /********************/
     /*Prepare radiance boundaries */
 
-	/********************/
+    /********************/
+    int gain_code = 1;
 
-    gain[0] = L1GAIN;
-    gain[1] = L2GAIN;
-    gain[2] = L3GAIN;
-    gain[3] = L4GAIN;
-    gain[4] = L5GAIN;
-    gain[5] = L6GAIN;
-    gain[6] = L7GAIN;
-    gain[7] = L8GAIN;
-    gain[8] = L9GAIN;
+    for (i = 0; i < MAXFILES; i++) {
+	/*0 - High (Not Applicable for band 10-14: TIR) */
+	/*1 - Normal */
+	/*2 - Low 1(Not Applicable for band 10-14: TIR) */
+	/*3 - Low 2(Not Applicable for Band 1-3N/B & 10-14) */
+	if (flag1->answer && i <= 3)
+	    gain_code = 0;
+	if (flag2->answer && i >= 4 && i <= 9)
+	    gain_code = 0;
+	if (flag3->answer && i <= 3)
+	    gain_code = 2;
+	if (flag4->answer && i >= 4 && i <= 9)
+	    gain_code = 2;
+	if (flag5->answer && i >= 4 && i <= 9)
+	    gain_code = 3;
+	gain[i] = gain_aster(i, gain_code);
+	/* Reset to NORMAL GAIN */
+	gain_code = 1;
+    }
 
-    offset[0] = L1OFFS;
-    offset[1] = L2OFFS;
-    offset[2] = L3OFFS;
-    offset[3] = L4OFFS;
-    offset[4] = L5OFFS;
-    offset[5] = L6OFFS;
-    offset[6] = L7OFFS;
-    offset[7] = L8OFFS;
-    offset[8] = L9OFFS;
-
-	/********************/
+    /********************/
     /*Prepare sun exo-atm irradiance */
 
-	/********************/
-
+    /********************/
     kexo[0] = KEXO1;
     kexo[1] = KEXO2;
     kexo[2] = KEXO3;
-    kexo[3] = KEXO4;
-    kexo[4] = KEXO5;
-    kexo[5] = KEXO6;
-    kexo[6] = KEXO7;
-    kexo[7] = KEXO8;
-    kexo[8] = KEXO9;
+    kexo[3] = KEXO3;
+    kexo[4] = KEXO4;
+    kexo[5] = KEXO5;
+    kexo[6] = KEXO6;
+    kexo[7] = KEXO7;
+    kexo[8] = KEXO8;
+    kexo[9] = KEXO9;
 
-	/********************/
+    /********************/
 
-	/********************/
+    /********************/
     for (; *ptr != NULL; ptr++) {
 	if (nfiles >= MAXFILES)
-	    G_fatal_error(_("%s - too many ETa files. Only %d allowed"),
-			  G_program_name(), MAXFILES);
+	    G_fatal_error(_("Too many input maps. Only %d allowed."),
+			  MAXFILES);
 	name = *ptr;
-	/* find map in mapset */
-	mapset = G_find_cell2(name, "");
-	if (mapset == NULL) {
-	    G_fatal_error(_("cell file [%s] not found"), name);
-	    ok = 0;
-	}
-	if (G_legal_filename(result) < 0) {
-	    G_fatal_error(_("[%s] is an illegal name"), result);
-	    ok = 0;
-	}
-	if (!ok) {
-	    continue;
-	}
-	infd[nfiles] = G_open_cell_old(name, mapset);
-	if (infd[nfiles] < 0) {
-	    ok = 0;
-	    continue;
-	}
+
 	/* Allocate input buffer */
-	in_data_type[nfiles] = G_raster_map_type(name, mapset);
-	if ((infd[nfiles] = G_open_cell_old(name, mapset)) < 0) {
-	    G_fatal_error(_("Cannot open cell file [%s]"), name);
-	}
-	if ((G_get_cellhd(name, mapset, &cellhd)) < 0) {
-	    G_fatal_error(_("Cannot read file header of [%s]"), name);
-	}
-	inrast[nfiles] = G_allocate_raster_buf(in_data_type[nfiles]);
+	in_data_type[nfiles] = Rast_map_type(name, "");
+	infd[nfiles] = Rast_open_old(name, "");
+
+	Rast_get_cellhd(name, "", &cellhd);
+
+	inrast[nfiles] = Rast_allocate_buf(in_data_type[nfiles]);
 	nfiles++;
     }
-    nfiles--;
-    if (nfiles <= 1) {
-	G_fatal_error(_("The input band number should be 6"));
+    if (nfiles < MAXFILES) {
+	G_fatal_error(_("The input band number should be 15"));
     }
 
-	/***************************************************/
+    /***************************************************/
     /* Allocate output buffer, use input map data_type */
-    nrows = G_window_rows();
-    ncols = G_window_cols();
+    nrows = Rast_window_rows();
+    ncols = Rast_window_cols();
     out_data_type = DCELL_TYPE;
-    for (i = 0; i < nfiles; i++) {
-	outrast[i] = G_allocate_raster_buf(out_data_type);
-    }
-    if ((outfd[0] = G_open_raster_new(result0, 1)) < 0)
-	G_fatal_error(_("Could not open <%s>"), result0);
-    if ((outfd[1] = G_open_raster_new(result1, 1)) < 0)
-	G_fatal_error(_("Could not open <%s>"), result1);
-    if ((outfd[2] = G_open_raster_new(result2, 1)) < 0)
-	G_fatal_error(_("Could not open <%s>"), result2);
-    if ((outfd[3] = G_open_raster_new(result3, 1)) < 0)
-	G_fatal_error(_("Could not open <%s>"), result3);
-    if ((outfd[4] = G_open_raster_new(result4, 1)) < 0)
-	G_fatal_error(_("Could not open <%s>"), result4);
-    if ((outfd[5] = G_open_raster_new(result5, 1)) < 0)
-	G_fatal_error(_("Could not open <%s>"), result5);
-    if ((outfd[6] = G_open_raster_new(result6, 1)) < 0)
-	G_fatal_error(_("Could not open <%s>"), result6);
-    if ((outfd[7] = G_open_raster_new(result7, 1)) < 0)
-	G_fatal_error(_("Could not open <%s>"), result7);
-    if ((outfd[8] = G_open_raster_new(result8, 1)) < 0)
-	G_fatal_error(_("Could not open <%s>"), result8);
+    for (i = 0; i < MAXFILES; i++)
+	outrast[i] = Rast_allocate_buf(out_data_type);
+
+    outfd[0] = Rast_open_new(result0, 1);
+    outfd[1] = Rast_open_new(result1, 1);
+    outfd[2] = Rast_open_new(result2, 1);
+    outfd[3] = Rast_open_new(result3, 1);
+    outfd[4] = Rast_open_new(result4, 1);
+    outfd[5] = Rast_open_new(result5, 1);
+    outfd[6] = Rast_open_new(result6, 1);
+    outfd[7] = Rast_open_new(result7, 1);
+    outfd[8] = Rast_open_new(result8, 1);
+    outfd[9] = Rast_open_new(result9, 1);
+    outfd[10] = Rast_open_new(result10, 1);
+    outfd[11] = Rast_open_new(result11, 1);
+    outfd[12] = Rast_open_new(result12, 1);
+    outfd[13] = Rast_open_new(result13, 1);
+    outfd[14] = Rast_open_new(result14, 1);
     /* Process pixels */
 
     DCELL dout[MAXFILES];
-
     DCELL d[MAXFILES];
 
     for (row = 0; row < nrows; row++) {
 	G_percent(row, nrows, 2);
 	/* read input map */
-	for (i = 1; i <= nfiles; i++) {
-	    if ((G_get_raster_row(infd[i], inrast[i], row, in_data_type[i])) <
-		0) {
-		G_fatal_error(_("Could not read from <%s>"), name);
-	    }
-	}
+	for (i = 0; i < MAXFILES; i++)
+	    Rast_get_row(infd[i], inrast[i], row, in_data_type[i]);
+
 	/*process the data */
 	for (col = 0; col < ncols; col++) {
-	    for (i = 1; i <= nfiles; i++) {
+	    for (i = 0; i < MAXFILES; i++) {
 		switch (in_data_type[i]) {
 		case CELL_TYPE:
 		    d[i] = (double)((CELL *) inrast[i])[col];
@@ -337,28 +301,27 @@
 		    d[i] = (double)((DCELL *) inrast[i])[col];
 		    break;
 		}
-
-		if (radiance) {
-		    dout[i] = gain[i] * d[i] + offset[i];
+		/* if radiance mode or Thermal band */
+		if (radiance || i >= 10) {
+		    dout[i] = gain[i] * (d[i] - 1.0);
 		}
+		/* if reflectance default mode and Not Thermal Band */
 		else {
-		    dout[i] = gain[i] * d[i] + offset[i];
+		    dout[i] = gain[i] * (d[i] - 1.0);
 		    dout[i] =
 			rad2ref_aster(dout[i], doy, sun_elevation, kexo[i]);
 		}
 		outrast[i][col] = dout[i];
 	    }
 	}
-	for (i = 0; i < nfiles; i++) {
-	    if (G_put_raster_row(outfd[i], outrast[i], out_data_type) < 0)
-		G_fatal_error(_("Cannot write to <%s.%i>"), result, i + 1);
-	}
+	for (i = 0; i < MAXFILES; i++)
+	    Rast_put_row(outfd[i], outrast[i], out_data_type);
     }
-    for (i = 1; i <= nfiles; i++) {
+    for (i = 0; i < MAXFILES; i++) {
 	G_free(inrast[i]);
-	G_close_cell(infd[i]);
+	Rast_close(infd[i]);
 	G_free(outrast[i]);
-	G_close_cell(outfd[i]);
+	Rast_close(outfd[i]);
     }
-    return 0;
+    exit(EXIT_SUCCESS);
 }

Modified: grass/trunk/imagery/i.aster.toar/rad2ref_aster.c
===================================================================
--- grass-addons/imagery/gipe/i.dn2ref.ast/rad2ref_aster.c	2010-12-08 23:19:08 UTC (rev 44565)
+++ grass/trunk/imagery/i.aster.toar/rad2ref_aster.c	2010-12-09 03:58:39 UTC (rev 44567)
@@ -3,10 +3,10 @@
 #include<stdlib.h>
 
 #define PI 3.1415926
-    
-    /* Conversion of Radiance to Reflectance for ASTER */ 
+
+    /* Conversion of Radiance to Reflectance for ASTER */
 double rad2ref_aster(double radiance, double doy, double sun_elevation,
-		      double k_exo) 
+		     double k_exo)
 {
     double result, ds;
 
@@ -16,5 +16,3 @@
 	 ((cos((90 - sun_elevation) * PI / 180) / (PI * ds * ds)) * k_exo));
     return result;
 }
-
-



More information about the grass-commit mailing list