[GRASS-SVN] r44580 - grass/trunk/imagery/i.aster.toar

svn_grass at osgeo.org svn_grass at osgeo.org
Fri Dec 10 07:30:39 EST 2010


Author: ychemin
Date: 2010-12-10 04:30:39 -0800 (Fri, 10 Dec 2010)
New Revision: 44580

Modified:
   grass/trunk/imagery/i.aster.toar/main.c
Log:
bug fixing

Modified: grass/trunk/imagery/i.aster.toar/main.c
===================================================================
--- grass/trunk/imagery/i.aster.toar/main.c	2010-12-10 11:15:57 UTC (rev 44579)
+++ grass/trunk/imagery/i.aster.toar/main.c	2010-12-10 12:30:39 UTC (rev 44580)
@@ -20,7 +20,7 @@
 #include <grass/raster.h>
 #include <grass/glocale.h>
 
-#define MAXFILES 14
+#define MAXFILES 15
 
 /* DN to radiance conversion factors */
 double gain_aster(int band_number, int gain_code);
@@ -225,24 +225,22 @@
 
     /********************/
     for (; *ptr != NULL; ptr++) {
-	if (nfiles > MAXFILES+1)
+	if (nfiles > MAXFILES)
 	    G_fatal_error(_("Too many input maps. Only %d allowed."),
-			  MAXFILES+1);
+			  MAXFILES);
 	name = *ptr;
 	/* Allocate input buffer */
-	in_data_type[nfiles] = Rast_map_type(name, "");
+	in_data_type[nfiles-1] = Rast_map_type(name, "");
 	/* For some strange reason infd[0] cannot be used later */
 	/* So nfiles is initialized with nfiles = 1 */
 	infd[nfiles] = Rast_open_old(name, "");
 
 	Rast_get_cellhd(name, "", &cellhd);
-	/* Because of nfiles init with 1 */
-	/* To return index init with 0 later in code [nfiles-1] */
-	inrast[nfiles-1] = Rast_allocate_buf(in_data_type[nfiles]);
+	inrast[nfiles-1] = Rast_allocate_buf(in_data_type[nfiles-1]);
 	nfiles++;
     }
     nfiles--;
-    if (nfiles < MAXFILES+1) 
+    if (nfiles < MAXFILES) 
 	G_fatal_error(_("The input band number should be 15"));
 
     /***************************************************/
@@ -253,21 +251,21 @@
     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);
+    outfd[1] = Rast_open_new(result0, 1);
+    outfd[2] = Rast_open_new(result1, 1);
+    outfd[3] = Rast_open_new(result2, 1);
+    outfd[4] = Rast_open_new(result3, 1);
+    outfd[5] = Rast_open_new(result4, 1);
+    outfd[6] = Rast_open_new(result5, 1);
+    outfd[7] = Rast_open_new(result6, 1);
+    outfd[8] = Rast_open_new(result7, 1);
+    outfd[9] = Rast_open_new(result8, 1);
+    outfd[10] = Rast_open_new(result9, 1);
+    outfd[11] = Rast_open_new(result10, 1);
+    outfd[12] = Rast_open_new(result11, 1);
+    outfd[13] = Rast_open_new(result12, 1);
+    outfd[14] = Rast_open_new(result13, 1);
+    outfd[15] = Rast_open_new(result14, 1);
     /* Process pixels */
 
     DCELL dout[MAXFILES];
@@ -276,8 +274,8 @@
     for (row = 0; row < nrows; row++) {
 	G_percent(row, nrows, 2);
 	/* read input map */
-	for (i = 1; i < MAXFILES; i++)
-	    Rast_get_row(infd[i], inrast[i-1], row, in_data_type[i]);
+	for (i = 1; i <= MAXFILES; i++)
+	    Rast_get_row(infd[i], inrast[i-1], row, in_data_type[i-1]);
 
 	/*process the data */
 	for (col = 0; col < ncols; col++) {
@@ -306,13 +304,13 @@
 		outrast[i][col] = dout[i];
 	    }
 	}
-	for (i = 0; i < MAXFILES; i++)
-	    Rast_put_row(outfd[i], outrast[i], out_data_type);
+	for (i = 1; i <= MAXFILES; i++)
+	    Rast_put_row(outfd[i], outrast[i-1], out_data_type);
     }
-    for (i = 0; i < MAXFILES; i++) {
-	G_free(inrast[i]);
+    for (i = 1; i <= MAXFILES; i++) {
+	G_free(inrast[i-1]);
 	Rast_close(infd[i]);
-	G_free(outrast[i]);
+	G_free(outrast[i-1]);
 	Rast_close(outfd[i]);
     }
     exit(EXIT_SUCCESS);



More information about the grass-commit mailing list