GRASS 8 Programmer's Manual 8.6.0dev(2026)-1878fdfec5
Loading...
Searching...
No Matches
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 SPDX-FileCopyrightText: 2001-2020 GRASS Development Team
7 SPDX-License-Identifier: GPL-2.0-or-later
8
9 \author Original author CERL
10 */
11
12#include <string.h>
13#include <stdlib.h>
14
15#include <grass/gis.h>
16#include <grass/raster.h>
17#include <grass/glocale.h>
18
19/*!
20 \brief Read the raster header
21
22 The raster header for the raster map <i>name</i> in the specified
23 <i>mapset</i> is read into the <i>cellhd</i> structure. If there is
24 an error reading the raster header file, G_fatal_error() is called.
25
26 Cell header files may contain either grid cell header information or
27 reclass information. If it is a reclass file, it will specify the
28 map and mapset names of the actual grid cell file being
29 reclassed. Rast_get_cellhd(), upon reading reclass information will go
30 read the cell header information for the referenced file. Only one
31 reference is allowed.
32
33 \param name name of map
34 \param mapset mapset that map belongs to
35 \param[out] cellhd structure to hold cell header info
36
37 \return void
38 */
39void Rast_get_cellhd(const char *name, const char *mapset,
40 struct Cell_head *cellhd)
41{
42 FILE *fp;
43 int is_reclass;
45 const char *detail;
46
47 /*
48 is_reclass = Rast_is_reclass (name, mapset, real_name, real_mapset);
49 if (is_reclass < 0)
50 {
51 sprintf (buf,"Can't read header file for [%s in %s]\n", name, mapset);
52 tail = buf + strlen(buf);
53 strcpy (tail, "It is a reclass file, but with an invalid format");
54 G_warning(buf);
55 return -1;
56 }
57 */
59 if (is_reclass) {
60 fp = G_fopen_old("cellhd", real_name, real_mapset);
61 if (!fp) {
63 ? _("However, that raster map is missing."
64 " Perhaps, it was deleted by mistake.")
65 : _("However, header file of that raster map can't be"
66 " opened. It seems that it was corrupted after"
67 " creating the reclass raster map.");
69 _("Unable to read header file for raster map <%s@%s>. "
70 "It is a reclass of raster map <%s@%s>. %s"),
71 name, mapset, real_name, real_mapset, detail);
72 }
73 }
74 else {
75 fp = G_fopen_old("cellhd", name, mapset);
76 if (!fp)
77 G_fatal_error(_("Unable to open header file for raster map <%s@%s>."
78 " It seems that some previous step failed and"
79 " created an incomplete raster map."),
80 name, mapset);
81 }
82
83 G__read_Cell_head(fp, cellhd);
84 fclose(fp);
85}
const char * G_find_raster(char *, const char *)
Find a raster map.
Definition find_rast.c:52
void G__read_Cell_head(FILE *, struct Cell_head *)
Read cell header (for internal use only)
Definition rd_cellhd.c:54
void void void void G_fatal_error(const char *,...) __attribute__((format(printf
FILE * G_fopen_old(const char *, const char *, const char *)
Open a database file for reading.
Definition gis/open.c:250
int Rast_is_reclass(const char *, const char *, char[256], char[256])
Check if raster map is reclassified.
Definition reclass.c:42
void Rast_get_cellhd(const char *name, const char *mapset, struct Cell_head *cellhd)
Read the raster header.
Definition get_cellhd.c:39
#define GMAPSET_MAX
Definition gis.h:194
#define GNAME_MAX
Definition gis.h:193
#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:443