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,
44 G_warning(
_(
"Floating data range for raster map <%s> is empty"),
53 G_warning(
_(
"Integer data range for raster map <%s> is empty"),
107 " table for CELL raster map <%s>"),
113 if (strlen(mapset) == 0)
115 else if (strcmp(xmapset, mapset) != 0)
121 sprintf(
element,
"quant2/%s", mapset);
123 parsStat = quant_parse_file(fd, quant);
127 sprintf(buf,
"quantization file in quant2 for raster map <%s> is empty",
136 G_warning(
_(
"Quantization file for raster map <%s> is missing"),
140 parsStat = quant_parse_file(fd, quant);
147 G_warning(
_(
"Quantization file for raster map <%s> is empty"),
168 static int quant_parse_file(FILE *fd,
struct Quant *quant)
173 int foundNegInf = 0, foundPosInf = 0;
175 while (fgets(buf,
sizeof(buf), fd)) {
176 if (strncmp(buf,
"truncate", 8) == 0) {
180 if (strncmp(buf,
"round", 5) == 0) {
184 switch (sscanf(buf,
"%lf:%lf:%d:%d", &dLow, &dHigh, &cLow, &cHigh)) {
192 switch (sscanf(buf,
"*:%lf:%d", &dLow, &cLow)) {
200 switch (sscanf(buf,
"%lf:*:%d", &dLow, &cLow)) {
222 static void quant_write(FILE *fd,
const struct Quant *quant)
229 fprintf(fd,
"truncate");
233 fprintf(fd,
"round");
237 fprintf(fd,
"*:%.20g:%d\n", dLow, cLow);
240 fprintf(fd,
"%.20g:*:%d\n", dLow, cLow);
244 fprintf(fd,
"%.20g:%.20g:%d", dLow, dHigh, cLow);
246 fprintf(fd,
":%d", cHigh);
271 const struct Quant *quant)
278 if (strcmp(xmapset, mapset) != 0)
283 if (strcmp(
G_mapset(), mapset) == 0) {
290 sprintf(
element,
"quant2/%s", mapset);
297 quant_write(fd, quant);
int G_name_is_fully_qualified(const char *, char *, char *)
Check if map name is fully qualified (map @ mapset)
FILE * G_fopen_old(const char *, const char *, const char *)
Open a database file for reading.
FILE * G_fopen_old_misc(const char *, const char *, const char *, const char *)
open a database misc file for reading
int G__make_mapset_element_misc(const char *, const char *)
Create misc element in the current mapset.
void G_warning(const char *,...) __attribute__((format(printf
int G_make_mapset_object_group(const char *)
Create directory for group of elements of a given type.
FILE * G_fopen_new_misc(const char *, const char *, const char *)
open a new database misc file
const char * G_mapset(void)
Get current mapset name.
int G_remove(const char *, const char *)
Remove a database file.
int G_remove_misc(const char *, const char *, const char *)
Remove a database misc file.
char * G_fully_qualified_name(const char *, const char *)
Get fully qualified element name.
FILE * G_fopen_new(const char *, const char *)
Open a new database file.
int Rast_quant_get_neg_infinite_rule(const struct Quant *, DCELL *, CELL *)
Returns in "dLeft" and "c" the rule values.
int Rast_read_fp_range(const char *, const char *, struct FPRange *)
Read floating-point range.
void Rast_quant_set_pos_infinite_rule(struct Quant *, DCELL, CELL)
Defines a rule for values "dRight" and larger.
void Rast_quant_free(struct Quant *)
Resets and frees allocated memory.
void Rast_quant_set_neg_infinite_rule(struct Quant *, DCELL, CELL)
Defines a rule for values "dLeft" and smaller.
void Rast_get_fp_range_min_max(const struct FPRange *, DCELL *, DCELL *)
Get minimum and maximum value from fp range.
void Rast_quant_reverse_rule_order(struct Quant *)
Rreverses the order in which the qunatization rules are stored.
RASTER_MAP_TYPE Rast_map_type(const char *, const char *)
Determine raster data type.
void Rast_quant_add_rule(struct Quant *, DCELL, DCELL, CELL, CELL)
Adds a new rule to the set of quantization rules.
void Rast_get_range_min_max(const struct Range *, CELL *, CELL *)
Get range min and max.
int Rast_read_range(const char *, const char *, struct Range *)
Read raster range (CELL)
void Rast_quant_get_ith_rule(const struct Quant *, int, DCELL *, DCELL *, CELL *, CELL *)
Returns the i'th quantization rule.
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)
#define Rast_is_c_null_value(cellVal)
int Rast_quant_nof_rules(const struct Quant *)
Returns the number of quantization rules defined.
int Rast__quant_export(const char *name, const char *mapset, const struct Quant *quant)
Writes the quantization rules (internal use only)
int Rast__quant_import(const char *name, const char *mapset, struct Quant *quant)
Reads quantization rules (internal use only)