[GRASS-SVN] r35847 - grass/branches/develbranch_6/raster/r.quantile
svn_grass at osgeo.org
svn_grass at osgeo.org
Tue Feb 10 15:27:17 EST 2009
Author: neteler
Date: 2009-02-10 15:27:16 -0500 (Tue, 10 Feb 2009)
New Revision: 35847
Modified:
grass/branches/develbranch_6/raster/r.quantile/main.c
Log:
glynn: Fix bug with sparse data (one value per slot); Allow calculation of 100th percentile (merge from trunk, r35846)
Modified: grass/branches/develbranch_6/raster/r.quantile/main.c
===================================================================
--- grass/branches/develbranch_6/raster/r.quantile/main.c 2009-02-10 16:04:47 UTC (rev 35846)
+++ grass/branches/develbranch_6/raster/r.quantile/main.c 2009-02-10 20:27:16 UTC (rev 35847)
@@ -51,7 +51,7 @@
static inline double get_quantile(int n)
{
- return (double)total *quants[n];
+ return (double)total * quants[n];
}
static void get_slot_counts(int infile)
@@ -190,27 +190,38 @@
static void compute_quantiles(int recode)
{
- struct bin *b = &bins[0];
+ int bin = 0;
double prev_v = min;
int quant;
for (quant = 0; quant < num_quants; quant++) {
+ struct bin *b;
double next = get_quantile(quant);
double k, v;
int i0, i1;
- while (b->origin + b->count < next)
- b++;
+ for (; bin < num_bins; bin++) {
+ b = &bins[bin];
+ if (b->origin + b->count >= next)
+ break;
+ }
- k = next - b->origin;
- i0 = (int)floor(k);
- i1 = (int)ceil(k);
+ if (bin < num_bins) {
+ k = next - b->origin;
+ i0 = (int)floor(k);
+ i1 = (int)ceil(k);
- v = (i0 == i1)
- ? values[b->base + i0]
- : values[b->base + i0] * (i1 - k) + values[b->base + i1] * (k -
- i0);
+ if (i1 > b->count - 1)
+ i1 = b->count - 1;
+ v = (i0 == i1)
+ ? values[b->base + i0]
+ : values[b->base + i0] * (i1 - k) +
+ values[b->base + i1] * (k - i0);
+ }
+ else
+ v = max;
+
if (recode)
printf("%f:%f:%i\n", prev_v, v, quant + 1);
else
More information about the grass-commit
mailing list