GRASS GIS 8 Programmer's Manual  8.5.0dev(2024)-602118adcc
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-2020 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, G_fatal_error() is called.
27 
28  Cell header files may contain either grid cell header information or
29  reclass information. If it is a reclass file, it will specify the
30  map and mapset names of the actual grid cell file being
31  reclassed. Rast_get_cellhd(), upon reading reclass information will go
32  read the cell header information for the referenced file. Only one
33  reference is allowed.
34 
35  \param name name of map
36  \param mapset mapset that map belongs to
37  \param[out] cellhd structure to hold cell header info
38 
39  \return void
40  */
41 void Rast_get_cellhd(const char *name, const char *mapset,
42  struct Cell_head *cellhd)
43 {
44  FILE *fp;
45  int is_reclass;
46  char real_name[GNAME_MAX], real_mapset[GMAPSET_MAX];
47  const char *detail;
48 
49  /*
50  is_reclass = Rast_is_reclass (name, mapset, real_name, real_mapset);
51  if (is_reclass < 0)
52  {
53  sprintf (buf,"Can't read header file for [%s in %s]\n", name, mapset);
54  tail = buf + strlen(buf);
55  strcpy (tail, "It is a reclass file, but with an invalid format");
56  G_warning(buf);
57  return -1;
58  }
59  */
60  is_reclass = (Rast_is_reclass(name, mapset, real_name, real_mapset) > 0);
61  if (is_reclass) {
62  fp = G_fopen_old("cellhd", real_name, real_mapset);
63  if (!fp) {
64  detail = !G_find_raster(real_name, real_mapset)
65  ? _("However, that raster map is missing."
66  " Perhaps, it was deleted by mistake.")
67  : _("However, header file of that raster map can't be"
68  " opened. It seems that it was corrupted after"
69  " creating the reclass raster map.");
71  _("Unable to read header file for raster map <%s@%s>. "
72  "It is a reclass of raster map <%s@%s>. %s"),
73  name, mapset, real_name, real_mapset, detail);
74  }
75  }
76  else {
77  fp = G_fopen_old("cellhd", name, mapset);
78  if (!fp)
79  G_fatal_error(_("Unable to open header file for raster map <%s@%s>."
80  " It seems that some previous step failed and"
81  " created an incomplete raster map."),
82  name, mapset);
83  }
84 
85  G__read_Cell_head(fp, cellhd);
86  fclose(fp);
87 }
FILE * G_fopen_old(const char *, const char *, const char *)
Open a database file for reading.
Definition: gis/open.c:251
void G__read_Cell_head(FILE *, struct Cell_head *)
Read cell header (for internal use only)
Definition: rd_cellhd.c:56
void void void void G_fatal_error(const char *,...) __attribute__((format(printf
const char * G_find_raster(char *, const char *)
Find a raster map.
Definition: find_rast.c:55
int Rast_is_reclass(const char *, const char *, char *, char *)
Check if raster map is reclassified.
Definition: reclass.c:43
void Rast_get_cellhd(const char *name, const char *mapset, struct Cell_head *cellhd)
Read the raster header.
Definition: get_cellhd.c:41
#define GMAPSET_MAX
Definition: gis.h:192
#define GNAME_MAX
Definition: gis.h:191
#define _(str)
Definition: glocale.h:10
const char * name
Definition: named_colr.c:6
2D/3D raster map header (used also for region)
Definition: gis.h:440