[GRASS-SVN] r61688 - in grass/branches/releasebranch_7_0: . raster/r.clump
svn_grass at osgeo.org
svn_grass at osgeo.org
Tue Aug 19 08:59:34 PDT 2014
Author: neteler
Date: 2014-08-19 08:59:34 -0700 (Tue, 19 Aug 2014)
New Revision: 61688
Modified:
grass/branches/releasebranch_7_0/
grass/branches/releasebranch_7_0/raster/r.clump/clump.c
grass/branches/releasebranch_7_0/raster/r.clump/local_proto.h
grass/branches/releasebranch_7_0/raster/r.clump/main.c
Log:
r.clump: Add -p flag to print only the number of clumps in shell script style; msg cosmetics (trunk, r61169 +r61260 + r61687)
Property changes on: grass/branches/releasebranch_7_0
___________________________________________________________________
Deleted: svn:mergeinfo
- /grass/trunk:60908,60986,61519
Modified: grass/branches/releasebranch_7_0/raster/r.clump/clump.c
===================================================================
--- grass/branches/releasebranch_7_0/raster/r.clump/clump.c 2014-08-19 15:52:29 UTC (rev 61687)
+++ grass/branches/releasebranch_7_0/raster/r.clump/clump.c 2014-08-19 15:59:34 UTC (rev 61688)
@@ -29,7 +29,7 @@
#define INCR 1024
-CELL clump(int in_fd, int out_fd, int diag)
+CELL clump(int in_fd, int out_fd, int diag, int print)
{
register int col;
register int n;
@@ -91,7 +91,7 @@
* pass thru the input, create initial clump labels *
****************************************************/
- G_message(_("Pass 1..."));
+ G_message(_("Pass 1 of 2..."));
for (row = 0; row < nrows; row++) {
Rast_get_c_row(in_fd, cur_in + 1, row);
@@ -250,35 +250,41 @@
/* rewind temp file */
lseek(cfd, 0, SEEK_SET);
- /****************************************************
- * PASS 2 *
- * apply renumbering scheme to initial clump labels *
- ****************************************************/
+ if (print) {
+ fprintf(stdout, "clumps=%d\n", cat - 1);
+ }
+ else {
+ /****************************************************
+ * PASS 2 *
+ * apply renumbering scheme to initial clump labels *
+ ****************************************************/
- /* the input raster is no longer needed,
- * using instead the temp file with initial clump labels */
+ /* the input raster is no longer needed,
+ * using instead the temp file with initial clump labels */
- G_message(_("Pass 2..."));
- for (row = 0; row < nrows; row++) {
+ G_message(_("Pass 2 of 2..."));
+ for (row = 0; row < nrows; row++) {
- G_percent(row, nrows, 4);
+ G_percent(row, nrows, 4);
- if (read(cfd, cur_clump, csize) != csize)
- G_fatal_error(_("Unable to read from temp file"));
+ if (read(cfd, cur_clump, csize) != csize)
+ G_fatal_error(_("Unable to read from temp file"));
- temp_clump = cur_clump;
- temp_cell = out_cell;
+ temp_clump = cur_clump;
+ temp_cell = out_cell;
- for (col = 0; col < ncols; col++) {
- *temp_cell = renumber[index[*temp_clump]];
- if (*temp_cell == 0)
- Rast_set_c_null_value(temp_cell, 1);
- temp_clump++;
- temp_cell++;
+ for (col = 0; col < ncols; col++) {
+ *temp_cell = renumber[index[*temp_clump]];
+ if (*temp_cell == 0)
+ Rast_set_c_null_value(temp_cell, 1);
+ temp_clump++;
+ temp_cell++;
+ }
+ Rast_put_row(out_fd, out_cell, CELL_TYPE);
}
- Rast_put_row(out_fd, out_cell, CELL_TYPE);
+ G_percent(1, 1, 1);
}
- G_percent(1, 1, 1);
+
close(cfd);
unlink(cname);
Modified: grass/branches/releasebranch_7_0/raster/r.clump/local_proto.h
===================================================================
--- grass/branches/releasebranch_7_0/raster/r.clump/local_proto.h 2014-08-19 15:52:29 UTC (rev 61687)
+++ grass/branches/releasebranch_7_0/raster/r.clump/local_proto.h 2014-08-19 15:59:34 UTC (rev 61688)
@@ -20,7 +20,7 @@
#define __LOCAL_PROTO_H__
/* clump.c */
-CELL clump(int, int, int);
+CELL clump(int, int, int, int);
int print_time(long *);
/* main.c */
Modified: grass/branches/releasebranch_7_0/raster/r.clump/main.c
===================================================================
--- grass/branches/releasebranch_7_0/raster/r.clump/main.c 2014-08-19 15:52:29 UTC (rev 61687)
+++ grass/branches/releasebranch_7_0/raster/r.clump/main.c 2014-08-19 15:59:34 UTC (rev 61688)
@@ -40,6 +40,7 @@
struct Option *opt_out;
struct Option *opt_title;
struct Flag *flag_diag;
+ struct Flag *flag_print;
G_gisinit(argv[0]);
@@ -56,6 +57,7 @@
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,56 @@
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 = 'g';
+ flag_print->label = _("Print only the number of clumps in shell script style");
+
/* 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);
+ clump(in_fd, out_fd, flag_diag->answer, flag_print->answer);
- G_debug(1, "Creating support files...");
-
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);
+ if (!flag_print->answer) {
+ Rast_close(out_fd);
- /* 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);
+ G_debug(1, "Creating support files...");
- /* history */
- Rast_short_history(OUTPUT, "raster", &hist);
- Rast_set_history(&hist, HIST_DATSRC_1, INPUT);
- Rast_command_history(&hist);
- Rast_write_history(OUTPUT, &hist);
+ /* 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);
- G_done_msg(_n("%d clump.", "%d clumps.", range.max), range.max);
+ /* 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);
}
More information about the grass-commit
mailing list