[GRASS-SVN] r33689 - in grass/branches/develbranch_6: lib/gis raster/r.series

svn_grass at osgeo.org svn_grass at osgeo.org
Mon Oct 6 05:44:30 EDT 2008


Author: neteler
Date: 2008-10-06 05:44:29 -0400 (Mon, 06 Oct 2008)
New Revision: 33689

Modified:
   grass/branches/develbranch_6/lib/gis/parser.c
   grass/branches/develbranch_6/raster/r.series/main.c
Log:
glynn: Fix check_overwrite() to handle opt->multiple == YES; Allow multiple aggregates to be computed in one run (merge from trunk, r33666; r33667)

Modified: grass/branches/develbranch_6/lib/gis/parser.c
===================================================================
--- grass/branches/develbranch_6/lib/gis/parser.c	2008-10-06 09:23:42 UTC (rev 33688)
+++ grass/branches/develbranch_6/lib/gis/parser.c	2008-10-06 09:44:29 UTC (rev 33689)
@@ -2535,22 +2535,25 @@
 	    split_gisprompt(opt->gisprompt, age, element, desc);
 
 	    if (strcmp(age, "new") == 0) {
-		if (G_find_file(element, opt->answer, G_mapset())) {	/* found */
-		    if (!overwrite && !over) {
-			if (G_info_format() != G_INFO_FORMAT_GUI) {
-			    fprintf(stderr,
-				    _("ERROR: option <%s>: <%s> exists.\n"),
-				    opt->key, opt->answer);
+		int i;
+		for (i = 0; opt->answers[i]; i++) {
+		    if (G_find_file(element, opt->answers[i], G_mapset())) {	/* found */
+			if (!overwrite && !over) {
+			    if (G_info_format() != G_INFO_FORMAT_GUI) {
+				fprintf(stderr,
+					_("ERROR: option <%s>: <%s> exists.\n"),
+					opt->key, opt->answers[i]);
+			    }
+			    else {
+				fprintf(stderr,
+					"GRASS_INFO_ERROR(%d,1): option <%s>: <%s> exists.\n",
+					getpid(), opt->key, opt->answers[i]);
+				fprintf(stderr, "GRASS_INFO_END(%d,1)\n",
+					getpid());
+			    }
+
+			    error = 1;
 			}
-			else {
-			    fprintf(stderr,
-				    "GRASS_INFO_ERROR(%d,1): option <%s>: <%s> exists.\n",
-				    getpid(), opt->key, opt->answer);
-			    fprintf(stderr, "GRASS_INFO_END(%d,1)\n",
-				    getpid());
-			}
-
-			error = 1;
 		    }
 		}
 	    }

Modified: grass/branches/develbranch_6/raster/r.series/main.c
===================================================================
--- grass/branches/develbranch_6/raster/r.series/main.c	2008-10-06 09:23:42 UTC (rev 33688)
+++ grass/branches/develbranch_6/raster/r.series/main.c	2008-10-06 09:44:29 UTC (rev 33689)
@@ -54,11 +54,19 @@
 
 struct input
 {
-    char *name, *mapset;
+    const char *name, *mapset;
     int fd;
     DCELL *buf;
 };
 
+struct output
+{
+    const char *name;
+    int fd;
+    DCELL *buf;
+    stat_func *method_fn;
+};
+
 static char *build_method_list(void)
 {
     char *buf = G_malloc(1024);
@@ -78,6 +86,19 @@
     return buf;
 }
 
+static int find_method(const char *method_name)
+{
+    int i;
+
+    for (i = 0; menu[i].name; i++)
+	if (strcmp(menu[i].name, method_name) == 0)
+	    return i;
+
+    G_fatal_error(_("Unknown method <%s>"), method_name);
+
+    return -1;
+}
+
 int main(int argc, char *argv[])
 {
     struct GModule *module;
@@ -91,16 +112,13 @@
 	struct Flag *quiet;
 	struct Flag *nulls;
     } flag;
-    int method;
-    stat_func *method_fn;
     int i;
     int num_inputs;
     struct input *inputs;
-    char *out_name;
-    int out_fd;
+    int num_outputs;
+    struct output *outputs;
     struct History history;
-    DCELL *out_buf;
-    DCELL *values;
+    DCELL *values, *values_tmp;
     int nrows, ncols;
     int row, col;
 
@@ -116,6 +134,7 @@
     parm.input = G_define_standard_option(G_OPT_R_INPUTS);
 
     parm.output = G_define_standard_option(G_OPT_R_OUTPUT);
+    parm.output->multiple = YES;
 
     parm.method = G_define_option();
     parm.method->key = "method";
@@ -123,6 +142,7 @@
     parm.method->required = YES;
     parm.method->options = build_method_list();
     parm.method->description = _("Aggregate operation");
+    parm.method->multiple = YES;
 
     /* please, remove before GRASS 7 released */
     flag.quiet = G_define_flag();
@@ -143,18 +163,6 @@
 		    "in future. Please use '--quiet' instead."));
     }
 
