[GRASS-SVN] r41377 -
grass/branches/releasebranch_6_4/raster/r.univar2
svn_grass at osgeo.org
svn_grass at osgeo.org
Wed Mar 10 11:52:35 EST 2010
Author: hamish
Date: 2010-03-10 11:52:33 -0500 (Wed, 10 Mar 2010)
New Revision: 41377
Modified:
grass/branches/releasebranch_6_4/raster/r.univar2/globals.h
grass/branches/releasebranch_6_4/raster/r.univar2/r.univar.html
grass/branches/releasebranch_6_4/raster/r.univar2/r.univar_main.c
grass/branches/releasebranch_6_4/raster/r.univar2/r3.univar.html
grass/branches/releasebranch_6_4/raster/r.univar2/r3.univar_main.c
grass/branches/releasebranch_6_4/raster/r.univar2/stats.c
Log:
support for non-integer percentiles (trac #873; merge from devbr6)
Modified: grass/branches/releasebranch_6_4/raster/r.univar2/globals.h
===================================================================
--- grass/branches/releasebranch_6_4/raster/r.univar2/globals.h 2010-03-10 00:39:39 UTC (rev 41376)
+++ grass/branches/releasebranch_6_4/raster/r.univar2/globals.h 2010-03-10 16:52:33 UTC (rev 41377)
@@ -30,7 +30,7 @@
double min;
double max;
unsigned int n_perc;
- int *perc;
+ double *perc;
double sum_abs;
int n;
int size;
Modified: grass/branches/releasebranch_6_4/raster/r.univar2/r.univar.html
===================================================================
--- grass/branches/releasebranch_6_4/raster/r.univar2/r.univar.html 2010-03-10 00:39:39 UTC (rev 41376)
+++ grass/branches/releasebranch_6_4/raster/r.univar2/r.univar.html 2010-03-10 16:52:33 UTC (rev 41377)
@@ -9,6 +9,7 @@
If the <b>-g</b> flag is given the results are presented in a format suitable
for use in a shell script.
+
<h2>NOTES</h2>
As with most GRASS raster modules, <em>r.univar</em> operates on the cell
@@ -22,8 +23,6 @@
<p>
The <em>r.quantile</em> module will be significantly more efficient for
calculating percentiles with large maps.
-In this version of the program the percentile option only calculates on
-whole integer values.
<h2>TODO</h2>
@@ -31,7 +30,6 @@
<i>mode, skewness, kurtosis</i>
-
<h2>SEE ALSO</h2>
<em>
Modified: grass/branches/releasebranch_6_4/raster/r.univar2/r.univar_main.c
===================================================================
--- grass/branches/releasebranch_6_4/raster/r.univar2/r.univar_main.c 2010-03-10 00:39:39 UTC (rev 41376)
+++ grass/branches/releasebranch_6_4/raster/r.univar2/r.univar_main.c 2010-03-10 16:52:33 UTC (rev 41377)
@@ -31,7 +31,7 @@
param.percentile = G_define_option();
param.percentile->key = "percentile";
- param.percentile->type = TYPE_INTEGER;
+ param.percentile->type = TYPE_DOUBLE;
param.percentile->required = NO;
param.percentile->multiple = YES;
param.percentile->options = "0-100";
@@ -166,7 +166,7 @@
i++;
stats = create_univar_stat_struct(map_type, size, i);
for (i = 0; i < stats->n_perc; i++) {
- sscanf(param.percentile->answers[i], "%i", &stats->perc[i]);
+ sscanf(param.percentile->answers[i], "%lf", &stats->perc[i]);
}
/* . */
Modified: grass/branches/releasebranch_6_4/raster/r.univar2/r3.univar.html
===================================================================
--- grass/branches/releasebranch_6_4/raster/r.univar2/r3.univar.html 2010-03-10 00:39:39 UTC (rev 41376)
+++ grass/branches/releasebranch_6_4/raster/r.univar2/r3.univar.html 2010-03-10 16:52:33 UTC (rev 41377)
@@ -9,6 +9,7 @@
If the <b>-g</b> flag is given the results are presented in a format suitable
for use in a shell script.
+
<h2>NOTES</h2>
As with most GRASS raster3d modules, <em>r3.univar</em> operates on the cell
@@ -24,9 +25,6 @@
The <em>r.quantile</em> module will be significantly more efficient for
calculating percentiles with large maps.
-->
-<p>
-In this version of the program the percentile option only calculates on
-whole integer values.
<h2>TODO</h2>
@@ -34,7 +32,6 @@
<i>mode, skewness, kurtosis</i>
-
<h2>SEE ALSO</h2>
<em>
Modified: grass/branches/releasebranch_6_4/raster/r.univar2/r3.univar_main.c
===================================================================
--- grass/branches/releasebranch_6_4/raster/r.univar2/r3.univar_main.c 2010-03-10 00:39:39 UTC (rev 41376)
+++ grass/branches/releasebranch_6_4/raster/r.univar2/r3.univar_main.c 2010-03-10 16:52:33 UTC (rev 41377)
@@ -30,7 +30,7 @@
param.percentile = G_define_option();
param.percentile->key = "percentile";
- param.percentile->type = TYPE_INTEGER;
+ param.percentile->type = TYPE_DOUBLE;
param.percentile->required = NO;
param.percentile->multiple = YES;
param.percentile->options = "0-100";
@@ -118,7 +118,7 @@
i++;
stats = create_univar_stat_struct(map_type, cols * rows * depths, i);
for (i = 0; i < stats->n_perc; i++) {
- sscanf(param.percentile->answers[i], "%i", &stats->perc[i]);
+ sscanf(param.percentile->answers[i], "%lf", &stats->perc[i]);
}
stats->n = 0;
Modified: grass/branches/releasebranch_6_4/raster/r.univar2/stats.c
===================================================================
--- grass/branches/releasebranch_6_4/raster/r.univar2/stats.c 2010-03-10 00:39:39 UTC (rev 41376)
+++ grass/branches/releasebranch_6_4/raster/r.univar2/stats.c 2010-03-10 16:52:33 UTC (rev 41377)
@@ -28,7 +28,7 @@
stats->max = 0.0 / 0.0; /*set to nan as default */
stats->n_perc = n_perc;
if (n_perc > 0)
- stats->perc = (int *)G_malloc(n_perc * sizeof(int));
+ stats->perc = (double *)G_malloc(n_perc * sizeof(double));
else
stats->perc = NULL;
stats->sum_abs = 0.0;
@@ -203,8 +203,10 @@
fprintf(stdout, "median=%g\n", median);
fprintf(stdout, "third_quartile=%g\n", quartile_75);
for (i = 0; i < stats->n_perc; i++) {
- fprintf(stdout, "percentile_%d=%g\n", stats->perc[i],
- quartile_perc[i]);
+ char buf[24];
+ sprintf(buf, "%.15g", stats->perc[i]);
+ G_strchg(buf, '.', '_');
+ fprintf(stdout, "percentile_%s=%g\n", buf, quartile_perc[i]);
}
}
else {
@@ -218,18 +220,38 @@
for (i = 0; i < stats->n_perc; i++) {
- if (stats->perc[i] % 10 == 1 && stats->perc[i] != 11)
- fprintf(stdout, "%dst percentile: %g\n", stats->perc[i],
+ if (stats->perc[i] == (int)stats->perc[i]) {
+ /* percentile is an exact integer */
+ if ((int)stats->perc[i] % 10 == 1 && (int)stats->perc[i] != 11)
+ fprintf(stdout, "%dst percentile: %g\n", (int)stats->perc[i],
+ quartile_perc[i]);
+ else if ((int)stats->perc[i] % 10 == 2 && (int)stats->perc[i] != 12)
+ fprintf(stdout, "%dnd percentile: %g\n", (int)stats->perc[i],
+ quartile_perc[i]);
+ else if ((int)stats->perc[i] % 10 == 3 && (int)stats->perc[i] != 13)
+ fprintf(stdout, "%drd percentile: %g\n", (int)stats->perc[i],
+ quartile_perc[i]);
+ else
+ fprintf(stdout, "%dth percentile: %g\n", (int)stats->perc[i],
+ quartile_perc[i]);
+ }
+ else {
+ /* percentile is not an exact integer */
+/*
+ char buf[24], suffix[3];
+ sprintf(buf, "%.15g", stats->perc[i]);
+ if (buf[strlen(buf)-1] == '1')
+ strcpy(suffix, "st");
+ else if (buf[strlen(buf)-1] == '2')
+ strcpy(suffix, "nd");
+ else if (buf[strlen(buf)-1] == '3')
+ strcpy(suffix, "rd");
+ else
+ strcpy(suffix, "th");
+*/
+ fprintf(stdout, "%.15g percentile: %g\n", stats->perc[i],
quartile_perc[i]);
- else if (stats->perc[i] % 10 == 2 && stats->perc[i] != 12)
- fprintf(stdout, "%dnd percentile: %g\n", stats->perc[i],
- quartile_perc[i]);
- else if (stats->perc[i] % 10 == 3 && stats->perc[i] != 13)
- fprintf(stdout, "%drd percentile: %g\n", stats->perc[i],
- quartile_perc[i]);
- else
- fprintf(stdout, "%dth percentile: %g\n", stats->perc[i],
- quartile_perc[i]);
+ }
}
}
G_free((void *)quartile_perc);
More information about the grass-commit
mailing list