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

svn_grass at osgeo.org svn_grass at osgeo.org
Fri Dec 20 08:35:40 PST 2013


Author: hcho
Date: 2013-12-20 08:35:40 -0800 (Fri, 20 Dec 2013)
New Revision: 58496

Modified:
   grass/trunk/raster/r.topmodel/file_io.c
   grass/trunk/raster/r.topmodel/r.topmodel.html
Log:
Changed the format of the parameters and input files.
ntimesteps removed from the input file and automatically determined.


Modified: grass/trunk/raster/r.topmodel/file_io.c
===================================================================
--- grass/trunk/raster/r.topmodel/file_io.c	2013-12-19 23:46:32 UTC (rev 58495)
+++ grass/trunk/raster/r.topmodel/file_io.c	2013-12-20 16:35:40 UTC (rev 58496)
@@ -10,7 +10,6 @@
 {
     char *str;
 
-
     buffer[0] = 0;
     fscanf(fp, "%[^\n]", buffer);
     getc(fp);
@@ -28,7 +27,6 @@
     int i, j;
     double x;
 
-
     /* Read topographic index statistics file */
     if ((fp = fopen(file.topidxstats, "r")) == NULL)
 	G_fatal_error(_("Unable to open input file <%s>"), file.topidxstats);
@@ -42,7 +40,6 @@
 	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));
@@ -55,7 +52,6 @@
     }
 
     misc.ntopidxclasses = i;
-
     fclose(fp);
 
     for (i = 0; i < misc.ntopidxclasses; i++)
@@ -74,14 +70,12 @@
 	}
     }
 
