浏览代码

add flag to print only bin number and cell counts

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@60101 15284696-431f-4ddb-bdfa-cd5b030d7da7
Hamish Bowman 11 年之前
父节点
当前提交
d98b23b1aa
共有 3 个文件被更改,包括 27 次插入15 次删除
  1. 1 1
      raster3d/r3.stats/local_proto.h
  2. 8 4
      raster3d/r3.stats/main.c
  3. 18 10
      raster3d/r3.stats/support.c

+ 1 - 1
raster3d/r3.stats/local_proto.h

@@ -40,7 +40,7 @@ int check_equal_value(equal_val_array * array, double val);
 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);

+ 8 - 4
raster3d/r3.stats/main.c

@@ -39,7 +39,7 @@ int main(int argc, char *argv[])
     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 @@ int main(int argc, char *argv[])
     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 @@ int main(int argc, char *argv[])
     }
     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 @@ int main(int argc, char *argv[])
     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);
     }

+ 18 - 10
raster3d/r3.stats/support.c

@@ -246,7 +246,7 @@ void update_stat_table(stat_table *stats, RASTER3D_Region *region)
 /* *************************************************************** */
 /* *************************************************************** */
 /* *************************************************************** */
-void print_stat_table(stat_table *stats)
+void print_stat_table(stat_table *stats, int counts_only)
 {
     int i;
 
@@ -269,6 +269,13 @@ void print_stat_table(stat_table *stats)
 	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,16 +295,17 @@ void print_stat_table(stat_table *stats)
 		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);
-
-    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);
+    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);
+    }
 
     return;
 }