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];
285 char xname[GNAME_MAX], xmapset[GMAPSET_MAX];
289 if (strcmp(xmapset, mapset) != 0)
294 if (strcmp(
G_mapset(), mapset) == 0) {
301 sprintf(element,
"quant2/%s", mapset);
310 quant_write(fd, quant);