[GRASS-SVN] r60856 - grass/trunk/raster/r.topmodel
svn_grass at osgeo.org
svn_grass at osgeo.org
Tue Jun 17 18:24:59 PDT 2014
Author: hcho
Date: 2014-06-17 18:24:59 -0700 (Tue, 17 Jun 2014)
New Revision: 60856
Modified:
grass/trunk/raster/r.topmodel/topmodel.c
Log:
r.topmodel: fixed topidxstats file generation
Modified: grass/trunk/raster/r.topmodel/topmodel.c
===================================================================
--- grass/trunk/raster/r.topmodel/topmodel.c 2014-06-17 17:40:00 UTC (rev 60855)
+++ grass/trunk/raster/r.topmodel/topmodel.c 2014-06-18 01:24:59 UTC (rev 60856)
@@ -10,7 +10,7 @@
const char *args[5];
struct Popen child;
FILE *fp;
- double *atb, *Aatb_r;
+ double *atb, *Aatb_r, delta, prev_atb2;
int i;
int total_ncells;
@@ -33,15 +33,31 @@
Aatb_r = (double *)G_malloc(ntopidxclasses * sizeof(double));
total_ncells = 0;
+ delta = -1.0;
+ prev_atb2 = 0.0;
+
for (i = 0; i < ntopidxclasses - 1 && !feof(fp);) {
double atb1, atb2;
int ncells;
get_line(fp, buf);
if (sscanf(buf, "%lf-%lf %d", &atb1, &atb2, &ncells) == 3) {
+ if (delta < 0)
+ delta = atb2 - atb1;
+ else if (atb1 > prev_atb2 + 0.5 * delta) {
+ /* r.stats doesn't report non-existing ranges at all. Use 0.5 *
+ * delta to avoid comparing two almost same double numbers. */
+ while (prev_atb2 < atb1 - 0.5 * delta) {
+ atb[i] = prev_atb2;
+ Aatb_r[i++] = 0.0;
+ prev_atb2 += delta;
+ }
+ }
+
atb[i] = atb1;
Aatb_r[i] = (double)ncells;
total_ncells += ncells;
+ prev_atb2 = atb2;
if (++i == ntopidxclasses - 1) {
atb[i] = atb2;
More information about the grass-commit
mailing list