[GRASS-SVN] r41744 - grass/branches/develbranch_6/raster/r.gwflow

svn_grass at osgeo.org svn_grass at osgeo.org
Tue Apr 6 09:21:16 EDT 2010


Author: huhabla
Date: 2010-04-06 09:21:15 -0400 (Tue, 06 Apr 2010)
New Revision: 41744

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

Modified: grass/branches/develbranch_6/raster/r.gwflow/main.c
===================================================================
--- grass/branches/develbranch_6/raster/r.gwflow/main.c	2010-04-06 13:20:59 UTC (rev 41743)
+++ grass/branches/develbranch_6/raster/r.gwflow/main.c	2010-04-06 13:21:15 UTC (rev 41744)
@@ -72,6 +72,7 @@
 
     param.q =  G_define_standard_option(G_OPT_R_INPUT);
     param.q->key = "q";
+    param.q->required = NO;
     param.q->description = _("Water sources and sinks in [m^3/s]");
 
     param.s =  G_define_standard_option(G_OPT_R_INPUT);
@@ -81,6 +82,7 @@
     param.r =  G_define_standard_option(G_OPT_R_INPUT);
     param.r->key = "r";
     param.r->guisection = _("Recharge");
+    param.r->required = NO;
     param.r->description =
 	_("Recharge map e.g: 6*10^-9 per cell in [m^3/s*m^2]");
 
@@ -181,7 +183,6 @@
     char *buff = NULL;
     int with_river = 0, with_drain = 0;
 
-
     /* Initialize GRASS */
     G_gisinit(argv[0]);
 
@@ -200,7 +201,6 @@
 	G_fatal_error(_("Lat/Long location is not supported by %s. Please reproject map first."),
 		      G_program_name());
 
-
     /*Check the river  parameters */
     if (param.river_leak->answer == NULL && param.river_bed->answer == NULL &&
 	param.river_head->answer == NULL) {
@@ -227,7 +227,6 @@
 	G_fatal_error(_("Please provide drain_head and drain_leak maps"));
     }
 
-
     /*Set the maximum iterations */
     sscanf(param.maxit->answer, "%i", &(maxit));
     /*Set the calculation error break criteria */
@@ -242,7 +241,6 @@
     if (strcmp(solver, N_SOLVER_DIRECT_CHOLESKY) == 0 && param.sparse->answer)
 	G_fatal_error(_("The direct cholesky solver do not work with sparse matrices"));
 
-
     /*get the current region */
     G_get_set_window(&region);
 
@@ -275,16 +273,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);
@@ -316,6 +311,12 @@
 	N_convert_array_2d_null_to_zero(data->r);
     }
 
+    /*Sources or sinks are optional */
+    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++) {
@@ -397,7 +398,6 @@
     if (les)
 	N_free_les(les);
 
-
     /*Compute the the velocity field if required and write the result into three rast maps */
     if (param.vector->answer) {
 	field =
@@ -424,7 +424,6 @@
 	    N_free_gradient_field_2d(field);
     }
 
-
     if (data)
 	N_free_gwflow_data2d(data);
     if (geom)

Modified: grass/branches/develbranch_6/raster/r.gwflow/valid_calc_excavation.sh
===================================================================
--- grass/branches/develbranch_6/raster/r.gwflow/valid_calc_excavation.sh	2010-04-06 13:20:59 UTC (rev 41743)
+++ grass/branches/develbranch_6/raster/r.gwflow/valid_calc_excavation.sh	2010-04-06 13:21:15 UTC (rev 41744)
@@ -16,7 +16,6 @@
 		     (col() == 2 && row() == 14) ||\
 		     (row() == 19), 2, 1)"
 
-r.mapcalc "well=0.0"
 r.mapcalc "hydcond=0.001"
 r.mapcalc "recharge=0.000000006"
 r.mapcalc "top=20"
@@ -26,7 +25,7 @@
 
 #compute a steady state groundwater flow
 r.gwflow --o 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 \
  r=recharge output=gwresult dt=864000000000 type=unconfined 
 
 # create contour lines



More information about the grass-commit mailing list