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);
168 G_warning(
_(
"Too many reclass categories for <%s@%s>"),
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) {
229 strcpy(*rmapset, arg);
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);
284 G_warning(
_(
"Unable to create header file for <%s@%s>"),
289 fprintf(fd,
"reclass\n");
290 fprintf(fd,
"name: %s\n", reclass->
name);
291 fprintf(fd,
"mapset: %s\n", reclass->
mapset);
294 for (min = 0; min < reclass->
num; min++)
298 for (max = reclass->
num - 1; max >= 0; max--)
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]);
322 strcpy(buf2, reclass->
name);
323 if ((p = strchr(buf2,
'@')))
329 fd = fopen(buf1,
"a+");
332 G_warning(
_(
"Unable to create dependency file in <%s@%s>"),
344 if (!
G_getl2(buf,
sizeof(buf), fd))
346 if (strcmp(xname, buf) == 0) {
353 fprintf(fd,
"%s\n", xname);
361 static FILE *fopen_cellhd_new(
const char *
name)
366 static int get_reclass_table(FILE * fd,
struct Reclass *reclass)
370 int first, null_str_size;
381 null_str_size = strlen(NULL_STRING);
384 while (fgets(buf,
sizeof buf, fd)) {
387 if (sscanf(buf,
"#%d", &cat) == 1) {
392 if (strncmp(buf, NULL_STRING, null_str_size) == 0)
395 if (sscanf(buf,
"%d", &cat) != 1)
399 len = (long)n *
sizeof(
CELL);
401 if (len != (
int)len) {
407 reclass->
table[n - 1] = cat;
409 reclass->
max = reclass->
min + n - 1;
int G_getl2(char *, int, FILE *)
Gets a line of text from a file of any pedigree.
char * G_file_name_misc(char *, const char *, const char *, const char *, const char *)
Builds full path names to GIS misc data files.
void void void void G_fatal_error(const char *,...) __attribute__((format(printf
int Rast_get_reclass(const char *name, const char *mapset, struct Reclass *reclass)
Get reclass.
void Rast_set_c_null_value(CELL *, int)
To set a number of CELL raster values to NULL.
void G_free(void *)
Free allocated memory.
void Rast_free_reclass(struct Reclass *reclass)
Free Reclass structure.
int Rast_put_reclass(const char *name, const struct Reclass *reclass)
Put reclass.
FILE * G_fopen_new(const char *, const char *)
Open a new database file.
char * G_fully_qualified_name(const char *, const char *)
Get fully qualified element name.
int Rast_is_reclass(const char *name, const char *mapset, char *rname, char *rmapset)
Check if raster map is reclassified.
FILE * G_fopen_old_misc(const char *, const char *, const char *, const char *)
open a database file for reading
void G_fseek(FILE *, off_t, int)
Change the file position of the stream.
FILE * G_fopen_old(const char *, const char *, const char *)
Open a database file for reading.
int Rast_is_reclassed_to(const char *name, const char *mapset, int *nrmaps, char ***rmaps)
Get child reclass maps list.
const char * G_mapset(void)
Get current mapset name.
void G_warning(const char *,...) __attribute__((format(printf
char * G_store(const char *)
Copy string to allocated memory.
#define Rast_is_c_null_value(cellVal)