[GRASS-SVN] r46671 - grass/trunk/raster/r.univar

svn_grass at osgeo.org svn_grass at osgeo.org
Mon Jun 13 04:28:37 EDT 2011


Author: mmetz
Date: 2011-06-13 01:28:37 -0700 (Mon, 13 Jun 2011)
New Revision: 46671

Modified:
   grass/trunk/raster/r.univar/r3.univar_main.c
Log:
fix for #1388

Modified: grass/trunk/raster/r.univar/r3.univar_main.c
===================================================================
--- grass/trunk/raster/r.univar/r3.univar_main.c	2011-06-12 15:45:48 UTC (rev 46670)
+++ grass/trunk/raster/r.univar/r3.univar_main.c	2011-06-13 08:28:37 UTC (rev 46671)
@@ -77,6 +77,7 @@
 int main(int argc, char *argv[])
 {
 
+    CELL val_c;			/* for misc use */
     FCELL val_f;		/* for misc use */
     DCELL val_d;		/* for misc use */
     int map_type, zmap_type;
@@ -89,7 +90,7 @@
     unsigned int rows, cols, depths;
     unsigned int x, y, z;
     double dmin, dmax;
-    int zone, use_zone = 0;
+    int zone, n_zones, use_zone = 0;
     char *mapset, *name;
     struct FPRange zone_range;
 
@@ -155,9 +156,6 @@
 	if (zmap == NULL)
 	    G3d_fatalError(_("Error opening g3d map <%s>"), zonemap);
 
-	if (G3d_tileTypeMap(zmap) != CELL_TYPE)
-	    G_fatal_error("Zoning raster must be of type CELL");
-
 	zmap_type = G3d_tileTypeMap(zmap);
 	
 	if (zmap_type != CELL_TYPE)
@@ -203,7 +201,7 @@
     while (param.percentile->answers[i])
 	i++;
  
-    int n_zones = zone_info.n_zones;
+    n_zones = zone_info.n_zones;
 
     if (n_zones == 0)
         n_zones = 1;
@@ -223,10 +221,46 @@
 	    for (x = 0; x < cols; x++) {
 		zone = 0;
 		if (zone_info.n_zones) {
-		    G3d_getValue(zmap, x, y, z, &val_d, DCELL_TYPE);
-                    zone = (int)val_d;
+		    G3d_getValue(zmap, x, y, z, &zone, CELL_TYPE);
+		    if (G3d_isNullValueNum(&zone, CELL_TYPE))
+			continue;
+                    zone -= zone_info.min;
                 }
-		if (map_type == FCELL_TYPE) {
+		if (map_type == CELL_TYPE) {
+		    G3d_getValue(map, x, y, z, &val_c, map_type);
+		    if (!G3d_isNullValueNum(&val_c, map_type)) {
+			if (param.extended->answer) {
+			    if (stats[zone].n >= stats[zone].n_alloc) {
+				size_t msize;
+				stats[zone].n_alloc += 1000;
+				msize = stats[zone].n_alloc * sizeof(CELL);
+				stats[zone].cell_array =
+				    (CELL *)G_realloc((void *)stats[zone].cell_array, msize);
+			    }
+
+			    stats[zone].cell_array[stats[zone].n] = val_c;
+			}
+
+			stats[zone].sum += val_c;
+			stats[zone].sumsq += (val_c * val_c);
+			stats[zone].sum_abs += fabs(val_c);
+
+			if (stats[zone].first) {
+			    stats[zone].max = val_c;
+			    stats[zone].min = val_c;
+			    stats[zone].first = FALSE;
+			}
+			else {
+			    if (val_c > stats[zone].max)
+				stats[zone].max = val_c;
+			    if (val_c < stats[zone].min)
+				stats[zone].min = val_c;
+			}
+			stats[zone].n++;
+		    }
+		    stats[zone].size++;
+		}
+		else if (map_type == FCELL_TYPE) {
 		    G3d_getValue(map, x, y, z, &val_f, map_type);
 		    if (!G3d_isNullValueNum(&val_f, map_type)) {
 			if (param.extended->answer) {



More information about the grass-commit mailing list