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

« back to all changes in this revision

Viewing changes to raster/r.support.stats/check.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:
17
17
 
18
18
#include <stdlib.h>
19
19
#include <grass/gis.h>
 
20
#include <grass/raster.h>
20
21
#include <grass/glocale.h>
21
22
#include "local_proto.h"
22
23
 
26
27
 *
27
28
 * RETURN: 0 on success / 1 on failure
28
29
 */
29
 
int check_stats(char *name, char *mapset)
 
30
int check_stats(const char *name)
30
31
{
31
32
    RASTER_MAP_TYPE data_type;
32
33
    struct Histogram histogram;
37
38
    int cats_ok;
38
39
    int max;
39
40
 
40
 
    data_type = G_raster_map_type(name, mapset);
 
41
    data_type = Rast_map_type(name, "");
41
42
 
42
43
    G_message(_("Updating statistics for [%s]..."), name);
43
44
 
44
 
    if (!do_histogram(name, mapset))
 
45
    if (!do_histogram(name))
45
46
        return 1;
46
 
    if (G_read_histogram(name, mapset, &histogram) <= 0)
 
47
    if (Rast_read_histogram(name, "", &histogram) <= 0)
47
48
        return 1;
48
49
 
49
50
    /* Init histogram range */
50
51
    if (data_type == CELL_TYPE)
51
 
        G_init_range(&range);
 
52
        Rast_init_range(&range);
52
53
    else
53
 
        G_init_fp_range(&fprange);
 
54
        Rast_init_fp_range(&fprange);
54
55
 
55
56
    G_message(_("Updating histogram range..."));
56
 
    i = histo_num = G_get_histogram_num(&histogram);
 
57
    i = histo_num = Rast_get_histogram_num(&histogram);
57
58
    while (i >= 0) {
58
59
        G_percent(i, histo_num, 2);
59
60
 
60
61
        if (data_type == CELL_TYPE)
61
 
            G_update_range(G_get_histogram_cat(i--, &histogram), &range);
 
62
            Rast_update_range(Rast_get_histogram_cat(i--, &histogram), &range);
62
63
        else
63
 
            G_update_fp_range((DCELL) G_get_histogram_cat(i--, &histogram),
 
64
            Rast_update_fp_range((DCELL) Rast_get_histogram_cat(i--, &histogram),
64
65
                              &fprange);
65
66
    }
66
67
 
67
68
    /* Write histogram range */
68
69
    if (data_type == CELL_TYPE)
69
 
        G_write_range(name, &range);
 
70
        Rast_write_range(name, &range);
70
71
    else
71
 
        G_write_fp_range(name, &fprange);
 
72
        Rast_write_fp_range(name, &fprange);
72
73
 
73
74
    /* Get category status and max */
74
 
    cats_ok = (G_read_cats(name, mapset, &cats) >= 0);
 
75
    cats_ok = (Rast_read_cats(name, "", &cats) >= 0);
75
76
    max = (data_type == CELL_TYPE ? range.max : fprange.max);
76
77
 
77
78
    /* Further category checks */
78
79
    if (!cats_ok)
79
 
        G_init_cats(max, "", &cats);
 
80
        Rast_init_cats("", &cats);
80
81
    else if (cats.num != max) {
81
82
        cats.num = max;
82
83
        cats_ok = 0;
85
86
    /* Update categories if needed */
86
87
    if (!cats_ok) {
87
88
        G_message(_("Updating the number of categories for [%s]..."), name);
88
 
        G_write_cats(name, &cats);
 
89
        Rast_write_cats(name, &cats);
89
90
    }
90
91
 
91
 
    G_free_histogram(&histogram);
92
 
    G_free_cats(&cats);
 
92
    Rast_free_histogram(&histogram);
 
93
    Rast_free_cats(&cats);
93
94
 
94
95
    return 0;
95
96
}