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

« back to all changes in this revision

Viewing changes to raster/r.support/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:
 
1
#include <stdlib.h>
 
2
#include <grass/gis.h>
 
3
#include <grass/raster.h>
 
4
#include <grass/glocale.h>
 
5
#include "local_proto.h"
 
6
 
 
7
 
 
8
/*
 
9
 * check_stats() - Check and update statistics 
 
10
 *
 
11
 * RETURN: EXIT_SUCCESS / EXIT_FAILURE
 
12
 */
 
13
int check_stats(const char *name)
 
14
{
 
15
    RASTER_MAP_TYPE data_type;
 
16
    struct Histogram histogram;
 
17
    struct Categories cats;
 
18
    struct Range range;
 
19
    struct FPRange fprange;
 
20
    int i;
 
21
    int cats_ok;
 
22
    int max;
 
23
 
 
24
    data_type = Rast_map_type(name, "");
 
25
 
 
26
    G_message(_("\n  Updating statistics for [%s]"), name);
 
27
    if (do_histogram(name) < 0)
 
28
        return 0;
 
29
 
 
30
    if (Rast_read_histogram(name, "", &histogram) <= 0)
 
31
        return 0;
 
32
 
 
33
    /* Init histogram range */
 
34
    if (data_type == CELL_TYPE)
 
35
        Rast_init_range(&range);
 
36
    else
 
37
        Rast_init_fp_range(&fprange);
 
38
 
 
39
    /* Update histogram range */
 
40
    i = Rast_get_histogram_num(&histogram);
 
41
    while (i >= 0) {
 
42
        if (data_type == CELL_TYPE)
 
43
            Rast_update_range(Rast_get_histogram_cat(i--, &histogram), &range);
 
44
        else
 
45
            Rast_update_fp_range((DCELL) Rast_get_histogram_cat(i--, &histogram),
 
46
                              &fprange);
 
47
    }
 
48
 
 
49
    /* Write histogram range */
 
50
    if (data_type == CELL_TYPE)
 
51
        Rast_write_range(name, &range);
 
52
    else
 
53
        Rast_write_fp_range(name, &fprange);
 
54
 
 
55
    /* Get category status and max */
 
56
    cats_ok = (Rast_read_cats(name, "", &cats) >= 0);
 
57
    max = (data_type == CELL_TYPE ? range.max : fprange.max);
 
58
 
 
59
    /* Further category checks */
 
60
    if (!cats_ok)
 
61
        Rast_init_cats("", &cats);
 
62
    else if (cats.num != max) {
 
63
        cats.num = max;
 
64
        cats_ok = 0;
 
65
    }
 
66
 
 
67
    /* Update categories if needed */
 
68
    if (!cats_ok) {
 
69
        G_message(_("   Updating the number of categories for "
 
70
                    "[%s]\n\n"), name);
 
71
        Rast_write_cats(name, &cats);
 
72
    }
 
73
 
 
74
    Rast_free_histogram(&histogram);
 
75
    Rast_free_cats(&cats);
 
76
 
 
77
    return 0;
 
78
}