GRASS GIS 7 Programmer's Manual  7.5.svn(2017)-r71759
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
get_cellhd.c
Go to the documentation of this file.
1 /*!
2  \file lib/raster/get_cellhd.c
3 
4  \brief Raster library - Read raster map header
5 
6  (C) 2001-2009 by the GRASS Development Team
7 
8  This program is free software under the GNU General Public License
9  (>=v2). Read the file COPYING that comes with GRASS for details.
10 
11  \author Original author CERL
12  */
13 
14 #include <string.h>
15 #include <stdlib.h>
16 
17 #include <grass/gis.h>
18 #include <grass/raster.h>
19 #include <grass/glocale.h>
20 
21 /*!
22  \brief Read the raster header
23 
24  The raster header for the raster map <i>name</i> in the specified
25  <i>mapset</i> is read into the <i>cellhd</i> structure. If there is
26  an error reading the raster header file, a diagnostic message is
27  printed and -1 is returned. Otherwise, 0 is returned.
28 
29  <b>Note</b>:a warning message for errors encountered.
30 
31  Cell header files may contain either grid cell header information or
32  reclass information. If it is a reclass file, it will specify the
33  map and mapset names of the actual grid cell file being
34  reclassed. Rast_get_cellhd(), upon reading reclass information will go
35  read the cell header information for the referenced file. Only one
36  reference is allowed.
37 
38  \param name name of map
39  \param mapset mapset that map belongs to
40  \param[out] cellhd structure to hold cell header info
41 
42  \return void
43  */
44 void Rast_get_cellhd(const char *name, const char *mapset,
45  struct Cell_head *cellhd)
46 {
47  FILE *fp;
48  int is_reclass;
49  char real_name[GNAME_MAX], real_mapset[GMAPSET_MAX];
50 
51  /*
52  is_reclass = Rast_is_reclass (name, mapset, real_name, real_mapset);
53  if (is_reclass < 0)
54  {
55  sprintf (buf,"Can't read header file for [%s in %s]\n", name, mapset);
56  tail = buf + strlen(buf);
57  strcpy (tail, "It is a reclass file, but with an invalid format");
58  G_warning(buf);
59  return -1;
60  }
61  */
62  is_reclass = (Rast_is_reclass(name, mapset, real_name, real_mapset) > 0);
63  if (is_reclass) {
64  fp = G_fopen_old("cellhd", real_name, real_mapset);
65  if (!fp)
66  G_fatal_error(_("Unable to read header file for raster map <%s@%s>. "
67  "It is a reclass of raster map <%s@%s> %s"),
68  name, mapset, real_name, real_mapset,
69  !G_find_raster(real_name, real_mapset)
70  ? _("which is missing.")
71  : _("whose header file can't be opened."));
72  }
73  else {
74  fp = G_fopen_old("cellhd", name, mapset);
75  if (!fp)
76  G_fatal_error(_("Unable to open header file for raster map <%s@%s>"),
77  name, mapset);
78  }
79 
80  G__read_Cell_head(fp, cellhd, 1);
81  fclose(fp);
82 }
const char * G_find_raster(char *name, const char *mapset)
Find a raster map.
Definition: find_rast.c:55
#define GMAPSET_MAX
Definition: gis.h:149
2D/3D raster map header (used also for region)
Definition: gis.h:390
void G__read_Cell_head(FILE *fd, struct Cell_head *cellhd, int is_cellhd)
Read cell header (for internal use only)
Definition: rd_cellhd.c:57
void G_fatal_error(const char *msg,...)
Print a fatal error message to stderr.
Definition: gis/error.c:159
void Rast_get_cellhd(const char *name, const char *mapset, struct Cell_head *cellhd)
Read the raster header.
Definition: get_cellhd.c:44
int Rast_is_reclass(const char *name, const char *mapset, char *rname, char *rmapset)
Check if raster map is reclassified.
Definition: reclass.c:43
fclose(fd)
#define GNAME_MAX
Definition: gis.h:148
#define _(str)
Definition: glocale.h:13
FILE * G_fopen_old(const char *element, const char *name, const char *mapset)
Open a database file for reading.
Definition: gis/open.c:253
const char * name
Definition: named_colr.c:7