|
@@ -40,6 +40,7 @@ int main(int argc, char *argv[])
|
|
|
struct Option *opt_out;
|
|
|
struct Option *opt_title;
|
|
|
struct Flag *flag_diag;
|
|
|
+ struct Flag *flag_print;
|
|
|
|
|
|
G_gisinit(argv[0]);
|
|
|
|
|
@@ -56,6 +57,7 @@ int main(int argc, char *argv[])
|
|
|
opt_in = G_define_standard_option(G_OPT_R_INPUT);
|
|
|
|
|
|
opt_out = G_define_standard_option(G_OPT_R_OUTPUT);
|
|
|
+ opt_out->required = NO;
|
|
|
|
|
|
opt_title = G_define_option();
|
|
|
opt_title->key = "title";
|
|
@@ -66,48 +68,59 @@ int main(int argc, char *argv[])
|
|
|
flag_diag = G_define_flag();
|
|
|
flag_diag->key = 'd';
|
|
|
flag_diag->label = _("Clump also diagonal cells");
|
|
|
- flag_diag->description = _("Clumps are also traced along diagonal neighboring cells");
|
|
|
+ flag_diag->description = _("Clumps are also traced along diagonal neighboring cells");
|
|
|
+
|
|
|
+ flag_print = G_define_flag();
|
|
|
+ flag_print->key = 'p';
|
|
|
+ flag_print->label = _("Print only the number of clumps in shell script style");
|
|
|
+
|
|
|
+ G_option_exclusive(flag_print, opt_out, NULL);
|
|
|
+ G_option_required(flag_print, opt_out, NULL);
|
|
|
|
|
|
/* parse options */
|
|
|
if (G_parser(argc, argv))
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
|
|
INPUT = opt_in->answer;
|
|
|
- OUTPUT = opt_out->answer;
|
|
|
-
|
|
|
strcpy(name, INPUT);
|
|
|
|
|
|
in_fd = Rast_open_old(name, "");
|
|
|
|
|
|
- out_fd = Rast_open_c_new(OUTPUT);
|
|
|
+ if (!flag_print->answer) {
|
|
|
+ OUTPUT = opt_out->answer;
|
|
|
+ out_fd = Rast_open_c_new(OUTPUT);
|
|
|
+ }
|
|
|
|
|
|
- clump(in_fd, out_fd, flag_diag->answer);
|
|
|
-
|
|
|
- G_debug(1, "Creating support files...");
|
|
|
+ clump(in_fd, out_fd, flag_diag->answer, flag_print->answer);
|
|
|
|
|
|
Rast_close(in_fd);
|
|
|
- Rast_close(out_fd);
|
|
|
-
|
|
|
- /* build title */
|
|
|
- if (opt_title->answer != NULL)
|
|
|
- strcpy(title, opt_title->answer);
|
|
|
- else
|
|
|
- sprintf(title, "clump of <%s@%s>", name, G_mapset());
|
|
|
- Rast_put_cell_title(OUTPUT, title);
|
|
|
-
|
|
|
- /* colors */
|
|
|
- Rast_read_range(OUTPUT, G_mapset(), &range);
|
|
|
- Rast_get_range_min_max(&range, &min, &max);
|
|
|
- Rast_make_random_colors(&colr, min, max);
|
|
|
- Rast_write_colors(OUTPUT, G_mapset(), &colr);
|
|
|
-
|
|
|
- /* history */
|
|
|
- Rast_short_history(OUTPUT, "raster", &hist);
|
|
|
- Rast_set_history(&hist, HIST_DATSRC_1, INPUT);
|
|
|
- Rast_command_history(&hist);
|
|
|
- Rast_write_history(OUTPUT, &hist);
|
|
|
-
|
|
|
- G_done_msg(_n("%d clump.", "%d clumps.", range.max), range.max);
|
|
|
+
|
|
|
+ if (!flag_print->answer) {
|
|
|
+ Rast_close(out_fd);
|
|
|
+
|
|
|
+ G_debug(1, "Creating support files...");
|
|
|
+
|
|
|
+ /* build title */
|
|
|
+ if (opt_title->answer != NULL)
|
|
|
+ strcpy(title, opt_title->answer);
|
|
|
+ else
|
|
|
+ sprintf(title, "clump of <%s@%s>", name, G_mapset());
|
|
|
+ Rast_put_cell_title(OUTPUT, title);
|
|
|
+
|
|
|
+ /* colors */
|
|
|
+ Rast_read_range(OUTPUT, G_mapset(), &range);
|
|
|
+ Rast_get_range_min_max(&range, &min, &max);
|
|
|
+ Rast_make_random_colors(&colr, min, max);
|
|
|
+ Rast_write_colors(OUTPUT, G_mapset(), &colr);
|
|
|
+
|
|
|
+ /* history */
|
|
|
+ Rast_short_history(OUTPUT, "raster", &hist);
|
|
|
+ Rast_set_history(&hist, HIST_DATSRC_1, INPUT);
|
|
|
+ Rast_command_history(&hist);
|
|
|
+ Rast_write_history(OUTPUT, &hist);
|
|
|
+
|
|
|
+ G_done_msg(_n("%d clump.", "%d clumps.", range.max), range.max);
|
|
|
+ }
|
|
|
|
|
|
exit(EXIT_SUCCESS);
|
|
|
}
|