[GRASS-SVN] r41742 - grass/trunk/raster/r.gwflow

svn_grass at osgeo.org svn_grass at osgeo.org
Tue Apr 6 09:20:43 EDT 2010


Author: huhabla
Date: 2010-04-06 09:20:42 -0400 (Tue, 06 Apr 2010)
New Revision: 41742

Modified:
   grass/trunk/raster/r.gwflow/main.c
   grass/trunk/raster/r.gwflow/valid_calc_excavation.py
Log:
Bugfix: Avoid segfault if q is not provided.

Modified: grass/trunk/raster/r.gwflow/main.c
===================================================================
--- grass/trunk/raster/r.gwflow/main.c	2010-04-06 10:45:31 UTC (rev 41741)
+++ grass/trunk/raster/r.gwflow/main.c	2010-04-06 13:20:42 UTC (rev 41742)
@@ -73,6 +73,7 @@
 
     param.q = G_define_standard_option(G_OPT_R_INPUT);
     param.q->key = "q";
+    param.q->required = NO;
     param.q->description = _("Raster map water sources and sinks in [m^3/s]");
 
     param.s = G_define_standard_option(G_OPT_R_INPUT);
@@ -289,16 +290,13 @@
      * null values.*/
     N_read_rast_to_array_2d(param.phead->answer, data->phead);
     N_convert_array_2d_null_to_zero(data->phead);
-    N_read_rast_to_array_2d(param.phead->answer, data->phead_start);
-    N_convert_array_2d_null_to_zero(data->phead_start);
+    N_copy_array_2d(data->phead, data->phead_start);
     N_read_rast_to_array_2d(param.status->answer, data->status);
     N_convert_array_2d_null_to_zero(data->status);
     N_read_rast_to_array_2d(param.hc_x->answer, data->hc_x);
     N_convert_array_2d_null_to_zero(data->hc_x);
     N_read_rast_to_array_2d(param.hc_y->answer, data->hc_y);
     N_convert_array_2d_null_to_zero(data->hc_y);
-    N_read_rast_to_array_2d(param.q->answer, data->q);
-    N_convert_array_2d_null_to_zero(data->q);
     N_read_rast_to_array_2d(param.s->answer, data->s);
     N_convert_array_2d_null_to_zero(data->s);
     N_read_rast_to_array_2d(param.top->answer, data->top);
@@ -330,17 +328,23 @@
 	N_convert_array_2d_null_to_zero(data->r);
     }
 
+    /*Sources or sinks areoptional */
+    if (param.q->answer) {
+        N_read_rast_to_array_2d(param.q->answer, data->q);
+        N_convert_array_2d_null_to_zero(data->q);
+    }
+
     /* Set the inactive values to zero, to assure a no flow boundary */
     for (y = 0; y < geom->rows; y++) {
-	for (x = 0; x < geom->cols; x++) {
-	    stat = N_get_array_2d_c_value(data->status, x, y);
-	    if (stat == N_CELL_INACTIVE) {	/*only inactive cells */
-		N_put_array_2d_d_value(data->hc_x, x, y, 0);
-		N_put_array_2d_d_value(data->hc_y, x, y, 0);
-		N_put_array_2d_d_value(data->s, x, y, 0);
-		N_put_array_2d_d_value(data->q, x, y, 0);
-	    }
-	}
+        for (x = 0; x < geom->cols; x++) {
+            stat = N_get_array_2d_c_value(data->status, x, y);
+            if (stat == N_CELL_INACTIVE) {	/*only inactive cells */
+            N_put_array_2d_d_value(data->hc_x, x, y, 0);
+            N_put_array_2d_d_value(data->hc_y, x, y, 0);
+            N_put_array_2d_d_value(data->s, x, y, 0);
+            N_put_array_2d_d_value(data->q, x, y, 0);
+            }
+        }
     }
 
 

Modified: grass/trunk/raster/r.gwflow/valid_calc_excavation.py
===================================================================
--- grass/trunk/raster/r.gwflow/valid_calc_excavation.py	2010-04-06 10:45:31 UTC (rev 41741)
+++ grass/trunk/raster/r.gwflow/valid_calc_excavation.py	2010-04-06 13:20:42 UTC (rev 41742)
@@ -25,7 +25,6 @@
 		     (col() == 2 && row() == 14) ||\
 		     (row() == 19), 2, 1)")
 
-grass.run_command("r.mapcalc", expression="well=0.0")
 grass.run_command("r.mapcalc", expression="hydcond=0.001")
 grass.run_command("r.mapcalc", expression="recharge=0.000000006")
 grass.run_command("r.mapcalc", expression="top=20")
@@ -35,5 +34,5 @@
 
 #compute a steady state groundwater flow
 grass.run_command("r.gwflow", "f", solver="cholesky", top="top", bottom="bottom", phead="phead", \
- status="status", hc_x="hydcond", hc_y="hydcond", q="well", s="syield", \
+ status="status", hc_x="hydcond", hc_y="hydcond", s="syield", \
  recharge="recharge", output="gwresult", dt=864000000000, type="unconfined", budget="water_budget")



More information about the grass-commit mailing list