[GRASS-SVN] r61161 - grass/trunk/raster/r.topmodel

svn_grass at osgeo.org svn_grass at osgeo.org
Mon Jul 7 02:03:30 PDT 2014


Author: hcho
Date: 2014-07-07 02:03:30 -0700 (Mon, 07 Jul 2014)
New Revision: 61161

Modified:
   grass/trunk/raster/r.topmodel/file_io.c
   grass/trunk/raster/r.topmodel/global.h
   grass/trunk/raster/r.topmodel/topmodel.c
Log:
r.topmodel: Refactored area calculation

Modified: grass/trunk/raster/r.topmodel/file_io.c
===================================================================
--- grass/trunk/raster/r.topmodel/file_io.c	2014-07-07 04:21:01 UTC (rev 61160)
+++ grass/trunk/raster/r.topmodel/file_io.c	2014-07-07 09:03:30 UTC (rev 61161)
@@ -23,31 +23,6 @@
     FILE *fp;
     int i;
 
-    /* Read topographic index statistics file */
-    if ((fp = fopen(file.topidxstats, "r")) == NULL)
-	G_fatal_error(_("Unable to open input file <%s>"), file.topidxstats);
-
-    topidxstats.atb = NULL;
-    topidxstats.Aatb_r = NULL;
-
-    for (i = 0; !feof(fp);) {
-	double atb;
-	double Aatb_r;
-
-	get_line(fp, buf);
-	if (sscanf(buf, "%lf %lf", &atb, &Aatb_r) == 2) {
-	    topidxstats.atb = (double *)G_realloc(topidxstats.atb,
-			    (i + 1) * sizeof(double));
-	    topidxstats.Aatb_r = (double *)G_realloc(topidxstats.Aatb_r,
-			    (i + 1) * sizeof(double));
-	    topidxstats.atb[i] = atb;
-	    topidxstats.Aatb_r[i++] = Aatb_r;
-	}
-    }
-
-    misc.ntopidxclasses = i;
-    fclose(fp);
-
     /* Read parameters file */
     if ((fp = fopen(file.params, "r")) == NULL)
 	G_fatal_error(_("Unable to open input file <%s>"), file.params);
@@ -137,7 +112,7 @@
     }
 
     params.d = NULL;
-    params.Ad_r = NULL;
+    params.Ad = NULL;
 
     for (i = 0; !feof(fp);) {
 	double d;
@@ -146,16 +121,41 @@
 	get_line(fp, buf);
 	if (sscanf(buf, "%lf %lf", &d, &Ad_r) == 2) {
 	    params.d = (double *)G_realloc(params.d, (i + 1) * sizeof(double));
-	    params.Ad_r = (double *)G_realloc(params.Ad_r,
+	    params.Ad = (double *)G_realloc(params.Ad,
 			    (i + 1) * sizeof(double));
 	    params.d[i] = d;
-	    params.Ad_r[i++] = Ad_r;
+	    params.Ad[i++] = Ad_r * params.A;
 	}
     }
 
     params.nch = i;
     fclose(fp);
 
+    /* Read topographic index statistics file */
+    if ((fp = fopen(file.topidxstats, "r")) == NULL)
+	G_fatal_error(_("Unable to open input file <%s>"), file.topidxstats);
+
+    topidxstats.atb = NULL;
+    topidxstats.Aatb_r = NULL;
+
+    for (i = 0; !feof(fp);) {
+	double atb;
+	double Aatb_r;
+
+	get_line(fp, buf);
+	if (sscanf(buf, "%lf %lf", &atb, &Aatb_r) == 2) {
+	    topidxstats.atb = (double *)G_realloc(topidxstats.atb,
+			    (i + 1) * sizeof(double));
+	    topidxstats.Aatb_r = (double *)G_realloc(topidxstats.Aatb_r,
+			    (i + 1) * sizeof(double));
+	    topidxstats.atb[i] = atb;
+	    topidxstats.Aatb_r[i++] = Aatb_r;
+	}
+    }
+
+    misc.ntopidxclasses = i;
+    fclose(fp);
+
     /* Read input file */
     if ((fp = fopen(file.input, "r")) == NULL)
 	G_fatal_error(_("Unable to open input file <%s>"), file.input);

Modified: grass/trunk/raster/r.topmodel/global.h
===================================================================
--- grass/trunk/raster/r.topmodel/global.h	2014-07-07 04:21:01 UTC (rev 61160)
+++ grass/trunk/raster/r.topmodel/global.h	2014-07-07 09:03:30 UTC (rev 61161)
@@ -32,14 +32,6 @@
 double calculate_infiltration(int timestep, double R);
 
 
-/* Topographic index statistics file */
-struct topidxstats
-{
-    /* misc.ntopidxclasses */
-    double *atb;
-    double *Aatb_r;
-};
-
 /* Parameters file */
 struct params
 {
@@ -60,9 +52,17 @@
     int nch;
     /* params.nch's */
     double *d;
-    double *Ad_r;
+    double *Ad;
 };
 
+/* Topographic index statistics file */
+struct topidxstats
+{
+    /* misc.ntopidxclasses */
+    double *atb;
+    double *Aatb_r;
+};
+
 /* Input file */
 struct input
 {

Modified: grass/trunk/raster/r.topmodel/topmodel.c
===================================================================
--- grass/trunk/raster/r.topmodel/topmodel.c	2014-07-07 04:21:01 UTC (rev 61160)
+++ grass/trunk/raster/r.topmodel/topmodel.c	2014-07-07 09:03:30 UTC (rev 61161)
@@ -144,12 +144,12 @@
 
 	t = misc.delay + i + 1;
 	if (t > misc.tch[params.nch - 1])
-	    misc.Ad[i] = 1.0;
+	    misc.Ad[i] = params.A;
 	else {
 	    for (j = 1; j < params.nch; j++) {
 		if (t <= misc.tch[j]) {
-		    misc.Ad[i] = params.Ad_r[j - 1] +
-			(params.Ad_r[j] - params.Ad_r[j - 1]) *
+		    misc.Ad[i] = params.Ad[j - 1] +
+			(params.Ad[j] - params.Ad[j - 1]) *
 			(t - misc.tch[j - 1]) /
 			(misc.tch[j] - misc.tch[j - 1]);
 		    break;
@@ -160,10 +160,9 @@
 
     /* difference in the contribution area for each time step */
     A1 = misc.Ad[0];
-    misc.Ad[0] *= params.A;
     for (i = 1; i < misc.tcsub; i++) {
 	A2 = misc.Ad[i];
-	misc.Ad[i] = (A2 - A1) * params.A;
+	misc.Ad[i] = A2 - A1;
 	A1 = A2;
     }
 



More information about the grass-commit mailing list