[GRASS-SVN] r69771 - grass/branches/releasebranch_7_2/raster/r.stats.quantile
svn_grass at osgeo.org
svn_grass at osgeo.org
Fri Nov 4 06:23:16 PDT 2016
Author: mmetz
Date: 2016-11-04 06:23:16 -0700 (Fri, 04 Nov 2016)
New Revision: 69771
Modified:
grass/branches/releasebranch_7_2/raster/r.stats.quantile/main.c
Log:
r.stats.quantile: re-sync to r.quantile, use correct min (backport from trunk r69770)
Modified: grass/branches/releasebranch_7_2/raster/r.stats.quantile/main.c
===================================================================
--- grass/branches/releasebranch_7_2/raster/r.stats.quantile/main.c 2016-11-04 13:22:36 UTC (rev 69770)
+++ grass/branches/releasebranch_7_2/raster/r.stats.quantile/main.c 2016-11-04 13:23:16 UTC (rev 69771)
@@ -41,13 +41,13 @@
static int num_quants;
static DCELL *quants;
-static DCELL f_min, f_max;
+static DCELL min, max;
static int num_slots;
static DCELL slot_size;
static int rows, cols;
-static int min, max;
+static CELL cmin, cmax;
static int num_cats;
static struct basecat *basecats;
@@ -90,7 +90,7 @@
continue;
i = get_slot(coverbuf[col]);
- bc = &basecats[basebuf[col] - min];
+ bc = &basecats[basebuf[col] - cmin];
bc->slots[i]++;
bc->total++;
@@ -181,7 +181,7 @@
continue;
i = get_slot(coverbuf[col]);
- bc = &basecats[basebuf[col] - min];
+ bc = &basecats[basebuf[col] - cmin];
if (!bc->slot_bins[i])
continue;
@@ -246,7 +246,7 @@
int quant;
for (quant = 0; quant < num_quants; quant++)
- printf("%d:%d:%f:%f\n", min + cat, quant, 100 * quants[quant], bc->quants[quant]);
+ printf("%d:%d:%f:%f\n", cmin + cat, quant, 100 * quants[quant], bc->quants[quant]);
}
}
@@ -275,6 +275,9 @@
i0 = (int)floor(k);
i1 = (int)ceil(k);
+ if (i1 > b->count - 1)
+ i1 = b->count - 1;
+
v = (i0 == i1)
? bc->values[b->base + i0]
: bc->values[b->base + i0] * (i1 - k) + bc->values[b->base + i1] * (k - i0);
@@ -309,7 +312,7 @@
G_fatal_error(_("Unable to open temporary file"));
for (cat = 0; cat < num_cats; cat++)
- fprintf(fp, "%d = %d %f\n", min + cat, min + cat, basecats[cat].quants[quant]);
+ fprintf(fp, "%d = %d %f\n", cmin + cat, cmin + cat, basecats[cat].quants[quant]);
fclose(fp);
@@ -326,6 +329,7 @@
DCELL *out_buf = Rast_allocate_d_buf();
const char *mapset = G_mapset();
struct Colors colors;
+ struct History history;
int have_colors;
int quant;
int row, col;
@@ -348,7 +352,7 @@
if (Rast_is_c_null_value(&base_buf[col]))
Rast_set_d_null_value(&out_buf[col], 1);
else
- out_buf[col] = basecats[base_buf[col] - min].quants[quant];
+ out_buf[col] = basecats[base_buf[col] - cmin].quants[quant];
Rast_put_d_row(out_fd[quant], out_buf);
}
@@ -360,6 +364,9 @@
for (quant = 0; quant < num_quants; quant++) {
Rast_close(out_fd[quant]);
+ Rast_short_history(outputs[quant], "raster", &history);
+ Rast_command_history(&history);
+ Rast_write_history(outputs[quant], &history);
if (have_colors)
Rast_write_colors(outputs[quant], mapset, &colors);
}
@@ -482,15 +489,15 @@
if (Rast_read_range(basemap, "", &range) < 0)
G_fatal_error(_("Unable to read range of base map <%s>"), basemap);
- Rast_get_range_min_max(&range, &min, &max);
- num_cats = max - min + 1;
+ Rast_get_range_min_max(&range, &cmin, &cmax);
+ num_cats = cmax - cmin + 1;
if (num_cats > MAX_CATS)
G_fatal_error(_("Base map <%s> has too many categories (max: %d)"),
basemap, MAX_CATS);
Rast_read_fp_range(covermap, "", &fprange);
- Rast_get_fp_range_min_max(&fprange, &f_min, &f_max);
- slot_size = (f_max - f_min) / num_slots;
+ Rast_get_fp_range_min_max(&fprange, &min, &max);
+ slot_size = (max - min) / num_slots;
basecats = G_calloc(num_cats, sizeof(struct basecat));
More information about the grass-commit
mailing list