~ubuntu-branches/ubuntu/vivid/grass/vivid-proposed

« back to all changes in this revision

Viewing changes to display/d.profile/Range.c

  • Committer: Package Import Robot
  • Author(s): Bas Couwenberg
  • Date: 2015-02-20 23:12:08 UTC
  • mfrom: (8.2.6 experimental)
  • Revision ID: package-import@ubuntu.com-20150220231208-1u6qvqm84v430b10
Tags: 7.0.0-1~exp1
* New upstream release.
* Update python-ctypes-ternary.patch to use if/else instead of and/or.
* Drop check4dev patch, rely on upstream check.
* Add build dependency on libpq-dev to grass-dev for libpq-fe.h.
* Drop patches applied upstream, refresh remaining patches.
* Update symlinks for images switched from jpg to png.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#include <stdio.h>
2
 
#include <stdlib.h>
3
 
#include <grass/gis.h>
4
 
#include <grass/glocale.h>
5
 
 
6
 
int WindowRange(char *name, char *mapset, long *min, long *max)
7
 
{
8
 
    char inbuf[512];            /* input buffer for reading stats */
9
 
    int done = 0;
10
 
    char stats_cmd[GPATH_MAX];  /* string for r.stats command */
11
 
    char *temp_fname;           /* temp file name */
12
 
    FILE *temp_file;            /* temp file pointer */
13
 
    long int cat;               /* a category value */
14
 
    long int stat;              /* a category stat value */
15
 
    int first;
16
 
 
17
 
    /* write stats to a temp file */
18
 
    temp_fname = G_tempfile();
19
 
    sprintf(stats_cmd, "r.stats -ci \"%s\" > \"%s\"", name, temp_fname);
20
 
    G_debug(3, "r.stats command=[%s]", stats_cmd);
21
 
    system(stats_cmd);
22
 
 
23
 
    /* open temp file and read the stats into a linked list */
24
 
    temp_file = fopen(temp_fname, "r");
25
 
 
26
 
    first = 1;
27
 
    while (!done) {
28
 
        if (fgets(inbuf, sizeof(inbuf), temp_file) != NULL) {
29
 
            if (sscanf(inbuf, "%ld %ld", &cat, &stat) == 2) {
30
 
                if (first) {
31
 
                    *max = cat;
32
 
                    *min = cat;
33
 
                    first = 0;
34
 
                }
35
 
                else {
36
 
                    if (cat > *max)
37
 
                        *max = cat;
38
 
                    if (cat < *min)
39
 
                        *min = cat;
40
 
                }
41
 
            }
42
 
            else
43
 
                done = 1;
44
 
        }
45
 
        else
46
 
            done = 1;
47
 
    }
48
 
 
49
 
    fclose(temp_file);
50
 
    return 0;
51
 
}
52
 
 
53
 
int quick_range(char *name, char *mapset, long *min, long *max)
54
 
{
55
 
    struct Range range;
56
 
    struct FPRange fprange;
57
 
    CELL xmin, xmax;
58
 
    DCELL fpxmin, fpxmax;
59
 
 
60
 
    switch (G_raster_map_type(name, mapset)) {
61
 
    case CELL_TYPE:
62
 
        if (G_read_range(name, mapset, &range) <= 0)
63
 
            return 0;
64
 
        G_get_range_min_max(&range, &xmin, &xmax);
65
 
        *max = xmax;
66
 
        *min = xmin;
67
 
        break;
68
 
    default:
69
 
        if (G_read_fp_range(name, mapset, &fprange) <= 0)
70
 
            return 0;
71
 
        G_get_fp_range_min_max(&fprange, &fpxmin, &fpxmax);
72
 
        *max = (long)fpxmax;
73
 
        *min = (long)fpxmin;
74
 
        break;
75
 
    }
76
 
    return 1;
77
 
}
78
 
 
79
 
int slow_range(char *name, char *mapset, long *min, long *max)
80
 
{
81
 
    FILE *fd;
82
 
    int first;
83
 
    long n;
84
 
    int ok;
85
 
    char buf[512];
86
 
 
87
 
    *min = *max = 0;
88
 
 
89
 
    G_message(_("one moment ..."));
90
 
    sprintf(buf, "Gdescribe -r -1 '%s in %s'", name, mapset);
91
 
    fd = popen(buf, "r");
92
 
    if (fd == NULL)
93
 
        return 0;
94
 
    ok = 1;
95
 
    first = 1;
96
 
    while (ok && fgets(buf, sizeof(buf), fd)) {
97
 
        ok = (sscanf(buf, "%ld", &n) == 1);
98
 
        if (!ok)
99
 
            break;
100
 
        if (n == 0)
101
 
            continue;
102
 
        *max = n;
103
 
        if (first)
104
 
            *min = n;
105
 
        first = 0;
106
 
    }
107
 
    pclose(fd);
108
 
    if (!ok)
109
 
        *min = *max = 0;
110
 
    return ok;
111
 
}