20 static const char NULL_STRING[] =
"null";
21 static int reclass_type(FILE *,
char **,
char **);
22 static FILE *fopen_cellhd_old(
const char *,
const char *);
23 static FILE *fopen_cellhd_new(
const char *);
24 static int get_reclass_table(FILE *,
struct Reclass *);
49 fd = fopen_cellhd_old(
name, mapset);
53 type = reclass_type(fd, &rname, &rmapset);
84 char buf2[256], buf3[256];
94 for (i = 0; !feof(fd) && fgets(buf2, 255, fd);) {
96 for (j = 0, k = 0; j <
l; j++) {
98 ((buf2[j] ==
' ' || buf2[j] ==
'\t' || buf2[j] ==
'\n') && k))
100 else if (buf2[j] !=
' ' && buf2[j] !=
'\t')
108 *rmaps = (
char **)
G_realloc(*rmaps, i *
sizeof(
char *));
109 (*rmaps)[i - 1] = (
char *)
G_malloc(k + 1);
110 strncpy((*rmaps)[i - 1], buf3, k);
111 (*rmaps)[i - 1][k] = 0;
121 *rmaps = (
char **)
G_realloc(*rmaps, i *
sizeof(
char *));
122 (*rmaps)[i - 1] =
NULL;
146 fd = fopen_cellhd_old(
name, mapset);
151 reclass->
type = reclass_type(fd, &reclass->
name, &reclass->
mapset);
152 if (reclass->
type <= 0) {
154 return reclass->
type;
157 switch (reclass->
type) {
159 stat = get_reclass_table(fd, reclass);
171 G_warning(
_(
"Illegal reclass format in header file for <%s@%s>"),
185 switch (reclass->
type) {
187 if (reclass->
num > 0)
202 static int reclass_type(FILE *fd,
char **rname,
char **rmapset)
205 char label[128], arg[128];
210 if (fgets(buf,
sizeof(buf), fd) ==
NULL)
212 if (strncmp(buf,
"reclas", 6))
222 for (i = 0; i < 2; i++) {
223 if (fgets(buf,
sizeof buf, fd) ==
NULL)
225 if (sscanf(buf,
"%[^:]:%s", label, arg) != 2)
227 if (strncmp(label,
"maps", 4) == 0) {
233 else if (strncmp(label,
"name", 4) == 0) {
242 if (**rmapset && **rname)
248 static FILE *fopen_cellhd_old(
const char *
name,
const char *mapset)
270 switch (reclass->
type) {
272 if (reclass->
min > reclass->
max || reclass->
num <= 0) {
282 fd = fopen_cellhd_new(
name);
289 fprintf(fd,
"reclass\n");
290 fprintf(fd,
"name: %s\n", reclass->
name);
291 fprintf(fd,
"mapset: %s\n", reclass->
mapset);
311 fprintf(fd,
"#%ld\n", (
long)reclass->
min +
min);
314 fprintf(fd,
"%s\n", NULL_STRING);
316 fprintf(fd,
"%ld\n", (
long)reclass->
table[
min]);
323 if ((p = strchr(buf2,
'@')))
329 fd = fopen(buf1,
"a+");
332 G_warning(
_(
"Unable to create dependency file in <%s@%s>"),
345 if (!
G_getl2(buf,
sizeof(buf), fd))
347 if (strcmp(xname, buf) == 0) {
354 fprintf(fd,
"%s\n", xname);
362 static FILE *fopen_cellhd_new(
const char *
name)
367 static int get_reclass_table(FILE *fd,
struct Reclass *reclass)
371 int first, null_str_size;
382 null_str_size = strlen(NULL_STRING);
385 while (fgets(buf,
sizeof buf, fd)) {
388 if (sscanf(buf,
"#%d", &cat) == 1) {
393 if (strncmp(buf, NULL_STRING, null_str_size) == 0)
396 if (sscanf(buf,
"%d", &cat) != 1)
400 len = (long)n *
sizeof(
CELL);
402 if (len != (
int)len) {
408 reclass->
table[n - 1] = cat;
410 reclass->
max = reclass->
min + n - 1;
char * G_file_name_misc(char *, const char *, const char *, const char *, const char *)
Builds full path names to GIS misc data files.
FILE * G_fopen_old(const char *, const char *, const char *)
Open a database file for reading.
int G_getl2(char *, int, FILE *)
Gets a line of text from a file of any pedigree.
void G_free(void *)
Free allocated memory.
FILE * G_fopen_old_misc(const char *, const char *, const char *, const char *)
open a database misc file for reading
void void void void G_fatal_error(const char *,...) __attribute__((format(printf
void G_warning(const char *,...) __attribute__((format(printf
void G_fseek(FILE *, off_t, int)
Change the file position of the stream.
const char * G_mapset(void)
Get current mapset name.
char * G_fully_qualified_name(const char *, const char *)
Get fully qualified element name.
char * G_store(const char *)
Copy string to allocated memory.
FILE * G_fopen_new(const char *, const char *)
Open a new database file.
void Rast_set_c_null_value(CELL *, int)
To set a number of CELL raster values to NULL.
#define Rast_is_c_null_value(cellVal)
int Rast_is_reclass(const char *name, const char *mapset, char *rname, char *rmapset)
Check if raster map is reclassified.
int Rast_get_reclass(const char *name, const char *mapset, struct Reclass *reclass)
Get reclass.
int Rast_put_reclass(const char *name, const struct Reclass *reclass)
Put reclass.
int Rast_is_reclassed_to(const char *name, const char *mapset, int *nrmaps, char ***rmaps)
Get child reclass maps list.
void Rast_free_reclass(struct Reclass *reclass)
Free Reclass structure.