-
     /* Read parameters file */
     if ((fp = fopen(file.params, "r")) == NULL)
 	G_fatal_error(_("Unable to open input file <%s>"), file.params);
 
     for (; !feof(fp);) {
 	get_line(fp, buf);
-
 	i = strlen(buf) - 1;
 	for (; i >= 0; i--) {
 	    if (buf[i] != ' ' && buf[i] != '\t') {
@@ -96,36 +90,74 @@
 
     for (; !feof(fp);) {
 	get_line(fp, buf);
-
 	if (sscanf(buf, "%lf", &(params.A)) == 1)
 	    break;
     }
-
     for (; !feof(fp);) {
 	get_line(fp, buf);
-
-	if (sscanf(buf, "%lf %lf %lf %lf %lf %lf %lf %lf",
-		   &(params.qs0), &(params.lnTe),
-		   &(params.m), &(params.Sr0),
-		   &(params.Srmax), &(params.td),
-		   &(params.vch), &(params.vr)) == 8)
+	if (sscanf(buf, "%lf", &(params.qs0)) == 1)
 	    break;
     }
-
     if (params.qs0 == 0.0) {
 	fclose(fp);
-	G_fatal_error("parameters.qs0 can not be 0.0");
+	G_fatal_error("parameters.qs0 cannot be 0.0");
 	exit(EXIT_FAILURE);
     }
-
     for (; !feof(fp);) {
 	get_line(fp, buf);
-
-	if (sscanf(buf, "%d %lf %lf %lf",
-		   &(params.infex), &(params.K0),
-		   &(params.psi), &(params.dtheta)) == 4)
+	if (sscanf(buf, "%lf", &(params.lnTe)) == 1)
 	    break;
     }
+    for (; !feof(fp);) {
+	get_line(fp, buf);
+	if (sscanf(buf, "%lf", &(params.m)) == 1)
+	    break;
+    }
+    for (; !feof(fp);) {
+	get_line(fp, buf);
+	if (sscanf(buf, "%lf", &(params.Sr0)) == 1)
+	    break;
+    }
+    for (; !feof(fp);) {
+	get_line(fp, buf);
+	if (sscanf(buf, "%lf", &(params.Srmax)) == 1)
+	    break;
+    }
+    for (; !feof(fp);) {
+	get_line(fp, buf);
+	if (sscanf(buf, "%lf", &(params.td)) == 1)
+	    break;
+    }
+    for (; !feof(fp);) {
+	get_line(fp, buf);
+	if (sscanf(buf, "%lf", &(params.vch)) == 1)
+	    break;
+    }
+    for (; !feof(fp);) {
+	get_line(fp, buf);
+	if (sscanf(buf, "%lf", &(params.vr)) == 1)
+	    break;
+    }
+    for (; !feof(fp);) {
+	get_line(fp, buf);
+	if (sscanf(buf, "%d", &(params.infex)) == 1)
+	    break;
+    }
+    for (; !feof(fp);) {
+	get_line(fp, buf);
+	if (sscanf(buf, "%lf", &(params.K0)) == 1)
+	    break;
+    }
+    for (; !feof(fp);) {
+	get_line(fp, buf);
+	if (sscanf(buf, "%lf", &(params.psi)) == 1)
+	    break;
+    }
+    for (; !feof(fp);) {
+	get_line(fp, buf);
+	if (sscanf(buf, "%lf", &(params.dtheta)) == 1)
+	    break;
+    }
 
     params.d = NULL;
     params.Ad_r = NULL;
@@ -135,10 +167,8 @@
 	double Ad_r;
 
 	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.d = (double *)G_realloc(params.d, (i + 1) * sizeof(double));
 	    params.Ad_r = (double *)G_realloc(params.Ad_r,
 			    (i + 1) * sizeof(double));
 	    params.d[i] = d;
@@ -149,26 +179,30 @@
     params.nch = i;
     fclose(fp);
 
-
     /* Read input file */
     if ((fp = fopen(file.input, "r")) == NULL)
 	G_fatal_error(_("Unable to open input file <%s>"), file.input);
 
     for (; !feof(fp);) {
 	get_line(fp, buf);
-
-	if (sscanf(buf, "%d %lf", &(input.ntimesteps), &(input.dt)) == 2)
+	if (sscanf(buf, "%lf", &(input.dt)) == 1)
 	    break;
     }
 
-    input.R = (double *)G_malloc(input.ntimesteps * sizeof(double));
-    input.Ep = (double *)G_malloc(input.ntimesteps * sizeof(double));
+    input.R = NULL;
+    input.Ep = NULL;
 
-    for (i = 0; i < input.ntimesteps && !feof(fp);) {
+    for (i = 0; !feof(fp);) {
+	double R;
+	double Ep;
+
 	get_line(fp, buf);
-
-	if (sscanf(buf, "%lf %lf", &(input.R[i]), &(input.Ep[i])) == 2)
-	    i++;
+	if (sscanf(buf, "%lf %lf", &R, &Ep) == 2) {
+	    input.R = (double *)G_realloc(input.R, (i + 1) * sizeof(double));
+	    input.Ep = (double *)G_realloc(input.Ep, (i + 1) * sizeof(double));
+	    input.R[i] = R;
+	    input.Ep[i++] = Ep;
+	}
     }
 
     input.ntimesteps = i;
@@ -183,16 +217,14 @@
 
 	for (i = 0; i < input.ntimesteps && !feof(fp);) {
 	    get_line(fp, buf);
-
 	    if (sscanf(buf, "%lf", &(misc.Qobs[i])) == 1)
 		i++;
 	}
 
-	input.ntimesteps = (input.ntimesteps < i ? input.ntimesteps : i);
+	input.ntimesteps = (i < input.ntimesteps ? i : input.ntimesteps);
 	fclose(fp);
     }
 
-
     if (!(misc.timestep > 0 && misc.timestep < input.ntimesteps + 1))
 	misc.timestep = 0;
     if (!(misc.topidxclass > 0 && misc.topidxclass < misc.ntopidxclasses + 1))
@@ -209,14 +241,12 @@
     int st, et, si, ei;
     int i, j;
 
-
     time(&tloc);
     ltime = localtime(&tloc);
 
     ltime->tm_year += 1900;
     ltime->tm_mon++;
 
-
     if ((fp = fopen(file.output, "w")) == NULL)
 	G_fatal_error(_("Unable to open output file <%s>"), file.output);
 
@@ -295,7 +325,6 @@
 	fprintf(fp, "# %-15s Excess flow from a fully saturated "
 		"area per unit area\n" "# %77s\n", "ex:", "[m/timestep]");
     }
-
     fprintf(fp, "\n");
 
     if (file.obsflow) {

Modified: grass/trunk/raster/r.topmodel/r.topmodel.html
===================================================================
--- grass/trunk/raster/r.topmodel/r.topmodel.html	2013-12-19 23:46:32 UTC (rev 58495)
+++ grass/trunk/raster/r.topmodel/r.topmodel.html	2013-12-20 16:35:40 UTC (rev 58496)
@@ -19,40 +19,56 @@
 3.31697E+07
 
 ################################################################################
-# qs0 [m/h]:	Initial subsurface flow per unit area
-#		  "The first streamflow input is assumed to represent
-#		  only the subsurface flow contribution in the watershed."
+# qs0 [m/h]: Initial subsurface flow per unit area
+#		"The first streamflow input is assumed to represent
+#		only the subsurface flow contribution in the watershed."
 #								- Liaw (1988)
+0.000075
+
 # lnTe [ln(m^2/h)]: Areal average of ln(T0) = ln(Te)
-# m [m]:	Scaling parameter
-# Sr0 [m]:	Initial root zone storage deficit
-# Srmax [m]:	Maximum root zone storage deficit
-# td [h]:	Unsaturated zone time delay per unit storage deficit
-#		  if greater than 0.
+4.
+
+# m [m]: Scaling parameter
+0.0125
+
+# Sr0 [m]: Initial root zone storage deficit
+0.0025
+
+# Srmax [m]: Maximum root zone storage deficit
+0.041
+
+# td [h]: Unsaturated zone time delay per unit storage deficit if greater than 0
 #  OR
-# -alpha:	Effective vertical hydraulic gradient if not greater than 0.
-#		  For example, -10 means alpha = 10.
-# vch [m/h]:	Main channel routing velocity
-# vr [m/h]:	Internal subcatchment routing velocity
+# -alpha: Effective vertical hydraulic gradient if not greater than 0.
+#
+# For example, -10 means alpha=10.
+60.
 
-#     qs0      lnTe         m       Sr0     Srmax  td/alpha       vch        vr
- 0.000075        4.    0.0125    0.0025     0.041       60.    20000.    10000.
+# vch [m/h]: Main channel routing velocity
+20000.
 
+# vr [m/h]: Internal subcatchment routing velocity
+10000.
+
 ################################################################################
-# infex:	Calculate infiltration excess if not zero (integer)
-# K0 [m/h]:	Surface hydraulic conductivity
-# psi [m]:	Wetting front suction
-# dtheta:	Water content change across the wetting front
+# infex: Calculate infiltration excess if not zero (integer)
+0
 
-#   infex         K       psi    dtheta
-        0        2.       0.1       0.1
+# K0 [m/h]: Surface hydraulic conductivity
+2.
 
+# psi [m]: Wetting front suction
+0.1
+
+# dtheta: Water content change across the wetting front
+0.1
+
 ################################################################################
-# d [m]:	Distance from catchment
-#		  The first value should be the mainstream distance from
-#		  the subcatchment outlet to the catchment outlet.
-# Ad_r:		Cumulative area ratio of subcatchment (0.0 to 1.0)
-#		  The first and last values should be 0 and 1, respectively.
+# d [m]: Distance from the catchment outlet
+#		The first value should be the mainstream distance from
+#		the subcatchment outlet to the catchment outlet.
+# Ad_r:  Cumulative area ratio of subcatchment (0.0 to 1.0)
+#		The first and last values should be 0 and 1, respectively.
 
 #   d  Ad_r
     0   0.0
@@ -68,15 +84,12 @@
 <dd>
 This file contains observed weather data.
 <div class="code"><pre>
-# ntimesteps:   Number of time steps
-# dt [h]:       Time increment per time step
+# dt [h]: Time increment per time step
+24
 
-# ntimesteps   dt
-365            24
-
 ################################################################################
-# R [m/dt]:     Rainfall
-# Ep [m/dt]:    Potential evapotranspiration
+# R [m/dt]:  Rainfall
+# Ep [m/dt]: Potential evapotranspiration
 
 # R             Ep
 0.000033        0.000000



More information about the grass-commit mailing list