[GRASS-SVN] r45708 - grass/branches/develbranch_6/raster3d/r3.stats

svn_grass at osgeo.org svn_grass at osgeo.org
Fri Mar 18 05:25:51 EDT 2011


Author: huhabla
Date: 2011-03-18 02:25:50 -0700 (Fri, 18 Mar 2011)
New Revision: 45708

Modified:
   grass/branches/develbranch_6/raster3d/r3.stats/description.html
   grass/branches/develbranch_6/raster3d/r3.stats/main.c
Log:
Better NULL pointer handling.


Modified: grass/branches/develbranch_6/raster3d/r3.stats/description.html
===================================================================
--- grass/branches/develbranch_6/raster3d/r3.stats/description.html	2011-03-18 08:53:57 UTC (rev 45707)
+++ grass/branches/develbranch_6/raster3d/r3.stats/description.html	2011-03-18 09:25:50 UTC (rev 45708)
@@ -9,7 +9,7 @@
 
 <H2>NOTES</H2>
 
-As with most GRASS 3D raster modules, <EM>r3.univar</EM> operates on the cell
+As with most GRASS 3D raster modules, <EM>r3.stats</EM> operates on the cell
 array defined by the current 3D region settings, not the original extent and
 resolution of the input map. See <em><A HREF="g.region.html">g.region</A></em>.
 <P>

Modified: grass/branches/develbranch_6/raster3d/r3.stats/main.c
===================================================================
--- grass/branches/develbranch_6/raster3d/r3.stats/main.c	2011-03-18 08:53:57 UTC (rev 45707)
+++ grass/branches/develbranch_6/raster3d/r3.stats/main.c	2011-03-18 09:25:50 UTC (rev 45708)
@@ -52,16 +52,16 @@
 } equal_val_array;
 
 /*prototypes */
-equal_val_array *alloc_equal_val_array(int count);
-void free_equal_val_array(equal_val_array * vals);
-equal_val_array *add_equal_val_to_array(equal_val_array * array, double val);
-int check_equal_value(equal_val_array * array, double val);
-stat_table *create_stat_table(int nsteps, equal_val_array * values,
+static equal_val_array *alloc_equal_val_array(int count);
+static void free_equal_val_array(equal_val_array * vals);
+static equal_val_array *add_equal_val_to_array(equal_val_array * array, double val);
+static int check_equal_value(equal_val_array * array, double val);
+static stat_table *create_stat_table(int nsteps, equal_val_array * values,
 			      double min, double max);
-void free_stat_table(stat_table * stats);
-void print_stat_table(stat_table * stats);
-void update_stat_table(stat_table * stats, G3D_Region * region);
-void heapsort_eqvals(equal_val_array * data, int n);
+static void free_stat_table(stat_table * stats);
+static void print_stat_table(stat_table * stats);
+static void update_stat_table(stat_table * stats, G3D_Region * region);
+static void heapsort_eqvals(equal_val_array * data, int n);
 static void downheap_eqvals(equal_val_array * data, int n, int k);
 static void check_range_value(stat_table * stats, double value);
 static void tree_search_range(stat_table * stats, int left, int right,
@@ -546,14 +546,14 @@
 
     float val_f;		/* for misc use */
     double val_d;		/* for misc use */
-    stat_table *stats;
+    stat_table *stats = NULL;
     double min, max;
-    equal_val_array *eqvals;
+    equal_val_array *eqvals = NULL;
 
     unsigned int n = 0, nsteps;
     int map_type;
-    char *infile;
-    void *map;
+    char *infile = NULL;
+    void *map = NULL;
     G3D_Region region;
     unsigned int rows, cols, depths;
     unsigned int x, y, z;
@@ -660,18 +660,18 @@
 	    }
 	}
 
-	/* sort the equal values array */
-	G_message(_("Sort non-null values"));
-	heapsort_eqvals(eqvals, eqvals->count);
+	if (eqvals) {
+            /* sort the equal values array */
+            G_message(_("Sort non-null values"));
+            heapsort_eqvals(eqvals, eqvals->count);
 
-	/* create the statistic table with equal values */
-	stats = create_stat_table(eqvals->count, eqvals, 0, 0);
-	/* compute the number of null values */
-	stats->null->count = rows * cols * depths - n;
+            /* create the statistic table with equal values */
+            stats = create_stat_table(eqvals->count, eqvals, 0, 0);
+            /* compute the number of null values */
+            stats->null->count = rows * cols * depths - n;
 
-	if (eqvals)
-	    free_equal_val_array(eqvals);
-
+            free_equal_val_array(eqvals);
+        }
     }
     else {
 
@@ -709,11 +709,14 @@
 	stats->null->count = rows * cols * depths - n;
     }
 
-    /* Compute the volume and percentage */
-    update_stat_table(stats, &region);
-    /* Print the statistics to stdout */
-    print_stat_table(stats);
+    if(stats) {
+        /* Compute the volume and percentage */
+        update_stat_table(stats, &region);
+        /* Print the statistics to stdout */
+        print_stat_table(stats);
 
-    free_stat_table(stats);
+        free_stat_table(stats);
+    }
+    
     exit(EXIT_SUCCESS);
 }



More information about the grass-commit mailing list