[GRASS-SVN] r60101 - grass/trunk/raster3d/r3.stats

svn_grass at osgeo.org svn_grass at osgeo.org
Mon May 5 02:06:44 PDT 2014


Author: hamish
Date: 2014-05-05 02:06:44 -0700 (Mon, 05 May 2014)
New Revision: 60101

Modified:
   grass/trunk/raster3d/r3.stats/local_proto.h
   grass/trunk/raster3d/r3.stats/main.c
   grass/trunk/raster3d/r3.stats/support.c
Log:
add flag to print only bin number and cell counts

Modified: grass/trunk/raster3d/r3.stats/local_proto.h
===================================================================
--- grass/trunk/raster3d/r3.stats/local_proto.h	2014-05-05 08:50:41 UTC (rev 60100)
+++ grass/trunk/raster3d/r3.stats/local_proto.h	2014-05-05 09:06:44 UTC (rev 60101)
@@ -40,7 +40,7 @@
 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 print_stat_table(stat_table *stats, int);
 void update_stat_table(stat_table *stats, RASTER3D_Region *region);
 void heapsort_eqvals(equal_val_array *data, int n);
 void downheap_eqvals(equal_val_array *data, int n, int k);

Modified: grass/trunk/raster3d/r3.stats/main.c
===================================================================
--- grass/trunk/raster3d/r3.stats/main.c	2014-05-05 08:50:41 UTC (rev 60100)
+++ grass/trunk/raster3d/r3.stats/main.c	2014-05-05 09:06:44 UTC (rev 60101)
@@ -39,7 +39,7 @@
     unsigned int x, y, z;
 
     struct Option *inputfile, *steps;
-    struct Flag *equal;
+    struct Flag *equal, *counts_only;
     struct GModule *module;
 
     G_gisinit(argv[0]);
@@ -60,12 +60,15 @@
     steps->answer = "20";
     steps->description = _("Number of subranges to collect stats from");
 
-
     equal = G_define_flag();
     equal->key = 'e';
     equal->description =
 	_("Calculate statistics based on equal value groups");
 
+    counts_only = G_define_flag();
+    counts_only->key = 'c';
+    counts_only->description = _("Only print cell counts");
+
     if (G_parser(argc, argv))
 	exit(EXIT_FAILURE);
 
@@ -156,7 +159,7 @@
     }
     else {
 
-	/*create the statistic table based on value ranges */
+	/* create the statistic table based on value ranges */
 
 	/* get the range of the map */
 	Rast3d_range_load(map);
@@ -193,8 +196,9 @@
     if(stats) {
         /* Compute the volume and percentage */
         update_stat_table(stats, &region);
+
         /* Print the statistics to stdout */
-        print_stat_table(stats);
+        print_stat_table(stats, counts_only->answer);
 
         free_stat_table(stats);
     }

Modified: grass/trunk/raster3d/r3.stats/support.c
===================================================================
--- grass/trunk/raster3d/r3.stats/support.c	2014-05-05 08:50:41 UTC (rev 60100)
+++ grass/trunk/raster3d/r3.stats/support.c	2014-05-05 09:06:44 UTC (rev 60101)
@@ -246,7 +246,7 @@
 /* *************************************************************** */
 /* *************************************************************** */
 /* *************************************************************** */
-void print_stat_table(stat_table *stats)
+void print_stat_table(stat_table *stats, int counts_only)
 {
     int i;
 
@@ -269,6 +269,13 @@
 	fprintf(stdout, "\nNumber of groups with equal values: %i",
 		stats->nsteps);
     }
+    else if (counts_only) {
+	for (i = 0; i < stats->nsteps; i++) {
+	    fprintf(stdout, "%d %ld\n",
+		    stats->table[i]->num, stats->table[i]->count);
+	}
+	fprintf(stdout, "* %ld\n", stats->null->count);
+    }
     else {
 	/*       1234567   012345678901234567   012345678901234567   0123456789012   0123456   0123456789 */
 	fprintf(stdout,
@@ -288,17 +295,18 @@
 		stats->null->count);
     }
 
-    fprintf(stdout,
-	    "\nSum of non Null cells: \n\tVolume = %13.3lf \n\tPercentage = %7.3lf  \n\tCell count = %i\n",
-	    stats->sum_vol, stats->sum_perc, stats->sum_count);
+    if (!counts_only) {
+	fprintf(stdout,
+		"\nSum of non Null cells: \n\tVolume = %13.3lf \n\tPercentage = %7.3lf  \n\tCell count = %i\n",
+		stats->sum_vol, stats->sum_perc, stats->sum_count);
 
-    fprintf(stdout,
-	    "\nSum of all cells: \n\tVolume = %13.3lf \n\tPercentage = %7.3lf  \n\tCell count = %i\n",
-	    stats->sum_vol + stats->null->vol,
-	    stats->sum_perc + stats->null->perc,
-	    stats->sum_count + stats->null->count);
+	fprintf(stdout,
+		"\nSum of all cells: \n\tVolume = %13.3lf \n\tPercentage = %7.3lf  \n\tCell count = %i\n",
+		stats->sum_vol + stats->null->vol,
+		stats->sum_perc + stats->null->perc,
+		stats->sum_count + stats->null->count);
+    }
 
-
     return;
 }
 



More information about the grass-commit mailing list