17
19
stats_file = G_tempfile();
19
21
if (stats_flag != REPORT_ONLY) {
20
strcpy(buf, "r.stats -acr");
21
/* if (!masking) strcat (buf, "m"); */
24
const char **argv = G_calloc(n_argv, sizeof(*argv));
27
argv[argc++] = "r.stats";
28
argv[argc++] = "-acr";
30
/* if (!masking) argv[argc++] = "-m"; */
31
if (G_verbose() == G_verbose_min())
32
argv[argc++] = "--quiet";
32
45
else if (nsteps != 255) {
33
sprintf(tmp, " nsteps=%d", nsteps);
46
sprintf(tmp, "nsteps=%d", nsteps);
37
strcat(buf, " fs=: \"input=");
50
argv[argc++] = "separator=:";
52
argv[argc++] = SF_REDIRECT_FILE;
53
argv[argc++] = SF_STDOUT;
54
argv[argc++] = SF_MODE_OUT;
55
argv[argc++] = stats_file;
57
if (do_sort == SORT_ASC)
58
argv[argc++] = "sort=asc";
59
else if (do_sort == SORT_DESC)
60
argv[argc++] = "sort=desc";
39
62
for (i = 0; i < nlayers; i++) {
43
G_fully_qualified_name(layers[i].name, layers[i].mapset));
63
char *name = G_fully_qualified_name(layers[i].name, layers[i].mapset);
64
char *buf = G_malloc(6 + strlen(name) + 1);
66
sprintf(buf, "input=%s", name);
69
if (argc + 1 >= n_argv) {
71
argv = G_realloc(argv, n_argv * sizeof(*argv));
48
strcat(buf, stats_file);
50
/* G_fatal_error(buf); */
52
if (stats_flag == EVERYTHING)
79
if (G_vspawn_ex(argv[0], argv) != 0) {
81
G_fatal_error("error running r.stats");
57
85
if (stats_flag == STATS_ONLY)
64
92
unlink(stats_file);
65
93
G_fatal_error(_("Unable to open result file <%s>"), stats_file);
67
96
while (G_getl(buf, sizeof buf, fd)) {
68
97
tokens = G_tokenize(buf, ":");
73
102
for (nl = 0; nl < nlayers; nl++) {
74
103
if (sscanf(tokens[i], "%d", &Gstats[ns].cats[nl]) != 1) {
75
104
if (tokens[i][0] == '*')
76
G_set_c_null_value(&Gstats[ns].cats[nl], 1);
105
Rast_set_c_null_value(&Gstats[ns].cats[nl], 1);