-    /* get the method */
-    method = -1;
-    for (i = 0; menu[i].name; i++)
-	if (strcmp(menu[i].name, parm.method->answer) == 0) {
-	    method = i;
-	    break;
-	}
-    if (method < 0)
-	G_fatal_error(_("Unknown method <%s>"), parm.method->answer);
-
-    method_fn = menu[method].method;
-
     /* process the input maps */
     for (i = 0; parm.input->answers[i]; i++) ;
     num_inputs = i;
@@ -180,19 +188,34 @@
 	p->buf = G_allocate_d_raster_buf();
     }
 
-    /* process the output map */
-    out_name = parm.output->answer;
+    /* process the output maps */
+    for (i = 0; parm.output->answers[i]; i++) ;
+    num_outputs = i;
 
-    out_fd =
-	G_open_raster_new(out_name,
-			  menu[method].is_int ? CELL_TYPE : DCELL_TYPE);
-    if (out_fd < 0)
-	G_fatal_error(_("Unable to create raster map <%s>"), out_name);
+    for (i = 0; parm.method->answers[i]; i++) ;
+    if (num_outputs != i)
+	G_fatal_error(_("output= and method= must have the same number of values"));
 
-    out_buf = G_allocate_d_raster_buf();
+    outputs = G_calloc(num_outputs, sizeof(struct output));
 
+    for (i = 0; i < num_outputs; i++) {
+	struct output *out = &outputs[i];
+	const char *output_name = parm.output->answers[i];
+	const char *method_name = parm.method->answers[i];
+	int method = find_method(method_name);
+
+	out->name = output_name;
+	out->method_fn = menu[method].method;
+	out->buf = G_allocate_d_raster_buf();
+	out->fd = G_open_raster_new(
+	    output_name, menu[method].is_int ? CELL_TYPE : DCELL_TYPE);
+	if (out->fd < 0)
+	    G_fatal_error(_("Unable to create raster map <%s>"), out->name);
+    }
+
     /* initialise variables */
     values = G_malloc(num_inputs * sizeof(DCELL));
+    values_tmp = G_malloc(num_inputs * sizeof(DCELL));
 
     nrows = G_window_rows();
     ncols = G_window_cols();
@@ -218,24 +241,35 @@
 		values[i] = v;
 	    }
 
-	    if (null && flag.nulls->answer)
-		G_set_d_null_value(&out_buf[col], 1);
-	    else
-		(*method_fn) (&out_buf[col], values, num_inputs);
+	    for (i = 0; i < num_outputs; i++) {
+		struct output *out = &outputs[i];
+
+		if (null && flag.nulls->answer)
+		    G_set_d_null_value(&out->buf[col], 1);
+		else {
+		    memcpy(values_tmp, values, num_inputs * sizeof(DCELL));
+		    (*out->method_fn)(&out->buf[col], values_tmp, num_inputs);
+		}
+	    }
 	}
 
-	G_put_d_raster_row(out_fd, out_buf);
+	for (i = 0; i < num_outputs; i++)
+	    G_put_d_raster_row(outputs[i].fd, outputs[i].buf);
     }
 
     G_percent(row, nrows, 2);
 
     /* close maps */
-    G_close_cell(out_fd);
+    for (i = 0; i < num_outputs; i++) {
+	struct output *out = &outputs[i];
 
-    G_short_history(out_name, "raster", &history);
-    G_command_history(&history);
-    G_write_history(out_name, &history);
+	G_close_cell(out->fd);
 
+	G_short_history(out->name, "raster", &history);
+	G_command_history(&history);
+	G_write_history(out->name, &history);
+    }
+
     for (i = 0; i < num_inputs; i++)
 	G_close_cell(inputs[i].fd);
 



More information about the grass-commit mailing list