GRASS 8 Programmer's Manual  8.5.0dev(2025)-c070206eb1
raster/init.c
Go to the documentation of this file.
1 /**
2  * \file lib/raster/init.c
3  *
4  * \brief Raster Library - Handles program initialization.
5  *
6  * (C) 2001-2008 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 GRASS Development Team
12  *
13  * \date 2000-2008
14  */
15 
16 #include <stdio.h>
17 #include <unistd.h>
18 #include <stdlib.h>
19 #include <string.h>
20 #include <sys/stat.h>
21 #include <locale.h>
22 
23 #include <grass/gis.h>
24 #include <grass/raster.h>
25 #include <grass/glocale.h>
26 
27 #include "R.h"
28 
29 struct R__ R__;
30 
31 static int initialized = 0; /** Is set when engine is initialized */
32 static int init(void);
33 
34 /**
35  * \brief Initialize GRASS engine.
36  *
37  * Initializes GIS engine and ensures a valid mapset is available.
38  *
39  * \return always returns 0 on success
40  * \return exit() is called on error
41  */
42 void Rast_init(void)
43 {
44  Rast__init();
45 }
46 
47 /**
48  * \brief Checks to see if GIS engine is initialized.
49  *
50  * \return
51  */
52 void Rast__check_init(void)
53 {
54  if (initialized)
55  return;
56 
57  G_fatal_error(_("Raster library not initialized. Programmer forgot to call "
58  "Rast_init()."));
59 }
60 
61 void Rast__init(void)
62 {
63  if (G_is_initialized(&initialized))
64  return;
65  init();
66  G_initialize_done(&initialized);
67 }
68 
70 {
72 }
73 
74 static int init(void)
75 {
76  char *nulls, *cname;
77 
79 
80  /* no histograms */
81  R__.want_histogram = 0;
82 
83  /* set the write type for floating maps */
84  R__.fp_type = getenv("GRASS_FP_DOUBLE") ? DCELL_TYPE : FCELL_TYPE;
85 
86  /* Set masking flag unknown */
87  R__.auto_mask = -1;
88  R__.mask_fd = -1;
89 
90  R__.nbytes = sizeof(CELL);
91 
92  R__.fileinfo_count = 0;
93  R__.fileinfo = NULL;
94 
96 
97  cname = getenv("GRASS_COMPRESSOR");
98  /* 1: RLE
99  * 2: ZLIB (DEFLATE)
100  * 3: LZ4
101  * 4: BZIP2
102  * 5: ZSTD */
103  if (cname && *cname) {
104  /* ask gislib */
106  if (R__.compression_type < 1) {
107  if (R__.compression_type < 0) {
108  G_warning(
109  _("Unknown compression method <%s>, using default %s"),
111  }
112  if (R__.compression_type == 0) {
113  G_warning(_("No compression is not supported for GRASS raster "
114  "maps, using default %s"),
116  }
117  /* use default */
119  }
121  G_warning(_("This GRASS version does not support %s compression, "
122  "using default %s"),
124  /* use default */
126  }
127  G_debug(1, "Using %s compression",
129  }
130 
131  nulls = getenv("GRASS_COMPRESS_NULLS");
132  R__.compress_nulls = (nulls && atoi(nulls) == 0) ? 0 : 1;
133 
135 
136  initialized = 1;
137 
138  return 0;
139 }
140 
141 void Rast_init_all(void)
142 {
143  Rast__init();
145  Rast_init_gdal();
146 }
void init(double work[])
Definition: as177.c:61
#define NULL
Definition: ccmath.h:32
void void void void G_fatal_error(const char *,...) __attribute__((format(printf
void G_warning(const char *,...) __attribute__((format(printf
int G_default_compressor(void)
Definition: compress.c:126
char * G_compressor_name(int)
Definition: compress.c:118
int G_compressor_number(char *)
Definition: compress.c:100
int G_check_compressor(int)
Definition: compress.c:140
void G_add_error_handler(void(*)(void *), void *)
Add new error handler.
Definition: gis/handler.c:71
int G_is_initialized(int *)
Definition: counter.c:60
void G_initialize_done(int *)
Definition: counter.c:77
int G_debug(int, const char *,...) __attribute__((format(printf
void Rast__init_window(void)
int Rast__check_for_auto_masking(void)
Checks for auto masking.
Definition: auto_mask.c:33
void Rast__unopen_all(void)
Unopen all raster maps.
Definition: raster/close.c:156
void Rast_init_gdal(void)
Initialization.
Definition: gdal.c:39
#define UNUSED
A macro for an attribute, if attached to a variable, indicating that the variable is not used.
Definition: gis.h:46
int CELL
Definition: gis.h:634
#define _(str)
Definition: glocale.h:10
void Rast_init(void)
Initialize GRASS engine.
Definition: raster/init.c:42
void Rast_init_all(void)
Definition: raster/init.c:141
void Rast__error_handler(void *p)
Definition: raster/init.c:69
void Rast__check_init(void)
Checks to see if GIS engine is initialized.
Definition: raster/init.c:52
void Rast__init(void)
Definition: raster/init.c:61
#define FCELL_TYPE
Definition: raster.h:12
#define DCELL_TYPE
Definition: raster.h:13
Definition: R.h:87
int compress_nulls
Definition: R.h:94
struct fileinfo * fileinfo
Definition: R.h:101
int auto_mask
Definition: R.h:90
int compression_type
Definition: R.h:93
int want_histogram
Definition: R.h:91
int fileinfo_count
Definition: R.h:100
RASTER_MAP_TYPE fp_type
Definition: R.h:88
int nbytes
Definition: R.h:92
int mask_fd
Definition: R.h:89