[GRASS-SVN] r61374 - in grass/branches/releasebranch_7_0: . raster3d/r3.stats

svn_grass at osgeo.org svn_grass at osgeo.org
Wed Jul 23 06:24:57 PDT 2014


Author: neteler
Date: 2014-07-23 06:24:57 -0700 (Wed, 23 Jul 2014)
New Revision: 61374

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


Property changes on: grass/branches/releasebranch_7_0
___________________________________________________________________
Modified: svn:mergeinfo
   - /grass/trunk:59505,59646,60100,60215,60219,60278,60376,60610,60807,60835,60936-60937,61159-61160,61165,61275,61288,61290,61292,61294,61301
   + /grass/trunk:59505,59646,60100-60101,60215,60219,60278,60376,60610,60807,60835,60936-60937,61159-61160,61165,61275,61288,61290,61292,61294,61301

Modified: grass/branches/releasebranch_7_0/raster3d/r3.stats/local_proto.h
===================================================================
--- grass/branches/releasebranch_7_0/raster3d/r3.stats/local_proto.h	2014-07-23 13:22:59 UTC (rev 61373)
+++ grass/branches/releasebranch_7_0/raster3d/r3.stats/local_proto.h	2014-07-23 13:24:57 UTC (rev 61374)
@@ -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/branches/releasebranch_7_0/raster3d/r3.stats/main.c
===================================================================
--- grass/branches/releasebranch_7_0/raster3d/r3.stats/main.c	2014-07-23 13:22:59 UTC (rev 61373)
+++ grass/branches/releasebranch_7_0/raster3d/r3.stats/main.c	2014-07-23 13:24:57 UTC (rev 61374)
@@ -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/branches/releasebranch_7_0/raster3d/r3.stats/support.c
===================================================================
--- grass/branches/releasebranch_7_0/raster3d/r3.stats/support.c	2014-07-23 13:22:59 UTC (rev 61373)
+++ grass/branches/releasebranch_7_0/raster3d/r3.stats/support.c	2014-07-23 13:24:57 UTC (rev 61374)
@@ -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