[GRASS-SVN] r60857 - grass/branches/releasebranch_7_0/raster/r.topmodel

svn_grass at osgeo.org svn_grass at osgeo.org
Tue Jun 17 18:25:51 PDT 2014


Author: hcho
Date: 2014-06-17 18:25:51 -0700 (Tue, 17 Jun 2014)
New Revision: 60857

Modified:
   grass/branches/releasebranch_7_0/raster/r.topmodel/topmodel.c
Log:
r.topmodel: fixed topidxstats file generation (merge from r60856)

Modified: grass/branches/releasebranch_7_0/raster/r.topmodel/topmodel.c
===================================================================
--- grass/branches/releasebranch_7_0/raster/r.topmodel/topmodel.c	2014-06-18 01:24:59 UTC (rev 60856)
+++ grass/branches/releasebranch_7_0/raster/r.topmodel/topmodel.c	2014-06-18 01:25:51 UTC (rev 60857)
@@ -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