[GRASS-SVN] r36918 - in grass/trunk: include lib/stats raster/r.neighbors raster/r.resamp.stats raster/r.series

svn_grass at osgeo.org svn_grass at osgeo.org
Thu Apr 30 03:39:27 EDT 2009


Author: glynn
Date: 2009-04-30 03:39:26 -0400 (Thu, 30 Apr 2009)
New Revision: 36918

Modified:
   grass/trunk/include/stats.h
   grass/trunk/lib/stats/c_ave.c
   grass/trunk/lib/stats/c_count.c
   grass/trunk/lib/stats/c_divr.c
   grass/trunk/lib/stats/c_intr.c
   grass/trunk/lib/stats/c_kurt.c
   grass/trunk/lib/stats/c_max.c
   grass/trunk/lib/stats/c_maxx.c
   grass/trunk/lib/stats/c_median.c
   grass/trunk/lib/stats/c_min.c
   grass/trunk/lib/stats/c_minx.c
   grass/trunk/lib/stats/c_mode.c
   grass/trunk/lib/stats/c_percentile.c
   grass/trunk/lib/stats/c_range.c
   grass/trunk/lib/stats/c_reg.c
   grass/trunk/lib/stats/c_skew.c
   grass/trunk/lib/stats/c_stddev.c
   grass/trunk/lib/stats/c_sum.c
   grass/trunk/lib/stats/c_var.c
   grass/trunk/raster/r.neighbors/main.c
   grass/trunk/raster/r.resamp.stats/main.c
   grass/trunk/raster/r.series/main.c
Log:
Add closure argument to aggregate functions
Export c_quantile, w_quantile
Add method=quantile to r.resamp.stats, r.series, r.neighbors
Add method=quart1/quart3/perc90 to r.neighbors


Modified: grass/trunk/include/stats.h
===================================================================
--- grass/trunk/include/stats.h	2009-04-30 07:36:21 UTC (rev 36917)
+++ grass/trunk/include/stats.h	2009-04-30 07:39:26 UTC (rev 36918)
@@ -4,8 +4,8 @@
 
 #include <grass/gis.h>
 
-typedef void stat_func(DCELL *, DCELL *, int);
-typedef void stat_func_w(DCELL *, DCELL(*)[2], int);
+typedef void stat_func(DCELL *, DCELL *, int, const void *);
+typedef void stat_func_w(DCELL *, DCELL(*)[2], int, const void *);
 
 extern stat_func c_ave;
 extern stat_func c_count;
@@ -27,6 +27,7 @@
 extern stat_func c_quart1;
 extern stat_func c_quart3;
 extern stat_func c_perc90;
+extern stat_func c_quant;
 extern stat_func c_skew;
 extern stat_func c_kurt;
 
@@ -39,6 +40,7 @@
 extern stat_func_w w_quart1;
 extern stat_func_w w_quart3;
 extern stat_func_w w_perc90;
+extern stat_func_w w_quant;
 extern stat_func_w w_reg_m;
 extern stat_func_w w_reg_c;
 extern stat_func_w w_reg_r2;

Modified: grass/trunk/lib/stats/c_ave.c
===================================================================
--- grass/trunk/lib/stats/c_ave.c	2009-04-30 07:36:21 UTC (rev 36917)
+++ grass/trunk/lib/stats/c_ave.c	2009-04-30 07:39:26 UTC (rev 36918)
@@ -1,6 +1,6 @@
 #include <grass/gis.h>
 
-void c_ave(DCELL * result, DCELL * values, int n)
+void c_ave(DCELL * result, DCELL * values, int n, const void *closure)
 {
     DCELL sum;
     int count;
@@ -23,7 +23,7 @@
 	*result = sum / count;
 }
 
