~ubuntu-branches/ubuntu/wily/grass/wily

« back to all changes in this revision

Viewing changes to raster/r.report/stats.c

Tags: 7.0.0~rc1+ds1-1~exp1
* New upstream release candidate.
* Repack upstream tarball, remove precompiled Python objects.
* Add upstream metadata.
* Update gbp.conf and Vcs-Git URL to use the experimental branch.
* Update watch file for GRASS 7.0.
* Drop build dependencies for Tcl/Tk, add build dependencies:
  python-numpy, libnetcdf-dev, netcdf-bin, libblas-dev, liblapack-dev
* Update Vcs-Browser URL to use cgit instead of gitweb.
* Update paths to use grass70.
* Add configure options: --with-netcdf, --with-blas, --with-lapack,
  remove --with-tcltk-includes.
* Update patches for GRASS 7.
* Update copyright file, changes:
  - Update copyright years
  - Group files by license
  - Remove unused license sections
* Add patches for various typos.
* Fix desktop file with patch instead of d/rules.
* Use minimal dh rules.
* Bump Standards-Version to 3.9.6, no changes.
* Use dpkg-maintscript-helper to replace directories with symlinks.
  (closes: #776349)
* Update my email to use @debian.org address.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#include <string.h>
2
2
#include <unistd.h>
3
3
#include <stdlib.h>
 
4
#include <grass/gis.h>
 
5
#include <grass/glocale.h>
 
6
#include <grass/spawn.h>
4
7
#include "global.h"
5
8
 
6
9
static int die(void);
8
11
int get_stats(void)
9
12
{
10
13
    char buf[1024];
11
 
    char tmp[50];
12
14
    int i, nl, ns;
13
15
    FILE *fd;
14
16
    char **tokens;
17
19
        stats_file = G_tempfile();
18
20
 
19
21
    if (stats_flag != REPORT_ONLY) {
20
 
        strcpy(buf, "r.stats -acr");
21
 
        /* if (!masking) strcat (buf, "m"); */
22
 
        if (!verbose)
23
 
            strcat(buf, "q");
 
22
        char tmp[50];
 
23
        int n_argv = 50;
 
24
        const char **argv = G_calloc(n_argv, sizeof(*argv));
 
25
        int argc = 0;
 
26
 
 
27
        argv[argc++] = "r.stats";
 
28
        argv[argc++] = "-acr";
 
29
 
 
30
        /* if (!masking) argv[argc++] = "-m"; */
 
31
        if (G_verbose() == G_verbose_min())
 
32
            argv[argc++] = "--quiet";
 
33
 
24
34
        if (no_nulls)
25
 
            strcat(buf, "n");
 
35
            argv[argc++] = "-n";
 
36
 
26
37
        if (no_nulls_all)
27
 
            strcat(buf, "N");
 
38
            argv[argc++] = "-N";
 
39
 
28
40
        if (as_int)
29
 
            strcat(buf, "i");
 
41
            argv[argc++] = "-i";
 
42
 
30
43
        if (cat_ranges)
31
 
            strcat(buf, "C");
 
44
            argv[argc++] = "-C";
32
45
        else if (nsteps != 255) {
33
 
            sprintf(tmp, " nsteps=%d", nsteps);
34
 
            strcat(buf, tmp);
 
46
            sprintf(tmp, "nsteps=%d", nsteps);
 
47
            argv[argc++] = tmp;
35
48
        }
36
49
 
37
 
        strcat(buf, " fs=: \"input=");
38
 
 
 
50
        argv[argc++] = "separator=:";
 
51
 
 
52
        argv[argc++] = SF_REDIRECT_FILE;
 
53
        argv[argc++] = SF_STDOUT;
 
54
        argv[argc++] = SF_MODE_OUT;
 
55
        argv[argc++] = stats_file;
 
56
 
 
57
        if (do_sort == SORT_ASC)
 
58
            argv[argc++] = "sort=asc";
 
59
        else if (do_sort == SORT_DESC)
 
60
            argv[argc++] = "sort=desc";
 
61
        
39
62
        for (i = 0; i < nlayers; i++) {
40
 
            if (i)
41
 
                strcat(buf, ",");
42
 
            strcat(buf,
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);
 
65
 
 
66
            sprintf(buf, "input=%s", name);
 
67
            G_free(name);
 
68
 
 
69
            if (argc + 1 >= n_argv) {
 
70
                n_argv += 50;
 
71
                argv = G_realloc(argv, n_argv * sizeof(*argv));
 
72
            }
 
73
 
 
74
            argv[argc++] = buf;
44
75
        }
45
 
        strcat(buf, "\"");
46
 
 
47
 
        strcat(buf, " > \"");
48
 
        strcat(buf, stats_file);
49
 
        strcat(buf, "\"");
50
 
        /*      G_fatal_error(buf); */
51
 
        if (system(buf)) {
52
 
            if (stats_flag == EVERYTHING)
53
 
                unlink(stats_file);
54
 
            exit(1);
 
76
 
 
77
        argv[argc++] = NULL;
 
78
 
 
79
        if (G_vspawn_ex(argv[0], argv) != 0) {
 
80
            remove(stats_file);
 
81
            G_fatal_error("error running r.stats");
55
82
        }
56
83
    }
 
84
 
57
85
    if (stats_flag == STATS_ONLY)
58
86
        return 0;
59
87
 
64
92
            unlink(stats_file);
65
93
        G_fatal_error(_("Unable to open result file <%s>"), stats_file);
66
94
    }
 
95
 
67
96
    while (G_getl(buf, sizeof buf, fd)) {
68
97
        tokens = G_tokenize(buf, ":");
69
98
        i = 0;
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);
77
106
                else
78
107
                    die();
79
108
            }