[GRASS-SVN] r34224 - grass/branches/develbranch_6/raster/r.quantile

svn_grass at osgeo.org svn_grass at osgeo.org
Mon Nov 10 02:37:43 EST 2008


Author: neteler
Date: 2008-11-10 02:37:43 -0500 (Mon, 10 Nov 2008)
New Revision: 34224

Modified:
   grass/branches/develbranch_6/raster/r.quantile/main.c
Log:
dylan/glynn: Add flag to output recode table (ticket 358) (merge from trunk, r34219)

Modified: grass/branches/develbranch_6/raster/r.quantile/main.c
===================================================================
--- grass/branches/develbranch_6/raster/r.quantile/main.c	2008-11-10 07:14:51 UTC (rev 34223)
+++ grass/branches/develbranch_6/raster/r.quantile/main.c	2008-11-10 07:37:43 UTC (rev 34224)
@@ -188,9 +188,10 @@
     G_message(_("Computing quantiles"));
 }
 
-static void compute_quantiles(void)
+static void compute_quantiles(int recode)
 {
     struct bin *b = &bins[0];
+    double prev_v = min;
     int quant;
 
     for (quant = 0; quant < num_quants; quant++) {
@@ -210,8 +211,16 @@
 	    : values[b->base + i0] * (i1 - k) + values[b->base + i1] * (k -
 									i0);
 
-	printf("%d:%f:%f\n", quant, 100 * quants[quant], v);
+	if (recode)
+	    printf("%f:%f:%i\n", prev_v, v, quant + 1);
+	else
+	    printf("%d:%f:%f\n", quant, 100 * quants[quant], v);
+
+	prev_v = v;
     }
+
+    if (recode)
+	printf("%f:%f:%i\n", prev_v, max, num_quants + 1);
 }
 
 int main(int argc, char *argv[])
@@ -221,6 +230,10 @@
     {
 	struct Option *input, *quant, *perc, *slots;
     } opt;
+    struct {
+	struct Flag *r;
+    } flag;
+    int recode;
     int infile;
     struct FPRange range;
 
@@ -253,10 +266,15 @@
     opt.slots->description = _("Number of bins to use");
     opt.slots->answer = "1000000";
 
+    flag.r = G_define_flag();
+    flag.r->key = 'r';
+    flag.r->description = _("Generate recode rules based on quantile-defined intervals.");
+ 
     if (G_parser(argc, argv))
 	exit(EXIT_FAILURE);
 
     num_slots = atoi(opt.slots->answer);
+    recode = flag.r->answer;
 
     if (opt.perc->answer) {
 	int i;
@@ -305,7 +323,7 @@
     G_free(slot_bins);
 
     sort_bins();
-    compute_quantiles();
+    compute_quantiles(recode);
 
     return (EXIT_SUCCESS);
 }



More information about the grass-commit mailing list