-void w_ave(DCELL * result, DCELL(*values)[2], int n)
+void w_ave(DCELL * result, DCELL(*values)[2], int n, const void *closure)
 {
     DCELL sum;
     DCELL count;

Modified: grass/trunk/lib/stats/c_count.c
===================================================================
--- grass/trunk/lib/stats/c_count.c	2009-04-30 07:36:21 UTC (rev 36917)
+++ grass/trunk/lib/stats/c_count.c	2009-04-30 07:39:26 UTC (rev 36918)
@@ -1,6 +1,6 @@
 #include <grass/gis.h>
 
-void c_count(DCELL * result, DCELL * values, int n)
+void c_count(DCELL * result, DCELL * values, int n, const void *closure)
 {
     int count;
     int i;
@@ -14,7 +14,7 @@
     *result = count;
 }
 
-void w_count(DCELL * result, DCELL(*values)[2], int n)
+void w_count(DCELL * result, DCELL(*values)[2], int n, const void *closure)
 {
     DCELL count;
     int i;

Modified: grass/trunk/lib/stats/c_divr.c
===================================================================
--- grass/trunk/lib/stats/c_divr.c	2009-04-30 07:36:21 UTC (rev 36917)
+++ grass/trunk/lib/stats/c_divr.c	2009-04-30 07:39:26 UTC (rev 36918)
@@ -1,7 +1,7 @@
 #include <grass/gis.h>
 #include <grass/stats.h>
 
-void c_divr(DCELL * result, DCELL * values, int n)
+void c_divr(DCELL * result, DCELL * values, int n, const void *closure)
 {
     int count;
     DCELL prev;

Modified: grass/trunk/lib/stats/c_intr.c
===================================================================
--- grass/trunk/lib/stats/c_intr.c	2009-04-30 07:36:21 UTC (rev 36917)
+++ grass/trunk/lib/stats/c_intr.c	2009-04-30 07:39:26 UTC (rev 36918)
@@ -1,7 +1,7 @@
 #include <grass/gis.h>
 #include <grass/stats.h>
 
-void c_intr(DCELL * result, DCELL * values, int n)
+void c_intr(DCELL * result, DCELL * values, int n, const void *closure)
 {
     DCELL center;
     int count;

Modified: grass/trunk/lib/stats/c_kurt.c
===================================================================
--- grass/trunk/lib/stats/c_kurt.c	2009-04-30 07:36:21 UTC (rev 36917)
+++ grass/trunk/lib/stats/c_kurt.c	2009-04-30 07:39:26 UTC (rev 36918)
@@ -1,6 +1,6 @@
 #include <grass/gis.h>
 
-void c_kurt(DCELL * result, DCELL * values, int n)
+void c_kurt(DCELL * result, DCELL * values, int n, const void *closure)
 {
     DCELL sum, ave, sumsq, sumqt, var;
     int count;
@@ -42,7 +42,7 @@
     *result = sumqt / (count * var * var) - 3;
 }
 
-void w_kurt(DCELL * result, DCELL(*values)[2], int n)
+void w_kurt(DCELL * result, DCELL(*values)[2], int n, const void *closure)
 {
     DCELL sum, ave, sumsq, sumqt, var;
     int count;

Modified: grass/trunk/lib/stats/c_max.c
===================================================================
--- grass/trunk/lib/stats/c_max.c	2009-04-30 07:36:21 UTC (rev 36917)
+++ grass/trunk/lib/stats/c_max.c	2009-04-30 07:39:26 UTC (rev 36918)
@@ -1,6 +1,6 @@
 #include <grass/gis.h>
 
-void c_max(DCELL * result, DCELL * values, int n)
+void c_max(DCELL * result, DCELL * values, int n, const void *closure)
 {
     DCELL max;
     int i;
@@ -21,7 +21,7 @@
 	*result = max;
 }
 
-void w_max(DCELL * result, DCELL(*values)[2], int n)
+void w_max(DCELL * result, DCELL(*values)[2], int n, const void *closure)
 {
     DCELL max;
     int i;

Modified: grass/trunk/lib/stats/c_maxx.c
===================================================================
--- grass/trunk/lib/stats/c_maxx.c	2009-04-30 07:36:21 UTC (rev 36917)
+++ grass/trunk/lib/stats/c_maxx.c	2009-04-30 07:39:26 UTC (rev 36918)
@@ -1,6 +1,6 @@
 #include <grass/gis.h>
 
-void c_maxx(DCELL * result, DCELL * values, int n)
+void c_maxx(DCELL * result, DCELL * values, int n, const void *closure)
 {
     DCELL max, maxx;
     int i;

Modified: grass/trunk/lib/stats/c_median.c
===================================================================
--- grass/trunk/lib/stats/c_median.c	2009-04-30 07:36:21 UTC (rev 36917)
+++ grass/trunk/lib/stats/c_median.c	2009-04-30 07:39:26 UTC (rev 36918)
@@ -1,7 +1,7 @@
 #include <grass/gis.h>
 #include <grass/stats.h>
 
-void c_median(DCELL * result, DCELL * values, int n)
+void c_median(DCELL * result, DCELL * values, int n, const void *closure)
 {
     n = sort_cell(values, n);
 
@@ -11,7 +11,7 @@
 	*result = (values[(n - 1) / 2] + values[n / 2]) / 2;
 }
 
-void w_median(DCELL * result, DCELL(*values)[2], int n)
+void w_median(DCELL * result, DCELL(*values)[2], int n, const void *closure)
 {
     DCELL total;
     int i;

Modified: grass/trunk/lib/stats/c_min.c
===================================================================
--- grass/trunk/lib/stats/c_min.c	2009-04-30 07:36:21 UTC (rev 36917)
+++ grass/trunk/lib/stats/c_min.c	2009-04-30 07:39:26 UTC (rev 36918)
@@ -1,6 +1,6 @@
 #include <grass/gis.h>
 
-void c_min(DCELL * result, DCELL * values, int n)
+void c_min(DCELL * result, DCELL * values, int n, const void *closure)
 {
     DCELL min;
     int i;
@@ -21,7 +21,7 @@
 	*result = min;
 }
 
-void w_min(DCELL * result, DCELL(*values)[2], int n)
+void w_min(DCELL * result, DCELL(*values)[2], int n, const void *closure)
 {
     DCELL min;
     int i;

Modified: grass/trunk/lib/stats/c_minx.c
===================================================================
--- grass/trunk/lib/stats/c_minx.c	2009-04-30 07:36:21 UTC (rev 36917)
+++ grass/trunk/lib/stats/c_minx.c	2009-04-30 07:39:26 UTC (rev 36918)
@@ -1,7 +1,7 @@
 #include <grass/gis.h>
 
 
-void c_minx(DCELL * result, DCELL * values, int n)
+void c_minx(DCELL * result, DCELL * values, int n, const void *closure)
 {
     DCELL min, minx;
     int i;

Modified: grass/trunk/lib/stats/c_mode.c
===================================================================
--- grass/trunk/lib/stats/c_mode.c	2009-04-30 07:36:21 UTC (rev 36917)
+++ grass/trunk/lib/stats/c_mode.c	2009-04-30 07:39:26 UTC (rev 36918)
@@ -1,7 +1,7 @@
 #include <grass/gis.h>
 #include <grass/stats.h>
 
-void c_mode(DCELL * result, DCELL * values, int n)
+void c_mode(DCELL * result, DCELL * values, int n, const void *closure)
 {
     DCELL mode;
     int max;
@@ -34,7 +34,7 @@
 	*result = mode;
 }
 
-void w_mode(DCELL * result, DCELL(*values)[2], int n)
+void w_mode(DCELL * result, DCELL(*values)[2], int n, const void *closure)
 {
     DCELL mode;
     DCELL max;

Modified: grass/trunk/lib/stats/c_percentile.c
===================================================================
--- grass/trunk/lib/stats/c_percentile.c	2009-04-30 07:36:21 UTC (rev 36917)
+++ grass/trunk/lib/stats/c_percentile.c	2009-04-30 07:39:26 UTC (rev 36918)
@@ -2,8 +2,9 @@
 #include <grass/gis.h>
 #include <grass/stats.h>
 
-static void percentile(DCELL * result, DCELL * values, int n, double percent)
+void c_quant(DCELL * result, DCELL * values, int n, const void *closure)
 {
+    double quant = *(const double *)closure;
     double k;
     int i0, i1;
 
@@ -14,7 +15,7 @@
 	return;
     }
 
-    k = n * percent / 100;
+    k = n * quant;
     i0 = (int)floor(k);
     i1 = (int)ceil(k);
 
@@ -23,24 +24,27 @@
 	: values[i0] * (i1 - k) + values[i1] * (k - i0);
 }
 
-void c_quart1(DCELL * result, DCELL * values, int n)
+void c_quart1(DCELL * result, DCELL * values, int n, const void *closure)
 {
-    percentile(result, values, n, 25.0);
+    static const double q = 0.25;
+    c_quant(result, values, n, &q);
 }
 
-void c_quart3(DCELL * result, DCELL * values, int n)
+void c_quart3(DCELL * result, DCELL * values, int n, const void *closure)
 {
-    percentile(result, values, n, 75.0);
+    static const double q = 0.75;
+    c_quant(result, values, n, &q);
 }
 
-void c_perc90(DCELL * result, DCELL * values, int n)
+void c_perc90(DCELL * result, DCELL * values, int n, const void *closure)
 {
-    percentile(result, values, n, 90.0);
+    static const double q = 0.90;
+    c_quant(result, values, n, &q);
 }
 
-static void percentile_w(DCELL * result, DCELL(*values)[2], int n,
-			 double percent)
+void w_quant(DCELL * result, DCELL(*values)[2], int n, const void *closure)
 {
+    double quant = *(const double *)closure;
     DCELL total;
     int i;
     DCELL k;
@@ -59,24 +63,27 @@
     k = 0.0;
     for (i = 0; i < n; i++) {
 	k += values[i][1];
-	if (k >= total * percent / 100)
+	if (k >= total * quant)
 	    break;
     }
 
     *result = values[i][0];
 }
 
-void w_quart1(DCELL * result, DCELL(*values)[2], int n)
+void w_quart1(DCELL * result, DCELL(*values)[2], int n, const void *closure)
 {
-    percentile_w(result, values, n, 25.0);
+    static const double q = 0.25;
+    w_quant(result, values, n, &q);
 }
 
-void w_quart3(DCELL * result, DCELL(*values)[2], int n)
+void w_quart3(DCELL * result, DCELL(*values)[2], int n, const void *closure)
 {
-    percentile_w(result, values, n, 75.0);
+    static const double q = 0.75;
+    w_quant(result, values, n, &q);
 }
 
-void w_perc90(DCELL * result, DCELL(*values)[2], int n)
+void w_perc90(DCELL * result, DCELL(*values)[2], int n, const void *closure)
 {
-    percentile_w(result, values, n, 90.0);
+    static const double q = 0.90;
+    w_quant(result, values, n, &q);
 }

Modified: grass/trunk/lib/stats/c_range.c
===================================================================
--- grass/trunk/lib/stats/c_range.c	2009-04-30 07:36:21 UTC (rev 36917)
+++ grass/trunk/lib/stats/c_range.c	2009-04-30 07:39:26 UTC (rev 36918)
@@ -1,6 +1,6 @@
 #include <grass/gis.h>
 
-void c_range(DCELL * result, DCELL * values, int n)
+void c_range(DCELL * result, DCELL * values, int n, const void *closure)
 {
     DCELL min, max;
     int i;

Modified: grass/trunk/lib/stats/c_reg.c
===================================================================
--- grass/trunk/lib/stats/c_reg.c	2009-04-30 07:36:21 UTC (rev 36917)
+++ grass/trunk/lib/stats/c_reg.c	2009-04-30 07:39:26 UTC (rev 36918)
@@ -73,17 +73,17 @@
 	G_set_d_null_value(result, 1);
 }
 
-void c_reg_m(DCELL * result, DCELL * values, int n)
+void c_reg_m(DCELL * result, DCELL * values, int n, const void *closure)
 {
     regression(result, values, n, REGRESSION_SLOPE);
 }
 
-void c_reg_c(DCELL * result, DCELL * values, int n)
+void c_reg_c(DCELL * result, DCELL * values, int n, const void *closure)
 {
     regression(result, values, n, REGRESSION_OFFSET);
 }
 
-void c_reg_r2(DCELL * result, DCELL * values, int n)
+void c_reg_r2(DCELL * result, DCELL * values, int n, const void *closure)
 {
     regression(result, values, n, REGRESSION_COEFF_DET);
 }
@@ -157,17 +157,17 @@
 	G_set_d_null_value(result, 1);
 }
 
-void w_reg_m(DCELL * result, DCELL(*values)[2], int n)
+void w_reg_m(DCELL * result, DCELL(*values)[2], int n, const void *closure)
 {
     regression_w(result, values, n, REGRESSION_SLOPE);
 }
 
-void w_reg_c(DCELL * result, DCELL(*values)[2], int n)
+void w_reg_c(DCELL * result, DCELL(*values)[2], int n, const void *closure)
 {
     regression_w(result, values, n, REGRESSION_OFFSET);
 }
 
-void w_reg_r2(DCELL * result, DCELL(*values)[2], int n)
+void w_reg_r2(DCELL * result, DCELL(*values)[2], int n, const void *closure)
 {
     regression_w(result, values, n, REGRESSION_COEFF_DET);
 }

Modified: grass/trunk/lib/stats/c_skew.c
===================================================================
--- grass/trunk/lib/stats/c_skew.c	2009-04-30 07:36:21 UTC (rev 36917)
+++ grass/trunk/lib/stats/c_skew.c	2009-04-30 07:39:26 UTC (rev 36918)
@@ -1,7 +1,7 @@
 #include <math.h>
 #include <grass/gis.h>
 
-void c_skew(DCELL * result, DCELL * values, int n)
+void c_skew(DCELL * result, DCELL * values, int n, const void *closure)
 {
     DCELL sum, ave, sumsq, sumcb, sdev;
     int count;
@@ -43,7 +43,7 @@
     *result = sumcb / (count * sdev * sdev * sdev);
 }
 
-void w_skew(DCELL * result, DCELL(*values)[2], int n)
+void w_skew(DCELL * result, DCELL(*values)[2], int n, const void *closure)
 {
     DCELL sum, ave, sumsq, sumcb, sdev;
     int count;

Modified: grass/trunk/lib/stats/c_stddev.c
===================================================================
--- grass/trunk/lib/stats/c_stddev.c	2009-04-30 07:36:21 UTC (rev 36917)
+++ grass/trunk/lib/stats/c_stddev.c	2009-04-30 07:39:26 UTC (rev 36918)
@@ -2,11 +2,11 @@
 #include <grass/gis.h>
 #include <grass/stats.h>
 
-void c_stddev(DCELL * result, DCELL * values, int n)
+void c_stddev(DCELL * result, DCELL * values, int n, const void *closure)
 {
     DCELL var;
 
-    c_var(&var, values, n);
+    c_var(&var, values, n, closure);
 
     if (G_is_d_null_value(&var))
 	G_set_d_null_value(result, 1);
@@ -14,11 +14,11 @@
 	*result = sqrt(var);
 }
 
-void w_stddev(DCELL * result, DCELL(*values)[2], int n)
+void w_stddev(DCELL * result, DCELL(*values)[2], int n, const void *closure)
 {
     DCELL var;
 
-    w_var(&var, values, n);
+    w_var(&var, values, n, closure);
 
     if (G_is_d_null_value(&var))
 	G_set_d_null_value(result, 1);

Modified: grass/trunk/lib/stats/c_sum.c
===================================================================
--- grass/trunk/lib/stats/c_sum.c	2009-04-30 07:36:21 UTC (rev 36917)
+++ grass/trunk/lib/stats/c_sum.c	2009-04-30 07:39:26 UTC (rev 36918)
@@ -1,6 +1,6 @@
 #include <grass/gis.h>
 
-void c_sum(DCELL * result, DCELL * values, int n)
+void c_sum(DCELL * result, DCELL * values, int n, const void *closure)
 {
     DCELL sum;
     int count;
@@ -23,7 +23,7 @@
 	*result = sum;
 }
 
-void w_sum(DCELL * result, DCELL(*values)[2], int n)
+void w_sum(DCELL * result, DCELL(*values)[2], int n, const void *closure)
 {
     DCELL sum;
     DCELL count;

Modified: grass/trunk/lib/stats/c_var.c
===================================================================
--- grass/trunk/lib/stats/c_var.c	2009-04-30 07:36:21 UTC (rev 36917)
+++ grass/trunk/lib/stats/c_var.c	2009-04-30 07:39:26 UTC (rev 36918)
@@ -1,6 +1,6 @@
 #include <grass/gis.h>
 
-void c_var(DCELL * result, DCELL * values, int n)
+void c_var(DCELL * result, DCELL * values, int n, const void *closure)
 {
     DCELL sum, ave, sumsq;
     int count;
@@ -39,7 +39,7 @@
     *result = sumsq / count;
 }
 
-void w_var(DCELL * result, DCELL(*values)[2], int n)
+void w_var(DCELL * result, DCELL(*values)[2], int n, const void *closure)
 {
     DCELL sum, ave, sumsq;
     int count;

Modified: grass/trunk/raster/r.neighbors/main.c
===================================================================
--- grass/trunk/raster/r.neighbors/main.c	2009-04-30 07:36:21 UTC (rev 36917)
+++ grass/trunk/raster/r.neighbors/main.c	2009-04-30 07:39:26 UTC (rev 36918)
@@ -56,6 +56,10 @@
      "number of different values"},
     {c_intr, NULL, intr_cats, 0, 0, "interspersion",
      "number of values different than center value"},
+    {c_quart1, w_quart1, NO_CATS, 1, 0, "quart1", "first quartile"},
+    {c_quart3, w_quart3, NO_CATS, 1, 0, "quart3", "third quartile"},
+    {c_perc90, w_perc90, NO_CATS, 1, 0, "perc90", "ninetieth percentile"},
+    {c_quant, w_quant, NO_CATS, 1, 0, "quantile", "arbitrary quantile"},
     {0, 0, 0, 0, 0, 0, 0}
 };
 
@@ -78,6 +82,8 @@
     stat_func *newvalue;
     stat_func_w *newvalue_w;
     ifunc cat_names;
+    double quantile;
+    const void *closure;
     struct Colors colr;
     struct Cell_head cellhd;
     struct Cell_head window;
@@ -90,6 +96,7 @@
 	struct Option *title;
 	struct Option *weight;
 	struct Option *gauss;
+	struct Option *quantile;
     } parm;
     struct
     {
@@ -159,6 +166,14 @@
     parm.gauss->required = NO;
     parm.gauss->description = _("Sigma (in cells) for Gaussian filter");
 
+    parm.quantile = G_define_option();
+    parm.quantile->key = "quantile";
+    parm.quantile->type = TYPE_DOUBLE;
+    parm.quantile->required = NO;
+    parm.quantile->description = _("Quantile to calculate for method=quantile");
+    parm.quantile->options = "0.0-1.0";
+    parm.quantile->answer = "0.5";
+
     flag.align = G_define_flag();
     flag.align->key = 'a';
     flag.align->description = _("Do not align output with the input");
@@ -216,6 +231,11 @@
 	exit(EXIT_FAILURE);
     }
 
+    if (menu[method].method == c_quant) {
+	quantile = atoi(parm.quantile->answer);
+	closure = &quantile;
+    }
+
     half = (map_type == CELL_TYPE) ? menu[method].half : 0;
 
     /* establish the newvalue routine */
@@ -297,9 +317,9 @@
 		G_set_d_null_value(rp, 1);
 	    else {
 		if (newvalue_w)
-		    newvalue_w(rp, values_w, n);
+		    newvalue_w(rp, values_w, n, closure);
 		else
-		    newvalue(rp, values, n);
+		    newvalue(rp, values, n, closure);
 
 		if (half && !G_is_d_null_value(rp))
 		    *rp += 0.5;

Modified: grass/trunk/raster/r.resamp.stats/main.c
===================================================================
--- grass/trunk/raster/r.resamp.stats/main.c	2009-04-30 07:36:21 UTC (rev 36917)
+++ grass/trunk/raster/r.resamp.stats/main.c	2009-04-30 07:39:26 UTC (rev 36918)
@@ -38,6 +38,7 @@
     {c_sum,    w_sum,    "sum",      "sum of values"},
     {c_var,    w_var,    "variance", "variance value"},
     {c_stddev, w_stddev, "stddev",   "standard deviation"},
+    {c_quant,  w_quant,  "quantile", "arbitrary quantile"},
     {NULL, NULL, NULL}
 };
 
@@ -77,7 +78,9 @@
 static DCELL *outbuf;
 static DCELL **bufs;
 static int method;
+static const void *closure;
 static int row_scale, col_scale;
+static double quantile;
 
 static void resamp_unweighted(void)
 {
@@ -141,7 +144,7 @@
 	    if (null && nulls)
 		G_set_d_null_value(&outbuf[col], 1);
 	    else
-		(*method_fn) (&outbuf[col], values, n);
+		(*method_fn) (&outbuf[col], values, n, closure);
 	}
 
 	G_set_window(&dst_w);
@@ -227,7 +230,7 @@
 	    if (null && nulls)
 		G_set_d_null_value(&outbuf[col], 1);
 	    else
-		(*method_fn) (&outbuf[col], values, n);
+		(*method_fn) (&outbuf[col], values, n, closure);
 	}
 
 	G_set_window(&dst_w);
@@ -240,7 +243,7 @@
     struct GModule *module;
     struct
     {
-	struct Option *rastin, *rastout, *method;
+	struct Option *rastin, *rastout, *method, *quantile;
     } parm;
     struct
     {
@@ -271,6 +274,14 @@
     parm.method->options = build_method_list();
     parm.method->answer = "average";
 
+    parm.quantile = G_define_option();
+    parm.quantile->key = "quantile";
+    parm.quantile->type = TYPE_DOUBLE;
+    parm.quantile->required = NO;
+    parm.quantile->description = _("Quantile to calculate for method=quantile");
+    parm.quantile->options = "0.0-1.0";
+    parm.quantile->answer = "0.5";
+
     flag.nulls = G_define_flag();
     flag.nulls->key = 'n';
     flag.nulls->description = _("Propagate NULLs");
@@ -288,6 +299,11 @@
     if (method < 0)
 	G_fatal_error(_("Unknown method <%s>"), parm.method->answer);
 
+    if (menu[method].method == c_quant) {
+	quantile = atoi(parm.quantile->answer);
+	closure = &quantile;
+    }
+
     G_get_set_window(&dst_w);
 
     /* set window to old map */

Modified: grass/trunk/raster/r.series/main.c
===================================================================
--- grass/trunk/raster/r.series/main.c	2009-04-30 07:36:21 UTC (rev 36917)
+++ grass/trunk/raster/r.series/main.c	2009-04-30 07:39:26 UTC (rev 36918)
@@ -47,6 +47,7 @@
     {c_quart1, 0, "quart1",     "first quartile"},
     {c_quart3, 0, "quart3",     "third quartile"},
     {c_perc90, 0, "perc90",     "ninetieth percentile"},
+    {c_quant,  0, "quantile",   "arbitrary quantile"},
     {c_skew,   0, "skewness",   "skewness"},
     {c_kurt,   0, "kurtosis",   "kurtosis"},
     {NULL,     0, NULL,         NULL}
@@ -65,6 +66,7 @@
     int fd;
     DCELL *buf;
     stat_func *method_fn;
+    double quantile;
 };
 
 static char *build_method_list(void)
@@ -104,7 +106,7 @@
     struct GModule *module;
     struct
     {
-	struct Option *input, *output, *method, *range;
+	struct Option *input, *output, *method, *quantile, *range;
     } parm;
     struct
     {
@@ -143,6 +145,14 @@
     parm.method->description = _("Aggregate operation");
     parm.method->multiple = YES;
 
+    parm.quantile = G_define_option();
+    parm.quantile->key = "quantile";
+    parm.quantile->type = TYPE_DOUBLE;
+    parm.quantile->required = NO;
+    parm.quantile->description = _("Quantile to calculate for method=quantile");
+    parm.quantile->options = "0.0-1.0";
+    parm.quantile->multiple = YES;
+
     parm.range = G_define_option();
     parm.range->key = "range";
     parm.range->type = TYPE_DOUBLE;
@@ -203,6 +213,9 @@
 
 	out->name = output_name;
 	out->method_fn = menu[method].method;
+	out->quantile = (parm.quantile->answer && parm.quantile->answers[i])
+	    ? atof(parm.quantile->answers[i])
+	    : 0;
 	out->buf = G_allocate_d_raster_buf();
 	out->fd = G_open_raster_new(
 	    output_name, menu[method].is_int ? CELL_TYPE : DCELL_TYPE);
@@ -249,7 +262,7 @@
 		    G_set_d_null_value(&out->buf[col], 1);
 		else {
 		    memcpy(values_tmp, values, num_inputs * sizeof(DCELL));
-		    (*out->method_fn)(&out->buf[col], values_tmp, num_inputs);
+		    (*out->method_fn)(&out->buf[col], values_tmp, num_inputs, &out->quantile);
 		}
 	    }
 	}



More information about the grass-commit mailing list