34 char str1[100], str2[100];
41 fprintf(fd,
"# %ld categories\n", (
long)cats->
num);
47 fprintf(fd,
"%s\n", cats->
fmt !=
NULL ? cats->
fmt :
"");
48 fprintf(fd,
"%.2f %.2f %.2f %.2f\n",
49 cats->
m1, cats->
a1, cats->
m2, cats->
a2);
54 if ((cats->
fmt && cats->
fmt[0]) || (descr && descr[0])) {
56 sprintf(str1,
"%.10f", val1);
58 fprintf(fd,
"%s:%s\n", str1, descr !=
NULL ? descr :
"");
61 sprintf(str1,
"%.10f", val1);
63 sprintf(str2,
"%.10f", val2);
65 fprintf(fd,
"%s:%s:%s\n", str1, str2,
66 descr !=
NULL ? descr :
"");
77 read_cats(
const char *
name,
const char *mapset,
struct Categories *pcats)
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)
182 switch (read_cats(name, mapset, pcats)) {
193 G_warning(
"category support for [%s] in mapset [%s] %s",
int G_getl(char *, int, FILE *)
Gets a line of text from a file.
#define RASTER3D_CATS_ELEMENT
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...
void G_strip(char *)
Removes all leading and trailing white space from string.
int Rast_set_cat(const void *, const void *, const char *, struct Categories *, RASTER_MAP_TYPE)
Set a raster category label.
int Rast_quant_nof_rules(const struct Quant *)
Returns the number of quantization rules defined.
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...
FILE * G_fopen_old_misc(const char *, const char *, const char *, const char *)
open a database misc file for reading
char * Rast_get_ith_d_cat(const struct Categories *, int, DCELL *, DCELL *)
Get category description (DCELL)
void Rast_init_cats(const char *, struct Categories *)
Initialize category structure.
int Rast_set_c_cat(const CELL *, const CELL *, const char *, struct Categories *)
Set a raster category label (CELL)
#define RASTER3D_DIRECTORY
FILE * G_fopen_new_misc(const char *, const char *, const char *)
open a new database misc file
void G_warning(const char *,...) __attribute__((format(printf
void Rast_set_cats_fmt(const char *, double, double, double, double, struct Categories *)
Set category fmt (?)
void G_trim_decimal(char *)
Removes trailing zeros from decimal number.