33 char str1[100], str2[100];
40 fprintf(fd,
"# %ld categories\n", (
long)cats->
num);
46 fprintf(fd,
"%s\n", cats->
fmt !=
NULL ? cats->
fmt :
"");
47 fprintf(fd,
"%.2f %.2f %.2f %.2f\n", cats->
m1, cats->
a1, cats->
m2,
53 if ((cats->
fmt && cats->
fmt[0]) || (descr && descr[0])) {
55 sprintf(str1,
"%.10f", val1);
57 fprintf(fd,
"%s:%s\n", str1, descr !=
NULL ? descr :
"");
60 sprintf(str1,
"%.10f", val1);
62 sprintf(str2,
"%.10f", val2);
64 fprintf(fd,
"%s:%s:%s\n", str1, str2,
65 descr !=
NULL ? descr :
"");
75 static int read_cats(
const char *
name,
const char *mapset,
92 if (
G_getl(buff,
sizeof(buff), fd) == 0)
95 if (sscanf(buff,
"# %ld", &num) == 1)
97 else if (sscanf(buff,
"%ld", &num) == 1)
101 if (
G_getl(buff,
sizeof(buff), fd) == 0)
111 float m1, a1, m2, a2;
113 if (
G_getl(fmt,
sizeof(fmt), fd) == 0)
116 if (
G_getl(buff,
sizeof(buff), fd) == 0)
118 if (sscanf(buff,
"%f %f %f %f", &m1, &a1, &m2, &a2) != 4)
124 for (cat = 0;; cat++) {
127 if (
G_getl(buff,
sizeof(buff), fd) == 0)
134 if (sscanf(buff,
"%1s", label) != 1)
141 if (sscanf(buff,
"%lf:%lf:%[^\n]", &val1, &val2, label) == 3)
143 else if (sscanf(buff,
"%d:%[^\n]", &cat, label) >= 1)
145 else if (sscanf(buff,
"%lf:%[^\n]", &val1, label) >= 1)
181 switch (read_cats(
name, mapset, pcats)) {
192 G_warning(
"category support for [%s] in mapset [%s] %s",
name, mapset,
FILE * G_fopen_old_misc(const char *, const char *, const char *, const char *)
open a database misc file for reading
void G_warning(const char *,...) __attribute__((format(printf
FILE * G_fopen_new_misc(const char *, const char *, const char *)
open a new database misc file
void G_trim_decimal(char *)
Removes trailing zeros from decimal number.
void G_strip(char *)
Removes all leading and trailing white space from string.
int G_getl(char *, int, FILE *)
Gets a line of text from a file.
char * Rast_get_ith_d_cat(const struct Categories *, int, DCELL *, DCELL *)
Get category description (DCELL)
void Rast_set_cats_fmt(const char *, double, double, double, double, struct Categories *)
Set category fmt (?)
void Rast_init_cats(const char *, struct Categories *)
Initialize category structure.
int Rast_set_cat(const void *, const void *, const char *, struct Categories *, RASTER_MAP_TYPE)
Set a raster category label.
int Rast_set_c_cat(const CELL *, const CELL *, const char *, struct Categories *)
Set a raster category label (CELL)
int Rast_quant_nof_rules(const struct Quant *)
Returns the number of quantization rules defined.
int Rast3d_write_cats(const char *name, struct Categories *cats)
Writes the categories stored in the cats structure into the categories file for map name in the curre...
int Rast3d_read_cats(const char *name, const char *mapset, struct Categories *pcats)
Reads the categories file for map name in mapset and stores the categories in the pcats structure....
#define RASTER3D_DIRECTORY
#define RASTER3D_CATS_ELEMENT