61 #include <grass/gis.h>
62 #include <grass/glocale.h>
67 #define QUANT_FILE_NAME "f_quant"
71 static int quant_parse_file(FILE *,
struct Quant *);
77 quant_load_range(
struct Quant *quant,
const char *
name,
const char *mapset)
79 struct FPRange fprange;
89 sprintf(buf, _(
"The floating data range for %s@%s is empty"), name,
99 sprintf(buf, _(
"The integer data range for %s@%s is empty"), name,
117 char xname[GNAME_MAX],
xmapset[GMAPSET_MAX], element[GNAME_MAX + 7];
125 "G__quant_import: attempt to open quantization table for CELL_TYPE file [%s] in mapset {%s]",
132 if (strcmp(xmapset, mapset) != 0)
138 sprintf(element,
"quant2/%s", mapset);
140 parsStat = quant_parse_file(fd, quant);
145 "quantization file in quant2 for [%s] in mapset [%s] is empty",
157 parsStat = quant_parse_file(fd, quant);
168 _(
"quantization file [%s] in mapset [%s] %s"), name, mapset, err);
191 static int quant_parse_file(FILE *
fd,
struct Quant *quant)
196 int foundNegInf = 0, foundPosInf = 0;
198 while (fgets(buf,
sizeof(buf), fd)) {
199 if (strncmp(buf,
"truncate", 8) == 0) {
200 quant->truncate_only = 1;
203 if (strncmp(buf,
"round", 5) == 0) {
204 quant->round_only = 1;
207 switch (sscanf(buf,
"%lf:%lf:%d:%d", &dLow, &dHigh, &cLow, &cHigh)) {
215 switch (sscanf(buf,
"*:%lf:%d", &dLow, &cLow)) {
223 switch (sscanf(buf,
"%lf:*:%d", &dLow, &cLow)) {
249 static void quant_write(FILE * fd,
const struct Quant *quant)
255 if (quant->truncate_only) {
256 fprintf(fd,
"truncate");
259 if (quant->round_only) {
260 fprintf(fd,
"round");
264 fprintf(fd,
"*:%.20g:%d\n", dLow, cLow);
267 fprintf(fd,
"%.20g:*:%d\n", dLow, cLow);
271 fprintf(fd,
"%.20g:%.20g:%d", dLow, dHigh, cLow);
273 fprintf(fd,
":%d", cHigh);
282 const struct Quant *quant)
284 char element[GNAME_MAX + 7];
289 if (strcmp(xmapset, mapset) != 0)
294 if (strcmp(
G_mapset(), mapset) == 0) {
301 sprintf(element,
"quant2/%s", mapset);
310 quant_write(fd, quant);
char * G_mapset(void)
current mapset name
int G_is_c_null_value(const CELL *cellVal)
Returns 1 if cell is NULL, 0 otherwise. This will test if the value cell is the largest int...
sprintf(buf2,"%s", G3D_CATS_ELEMENT)
void G_quant_free(struct Quant *q)
void G_quant_set_neg_infinite_rule(struct Quant *q, DCELL dLeft, CELL c)
int G_quant_get_neg_infinite_rule(const struct Quant *q, DCELL *dLeft, CELL *c)
FILE * G_fopen_old_misc(const char *dir, const char *element, const char *name, const char *mapset)
open a database file for reading
int G_read_range(const char *name, const char *mapset, struct Range *range)
read raster range
void G_quant_get_ith_rule(const struct Quant *q, int i, DCELL *dLow, DCELL *dHigh, CELL *cLow, CELL *cHigh)
int G_get_range_min_max(const struct Range *range, CELL *min, CELL *max)
get range min and max
int G__quant_import(const char *name, const char *mapset, struct Quant *quant)
int G_is_d_null_value(const DCELL *dcellVal)
Returns 1 if dcell is NULL, 0 otherwise. This will test if the value dcell is a NaN. Same test as in G_is_f_null_value().
void G_quant_reverse_rule_order(struct Quant *q)
int G__quant_export(const char *name, const char *mapset, const struct Quant *quant)
int G_remove(const char *element, const char *name)
Remove a database file.
char buf[GNAME_MAX+sizeof(G3D_DIRECTORY)+2]
int G_quant_nof_rules(const struct Quant *q)
int G__make_mapset_element_misc(const char *dir, const char *name)
Create misc element in the current mapset.
void G_quant_add_rule(struct Quant *q, DCELL dLow, DCELL dHigh, CELL cLow, CELL cHigh)
FILE * G_fopen_new(const char *element, const char *name)
Open a new database file.
G_warning("category support for [%s] in mapset [%s] %s", name, mapset, type)
int G_get_fp_range_min_max(const struct FPRange *range, DCELL *min, DCELL *max)
Extract the min/max from the range structure r. If the range structure has no defined min/max (first!...
FILE * G_fopen_new_misc(const char *dir, const char *element, const char *name)
open a new database file
int G_read_fp_range(const char *name, const char *mapset, struct FPRange *drange)
Read the floating point range file f_range. This file is written in binary using XDR format...
int G__make_mapset_element(const char *p_element)
Create element in the current mapset.
int G_remove_misc(const char *dir, const char *element, const char *name)
Remove a database misc file.
FILE * G_fopen_old(const char *element, const char *name, const char *mapset)
Open a database file for reading.
RASTER_MAP_TYPE G_raster_map_type(const char *name, const char *mapset)
Determine raster data type.
void G_quant_set_pos_infinite_rule(struct Quant *q, DCELL dRight, CELL c)
int G_quant_get_pos_infinite_rule(const struct Quant *q, DCELL *dRight, CELL *c)
int G__name_is_fully_qualified(const char *fullname, char *name, char *mapset)
Check if map name is fully qualified (map @ mapset)