[GRASS-SVN] r43592 - grass/branches/releasebranch_6_4/raster/r.what
svn_grass at osgeo.org
svn_grass at osgeo.org
Tue Sep 21 09:44:57 EDT 2010
Author: neteler
Date: 2010-09-21 13:44:57 +0000 (Tue, 21 Sep 2010)
New Revision: 43592
Modified:
grass/branches/releasebranch_6_4/raster/r.what/main.c
Log:
backport: r38800; r38802
Modified: grass/branches/releasebranch_6_4/raster/r.what/main.c
===================================================================
--- grass/branches/releasebranch_6_4/raster/r.what/main.c 2010-09-21 13:42:06 UTC (rev 43591)
+++ grass/branches/releasebranch_6_4/raster/r.what/main.c 2010-09-21 13:44:57 UTC (rev 43592)
@@ -5,7 +5,7 @@
* AUTHOR(S): Michael Shapiro, CERL (original contributor)
* Markus Neteler <neteler itc.it>,Brad Douglas <rez touchofmadness.com>,
* Huidae Cho <grass4u gmail.com>, Glynn Clements <glynn gclements.plus.com>,
- * Hamish Bowman <hamish_nospam yahoo.com>, Soeren Gebbert <soeren.gebbert gmx.de>
+ * Hamish Bowman <hamish_b yahoo.com>, Soeren Gebbert <soeren.gebbert gmx.de>
* PURPOSE:
* COPYRIGHT: (C) 1999-2006 by the GRASS Development Team
*
@@ -50,7 +50,6 @@
char *mapset;
int i, j;
int nfiles;
- int withcats;
int fd[NFILES];
struct Categories cats[NFILES];
struct Cell_head window;
@@ -68,10 +67,10 @@
char buffer[1024];
char **ptr;
struct Option *opt1, *opt2, *opt3, *opt4, *opt_fs;
- struct Flag *flag1, *flag2, *flag3, *flag4;
+ struct Flag *label_flag, *cache_flag, *int_flag, *color_flag, *header_flag;
char fs;
int Cache_size;
- int done = 0;
+ int done = FALSE;
int point, point_cnt;
struct order *cache;
int cur_row;
@@ -79,7 +78,7 @@
int cache_hit = 0, cache_miss = 0;
int cache_hit_tot = 0, cache_miss_tot = 0;
int pass = 0;
- int cache_report = 0;
+ int cache_report = FALSE;
char tmp_buf[500], *null_str;
int red, green, blue;
struct GModule *module;
@@ -108,6 +107,7 @@
opt2->multiple = NO;
opt2->description = _("Size of point cache");
opt2->answer = "500";
+ opt2->guisection = _("Advanced");
opt3 = G_define_option();
opt3->key = "null";
@@ -126,25 +126,31 @@
opt4->multiple = YES;
opt4->description = _("Coordinates for query");
- flag1 = G_define_flag();
- flag1->key = 'f';
- flag1->description = _("Show the category label in the grid cell(s)");
+ header_flag = G_define_flag();
+ header_flag->key = 'n';
+ header_flag->description = _("Output header row");
- flag2 = G_define_flag();
- flag2->key = 'c';
- flag2->description = _("Turn on cache reporting");
+ label_flag = G_define_flag();
+ label_flag->key = 'f';
+ label_flag->description = _("Show the category labels of the grid cell(s)");
- flag3 = G_define_flag();
- flag3->key = 'i';
- flag3->description = _("Output integer category values, not cell values");
+ color_flag = G_define_flag();
+ color_flag->key = 'r';
+ color_flag->description = _("Output color values as RRR:GGG:BBB");
- flag4 = G_define_flag();
- flag4->key = 'r';
- flag4->description = _("Output color values as RRR:GGG:BBB");
+ int_flag = G_define_flag();
+ int_flag->key = 'i';
+ int_flag->description = _("Output integer category values, not cell values");
+ cache_flag = G_define_flag();
+ cache_flag->key = 'c';
+ cache_flag->description = _("Turn on cache reporting");
+ cache_flag->guisection = _("Advanced");
+
if (G_parser(argc, argv))
exit(EXIT_FAILURE);
+
tty = isatty(0);
projection = G_projection();
@@ -161,29 +167,26 @@
fs = opt_fs->answer[0];
}
- withcats = 0;
- nfiles = 0;
+ null_str = opt3->answer;
+
if (tty)
Cache_size = 1;
else
Cache_size = atoi(opt2->answer);
- null_str = opt3->answer;
-
if (Cache_size < 1)
Cache_size = 1;
cache = (struct order *)G_malloc(sizeof(struct order) * Cache_size);
- /* note this is not kosher */
- withcats = flag1->answer;
-
/*enable cache report */
- if (flag2->answer)
- cache_report = 1;
+ if (cache_flag->answer)
+ cache_report = TRUE;
+
ptr = opt1->answers;
+ nfiles = 0;
for (; *ptr != NULL; ptr++) {
char name[GNAME_MAX];
@@ -198,21 +201,22 @@
die("can't open", name);
out_type[nfiles] = G_get_raster_map_type(fd[nfiles]);
- if (flag3->answer)
+ if (int_flag->answer)
out_type[nfiles] = CELL_TYPE;
- if (flag4->answer) {
+ if (color_flag->answer) {
G_read_colors(name, mapset, &colors);
ncolor[nfiles] = colors;
}
- if (withcats && G_read_cats(name, mapset, &cats[nfiles]) < 0)
+ if (label_flag->answer && G_read_cats(name, mapset, &cats[nfiles]) < 0)
die(name, " - can't read category file");
+
nfiles++;
}
for (i = 0; i < nfiles; i++) {
- if (flag3->answer)
+ if (int_flag->answer)
out_type[i] = CELL_TYPE;
cell[i] = G_allocate_c_raster_buf();
@@ -222,18 +226,39 @@
G_get_window(&window);
+
+ if(header_flag->answer) {
+ fprintf(stdout, "easting%cnorthing%csite_name", fs, fs);
+
+ ptr = opt1->answers;
+ for (; *ptr != NULL; ptr++) {
+ char name[GNAME_MAX];
+ strcpy(name, *ptr);
+
+ fprintf(stdout, "%c%s", fs, name);
+
+ if (label_flag->answer)
+ fprintf(stdout, "%c%s_label", fs, name);
+ if (color_flag->answer)
+ fprintf(stdout, "%c%s_color", fs, name);
+ }
+
+ fprintf(stdout, "\n");
+ }
+
line = 0;
if (!opt4->answers && tty)
fprintf(stderr, "enter points, \"end\" to quit\n");
j = 0;
- done = 0;
+ done = FALSE;
while (!done) {
pass++;
if (cache_report & !tty)
fprintf(stderr, "Pass %3d Line %6d - ", pass, line);
cache_hit = cache_miss = 0;
+
if (!opt4->answers && tty) {
fprintf(stderr, "\neast north [label] > ");
Cache_size = 1;
@@ -242,14 +267,14 @@
point_cnt = 0;
for (i = 0; i < Cache_size; i++) {
if (!opt4->answers && fgets(buffer, 1000, stdin) == NULL)
- done = 1;
+ done = TRUE;
else {
line++;
if ((!opt4->answers &&
(strncmp(buffer, "end\n", 4) == 0 ||
strncmp(buffer, "exit\n", 5) == 0)) ||
(opt4->answers && !opt4->answers[j]))
- done = 1;
+ done = TRUE;
else {
*(cache[point_cnt].lab_buf) =
*(cache[point_cnt].east_buf) =
@@ -358,7 +383,7 @@
else
G_set_d_null_value(&(cache[point].dvalue[i]), 1);
}
- if (flag4->answer) {
+ if (color_flag->answer) {
if (out_type[i] == CELL_TYPE)
G_get_c_raster_color(&cell[i][cache[point].col],
&red, &green, &blue, &ncolor[i]);
@@ -392,9 +417,9 @@
if (out_type[i] == CELL_TYPE) {
if (G_is_c_null_value(&cache[point].value[i])) {
fprintf(stdout, "%c%s", fs, null_str);
- if (withcats)
+ if (label_flag->answer)
fprintf(stdout, "%c", fs);
- if (flag4->answer)
+ if (color_flag->answer)
fprintf(stdout, "%c", fs);
continue;
}
@@ -404,20 +429,23 @@
if (G_is_d_null_value(&cache[point].dvalue[i])) {
fprintf(stdout, "%c%s", fs, null_str);
- if (withcats)
+ if (label_flag->answer)
fprintf(stdout, "%c", fs);
- if (flag4->answer)
+ if (color_flag->answer)
fprintf(stdout, "%c", fs);
continue;
}
- sprintf(tmp_buf, "%.10f", cache[point].dvalue[i]);
- G_trim_decimal(tmp_buf);
+ if (out_type[i] == FCELL_TYPE)
+ sprintf(tmp_buf, "%.7g", cache[point].dvalue[i]);
+ else /* DCELL */
+ sprintf(tmp_buf, "%.15g", cache[point].dvalue[i]);
+ G_trim_decimal(tmp_buf); /* not needed with %g? */
fprintf(stdout, "%c%s", fs, tmp_buf);
}
- if (withcats)
+ if (label_flag->answer)
fprintf(stdout, "%c%s", fs,
G_get_cat(cache[point].value[i], &cats[i]));
- if (flag4->answer)
+ if (color_flag->answer)
fprintf(stdout, "%c%s", fs, cache[point].clr_buf[i]);
}
fprintf(stdout, "\n");
@@ -431,9 +459,13 @@
cache_miss_tot += cache_miss;
cache_hit = cache_miss = 0;
}
+
+ if (!opt4->answers && tty)
+ fprintf(stderr, "\n");
if (cache_report & !tty)
fprintf(stderr, "Total: Cache Hit: %6d Miss: %6d\n",
cache_hit_tot, cache_miss_tot);
+
exit(EXIT_SUCCESS);
}
More information about the grass-commit
mailing list