浏览代码

Bugfix: Avoid segfault if q is not provided.

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@41742 15284696-431f-4ddb-bdfa-cd5b030d7da7
Soeren Gebbert 15 年之前
父节点
当前提交
81f588d1d9
共有 2 个文件被更改,包括 18 次插入15 次删除
  1. 17 13
      raster/r.gwflow/main.c
  2. 1 2
      raster/r.gwflow/valid_calc_excavation.py

+ 17 - 13
raster/r.gwflow/main.c

@@ -73,6 +73,7 @@ void set_params(void)
 
     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 @@ int main(int argc, char *argv[])
      * 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 @@ int main(int argc, char *argv[])
 	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);
+            }
+        }
     }
 
 

+ 1 - 2
raster/r.gwflow/valid_calc_excavation.py

@@ -25,7 +25,6 @@ grass.run_command("r.mapcalc", expression="status=if((col() == 1 && row() == 13)
 		     (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 @@ grass.run_command("r.mapcalc", expression="null=0.0")
 
 #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")