21 #define DEFAULT_CELL_MIN 1 22 #define DEFAULT_CELL_MAX 255 24 static void init_rstats(
struct R_stats *);
103 G_warning(
_(
"Unable to read fp range file for <%s>"),
108 if (read(fd, xdr_buf,
sizeof(xdr_buf)) !=
sizeof(xdr_buf)) {
111 G_debug(1,
"Empty fp range file meaning Nulls for <%s>",
125 G_warning(
_(
"Missing fp range file for <%s> (run r.support -s)"),
176 G_warning(
_(
"Unable to read quant rules for raster map <%s>"),
190 x[0] = (
CELL) (dmin + .5);
192 x[0] = (
CELL) (dmin - .5);
194 x[1] = (
CELL) (dmax + .5);
196 x[1] = (
CELL) (dmax - .5);
213 G_warning(
_(
"Unable to read range file for <%s>"),
219 if (!fgets(buf,
sizeof buf, fd)) {
225 x[0] = x[1] = x[2] = x[3] = 0;
226 count = sscanf(buf,
"%d%d%d%d", &x[0], &x[1], &x[2], &x[3]);
233 G_warning(
_(
"Unable to read range file for <%s>"),
238 for (n = 0; n <
count; n++) {
241 if (count < 4 || x[n])
248 G_warning(
_(
"Missing range file for <%s> (run r.support -s)"),
280 DCELL dcell1, dcell2;
292 G_debug(1,
"Stats file does not exist");
298 G_warning(
_(
"Unable to read stats file for <%s>"),
303 if (read(fd, xdr_buf,
sizeof(xdr_buf)) !=
sizeof(xdr_buf)) {
306 G_debug(1,
"Empty stats file meaning Nulls for <%s>",
314 rstats->
sum = dcell1;
315 rstats->
sumsq = dcell2;
319 if (read(fd, &nbytes, 1) != 1) {
322 G_debug(1,
"Unable to read byte count in stats file for <%s>",
333 G_debug(1,
"Invalid byte count in stats file for <%s>",
337 if (read(fd, cc, nbytes) != nbytes) {
340 G_debug(1,
"Unable to read count in stats file for <%s>",
346 for (i = nbytes - 1; i >= 0; i--) {
347 count = (count << 8);
348 count = count + cc[i];
391 fprintf(fp,
"%ld %ld\n", (
long)range->
min, (
long)range->
max);
430 if (write(fd, xdr_buf,
sizeof(xdr_buf)) !=
sizeof(xdr_buf)) {
466 if (rstats->
count < 1) {
474 if (write(fd, xdr_buf,
sizeof(xdr_buf)) !=
sizeof(xdr_buf)) {
480 count = rstats->
count;
484 cc[i] = count & 0xff;
492 if (write(fd, &nbytes, 1) != 1) {
497 if (nbytes > 0 && write(fd, cc, nbytes) != nbytes) {
526 if (cat < range->
min)
528 if (cat > range->
max)
554 if (val < range->
min)
556 if (val > range->
max)
588 struct Range *range,
int ignore_zeros)
607 if (cat < range->
min)
609 if (cat > range->
max)
646 val = *((
DCELL *) rast);
664 if (val < range->
min)
666 if (val > range->
max)
695 init_rstats(&range->
rstats);
747 init_rstats(&range->
rstats);
void Rast_row_update_fp_range(const void *rast, int n, struct FPRange *range, RASTER_MAP_TYPE data_type)
Update range structure based on raster row (floating-point)
void void void void G_fatal_error(const char *,...) __attribute__((format(printf
void Rast_write_fp_range(const char *name, const struct FPRange *range)
Write raster range file (floating-point)
void Rast_set_c_null_value(CELL *, int)
To set a number of CELL raster values to NULL.
#define Rast_is_d_null_value(dcellVal)
int Rast_read_quant(const char *, const char *, struct Quant *)
Reads quantization rules for name in mapset and stores them in the quantization structure. If the map is in another mapset, first checks for quant2 table for this map in current mapset.
int G_open_new_misc(const char *, const char *, const char *)
open a new database file
int Rast_read_rstats(const char *name, const char *mapset, struct R_stats *rstats)
Read raster stats.
int Rast_quant_is_truncate(const struct Quant *)
Returns whether or not quant rules are set to truncate map.
#define G_incr_void_ptr(ptr, size)
int G_remove_misc(const char *, const char *, const char *)
Remove a database misc file.
int Rast_read_range(const char *name, const char *mapset, struct Range *range)
Read raster range (CELL)
int G_open_old_misc(const char *, const char *, const char *, const char *)
open a database file for reading
void Rast_update_fp_range(DCELL val, struct FPRange *range)
Update range structure (floating-point)
void Rast_init_range(struct Range *range)
Initialize range structure.
char * G_fully_qualified_name(const char *, const char *)
Get fully qualified element name.
void Rast_row_update_range(const CELL *cell, int n, struct Range *range)
Update range structure based on raster row (CELL)
size_t Rast_cell_size(RASTER_MAP_TYPE)
Returns size of a raster cell in bytes.
FILE * G_fopen_old_misc(const char *, const char *, const char *, const char *)
open a database file for reading
void G_xdr_put_double(void *, const double *)
void Rast_write_range(const char *name, const struct Range *range)
Write raster range file.
#define XDR_DOUBLE_NBYTES
int Rast_quant_is_round(const struct Quant *)
Returns whether or not quant rules are set to round map.
void Rast__row_update_range(const CELL *cell, int n, struct Range *range, int ignore_zeros)
Update range structure based on raster row.
void Rast_write_rstats(const char *name, const struct R_stats *rstats)
Write raster stats file.
int Rast_quant_get_limits(const struct Quant *, DCELL *, DCELL *, CELL *, CELL *)
Returns the minimum and maximum cell and dcell values of all the ranges defined.
const char * G_find_file2_misc(const char *, const char *, const char *, const char *)
Searches for a file from the mapset search list or in a specified mapset. (look but don't touch) ...
FILE * G_fopen_new_misc(const char *, const char *, const char *)
open a new database file
void Rast__remove_fp_range(const char *name)
Remove floating-point range.
const char * G_mapset(void)
Get current mapset name.
void G_warning(const char *,...) __attribute__((format(printf
int Rast_read_fp_range(const char *name, const char *mapset, struct FPRange *drange)
Read floating-point range.
void Rast_get_fp_range_min_max(const struct FPRange *range, DCELL *min, DCELL *max)
Get minimum and maximum value from fp range.
void Rast_init(void)
Initialize GRASS GIS engine.
#define Rast_is_c_null_value(cellVal)
int G_debug(int, const char *,...) __attribute__((format(printf
void Rast_set_d_null_value(DCELL *, int)
To set a number of DCELL raster values to NULL.
void Rast_init_fp_range(struct FPRange *range)
Initialize fp range.
void Rast_get_range_min_max(const struct Range *range, CELL *min, CELL *max)
Get range min and max.
int Rast_is_null_value(const void *, RASTER_MAP_TYPE)
To check if a raster value is set to NULL.
void G_xdr_get_double(double *, const void *)
RASTER_MAP_TYPE Rast_map_type(const char *, const char *)
Determine raster data type.
void Rast_update_range(CELL cat, struct Range *range)
Update range structure (CELL)
void Rast_construct_default_range(struct Range *range)
Construct default range.