24 #define QUANT_FILE_NAME "f_quant" 26 static int quant_parse_file(FILE *,
struct Quant *);
31 static int quant_load_range(
struct Quant *quant,
const char *
name,
const char *mapset)
43 G_warning(
_(
"Floating data range for raster map <%s> is empty"),
52 G_warning(
_(
"Integer data range for raster map <%s> is empty"),
106 " table for CELL raster map <%s>"),
112 if (strlen(mapset) == 0)
114 else if (strcmp(xmapset, mapset) != 0)
120 sprintf(element,
"quant2/%s", mapset);
122 parsStat = quant_parse_file(fd, quant);
127 "quantization file in quant2 for raster map <%s> is empty",
135 G_warning(
_(
"Quantization file for raster map <%s> is missing"),
139 parsStat = quant_parse_file(fd, quant);
145 G_warning(
_(
"Quantization file for raster map <%s> is empty"),
166 static int quant_parse_file(FILE * fd,
struct Quant *quant)
171 int foundNegInf = 0, foundPosInf = 0;
173 while (fgets(buf,
sizeof(buf), fd)) {
174 if (strncmp(buf,
"truncate", 8) == 0) {
178 if (strncmp(buf,
"round", 5) == 0) {
182 switch (sscanf(buf,
"%lf:%lf:%d:%d", &dLow, &dHigh, &cLow, &cHigh)) {
190 switch (sscanf(buf,
"*:%lf:%d", &dLow, &cLow)) {
198 switch (sscanf(buf,
"%lf:*:%d", &dLow, &cLow)) {
220 static void quant_write(FILE * fd,
const struct Quant *quant)
227 fprintf(fd,
"truncate");
231 fprintf(fd,
"round");
235 fprintf(fd,
"*:%.20g:%d\n", dLow, cLow);
238 fprintf(fd,
"%.20g:*:%d\n", dLow, cLow);
242 fprintf(fd,
"%.20g:%.20g:%d", dLow, dHigh, cLow);
244 fprintf(fd,
":%d", cHigh);
269 const struct Quant *quant)
276 if (strcmp(xmapset, mapset) != 0)
281 if (strcmp(
G_mapset(), mapset) == 0) {
288 sprintf(element,
"quant2/%s", mapset);
295 quant_write(fd, quant);
int G_remove(const char *, const char *)
Remove a database file.
int Rast_quant_get_pos_infinite_rule(const struct Quant *, DCELL *, CELL *)
Returns in "dRight" and "c" the rule values.
#define Rast_is_d_null_value(dcellVal)
int G__make_mapset_element_misc(const char *, const char *)
Create misc element in the current mapset.
int G_remove_misc(const char *, const char *, const char *)
Remove a database misc file.
int Rast_quant_nof_rules(const struct Quant *)
Returns the number of quantization rules defined.
int Rast_read_range(const char *, const char *, struct Range *)
Read raster range (CELL)
void Rast_quant_free(struct Quant *)
Resets and frees allocated memory.
int Rast__quant_import(const char *name, const char *mapset, struct Quant *quant)
Reads quantization rules (internal use only)
void Rast_get_fp_range_min_max(const struct FPRange *, DCELL *, DCELL *)
Get minimum and maximum value from fp range.
FILE * G_fopen_new(const char *, const char *)
Open a new database file.
char * G_fully_qualified_name(const char *, const char *)
Get fully qualified element name.
FILE * G_fopen_old_misc(const char *, const char *, const char *, const char *)
open a database misc file for reading
int Rast_quant_get_neg_infinite_rule(const struct Quant *, DCELL *, CELL *)
Returns in "dLeft" and "c" the rule values.
FILE * G_fopen_old(const char *, const char *, const char *)
Open a database file for reading.
void Rast_quant_set_pos_infinite_rule(struct Quant *, DCELL, CELL)
Defines a rule for values "dRight" and larger.
int Rast_read_fp_range(const char *, const char *, struct FPRange *)
Read floating-point range.
FILE * G_fopen_new_misc(const char *, const char *, const char *)
open a new database misc file
void Rast_quant_add_rule(struct Quant *, DCELL, DCELL, CELL, CELL)
Adds a new rule to the set of quantization rules.
const char * G_mapset(void)
Get current mapset name.
void Rast_quant_get_ith_rule(const struct Quant *, int, DCELL *, DCELL *, CELL *, CELL *)
Returns the i'th quantization rule.
void G_warning(const char *,...) __attribute__((format(printf
void Rast_quant_set_neg_infinite_rule(struct Quant *, DCELL, CELL)
Defines a rule for values "dLeft" and smaller.
int G_name_is_fully_qualified(const char *, char *, char *)
Check if map name is fully qualified (map @ mapset)
#define Rast_is_c_null_value(cellVal)
int Rast__quant_export(const char *name, const char *mapset, const struct Quant *quant)
Writes the quantization rules (internal use only)
int G_make_mapset_object_group(const char *)
Create directory for group of elements of a given type.
void Rast_quant_reverse_rule_order(struct Quant *)
Rreverses the order in which the qunatization rules are stored.
void Rast_get_range_min_max(const struct Range *, CELL *, CELL *)
Get range min and max.
RASTER_MAP_TYPE Rast_map_type(const char *, const char *)
Determine raster data type.