GRASS Programmer's Manual  6.5.svn(2014)-r66266
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
get_cellhd.c
Go to the documentation of this file.
1 
14 #include <string.h>
15 #include <stdlib.h>
16 #include <grass/gis.h>
17 #include <grass/glocale.h>
18 
45 int G_get_cellhd(const char *name, const char *mapset,
46  struct Cell_head *cellhd)
47 {
48  FILE *fd;
49  int is_reclass;
50  char real_name[GNAME_MAX], real_mapset[GMAPSET_MAX];
51  char buf[1024];
52  char *tail;
53  char *err;
54 
55  /*
56  is_reclass = G_is_reclass (name, mapset, real_name, real_mapset);
57  if (is_reclass < 0)
58  {
59  sprintf (buf,"Can't read header file for [%s in %s]\n", name, mapset);
60  tail = buf + strlen(buf);
61  strcpy (tail, "It is a reclass file, but with an invalid format");
62  G_warning(buf);
63  return -1;
64  }
65  */
66  is_reclass = (G_is_reclass(name, mapset, real_name, real_mapset) > 0);
67  if (is_reclass) {
68  fd = G_fopen_old("cellhd", real_name, real_mapset);
69  if (fd == NULL) {
70  sprintf(buf,
71  _("Unable to read header file for raster map <%s@%s>."),
72  name, mapset);
73  tail = buf + strlen(buf);
74  sprintf(tail, _(" It is a reclass of raster map <%s@%s> "),
75  real_name, real_mapset);
76  tail = buf + strlen(buf);
77  if (!G_find_cell(real_name, real_mapset))
78  sprintf(tail, _("which is missing."));
79  else
80  sprintf(tail, _("whose header file can't be opened."));
81  G_warning(buf);
82  return -1;
83  }
84  }
85  else {
86  fd = G_fopen_old("cellhd", name, mapset);
87  if (fd == NULL) {
88  G_warning(_("Unable to open header file for raster map <%s@%s>"),
89  name, mapset);
90  return -1;
91  }
92  }
93 
94  err = G__read_Cell_head(fd, cellhd, 1);
95  fclose(fd);
96 
97  if (err == NULL)
98  return 0;
99 
100  sprintf(buf, _("Unable to read header file for raster map <%s@%s>."),
101  name, mapset);
102  tail = buf + strlen(buf);
103  if (is_reclass) {
104  sprintf(tail,
105  _(" It is a reclass of raster map <%s@%s> whose header file is invalid."),
106  real_name, real_mapset);
107  }
108  else
109  sprintf(tail, _(" Invalid format."));
110  tail = buf + strlen(buf);
111  strcpy(tail, err);
112 
113  G_free(err);
114 
115  G_warning(buf);
116  return -1;
117 }
sprintf(buf2,"%s", G3D_CATS_ELEMENT)
void G_free(void *buf)
Free allocated memory.
Definition: gis/alloc.c:142
int G_get_cellhd(const char *name, const char *mapset, struct Cell_head *cellhd)
Read the raster header.
Definition: get_cellhd.c:45
FILE * fd
Definition: g3dcolor.c:368
string name
Definition: render.py:1314
const char * err
Definition: g3dcolor.c:50
char * G_find_cell(char *name, const char *mapset)
find a raster map
Definition: find_cell.c:63
int G_is_reclass(const char *name, const char *mapset, char *rname, char *rmapset)
reclass file?
Definition: reclass.c:30
char buf[GNAME_MAX+sizeof(G3D_DIRECTORY)+2]
Definition: g3drange.c:62
return NULL
Definition: dbfopen.c:1394
G_warning("category support for [%s] in mapset [%s] %s", name, mapset, type)
char * G__read_Cell_head(FILE *fd, struct Cell_head *cellhd, int is_cellhd)
Definition: rd_cellhd.c:53
fclose(fd)
FILE * G_fopen_old(const char *element, const char *name, const char *mapset)
Open a database file for reading.
Definition: gis/open.c:226