3
#include <grass/raster.h>
4
#include <grass/glocale.h>
5
#include "local_proto.h"
9
* check_stats() - Check and update statistics
11
* RETURN: EXIT_SUCCESS / EXIT_FAILURE
13
int check_stats(const char *name)
15
RASTER_MAP_TYPE data_type;
16
struct Histogram histogram;
17
struct Categories cats;
19
struct FPRange fprange;
24
data_type = Rast_map_type(name, "");
26
G_message(_("\n Updating statistics for [%s]"), name);
27
if (do_histogram(name) < 0)
30
if (Rast_read_histogram(name, "", &histogram) <= 0)
33
/* Init histogram range */
34
if (data_type == CELL_TYPE)
35
Rast_init_range(&range);
37
Rast_init_fp_range(&fprange);
39
/* Update histogram range */
40
i = Rast_get_histogram_num(&histogram);
42
if (data_type == CELL_TYPE)
43
Rast_update_range(Rast_get_histogram_cat(i--, &histogram), &range);
45
Rast_update_fp_range((DCELL) Rast_get_histogram_cat(i--, &histogram),
49
/* Write histogram range */
50
if (data_type == CELL_TYPE)
51
Rast_write_range(name, &range);
53
Rast_write_fp_range(name, &fprange);
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);
59
/* Further category checks */
61
Rast_init_cats("", &cats);
62
else if (cats.num != max) {
67
/* Update categories if needed */
69
G_message(_(" Updating the number of categories for "
71
Rast_write_cats(name, &cats);
74
Rast_free_histogram(&histogram);
75
Rast_free_cats(&cats);