GRASS GIS 8 Programmer's Manual  8.4.0dev(2024)-5f6977e40c
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 GIS 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 GIS 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 
43 void Rast_init(void)
44 {
45  Rast__init();
46 }
47 
48 /**
49  * \brief Checks to see if GIS engine is initialized.
50  *
51  * \return
52  */
53 
54 void Rast__check_init(void)
55 {
56  if (initialized)
57  return;
58 
59  G_fatal_error(_("Raster library not initialized. Programmer forgot to call "
60  "Rast_init()."));
61 }
62 
63 void Rast__init(void)
64 {
65  if (G_is_initialized(&initialized))
66  return;
67  init();
68  G_initialize_done(&initialized);
69 }
70 
72 {
74 }
75 
76 static int init(void)
77 {
78  char *nulls, *cname;
79 
81 
82  /* no histograms */
83  R__.want_histogram = 0;
84 
85  /* set the write type for floating maps */
86  R__.fp_type = getenv("GRASS_FP_DOUBLE") ? DCELL_TYPE : FCELL_TYPE;
87 
88  /* Set masking flag unknown */
89  R__.auto_mask = -1;
90  R__.mask_fd = -1;
91 
92  R__.nbytes = sizeof(CELL);
93 
94  R__.fileinfo_count = 0;
95  R__.fileinfo = NULL;
96 
98 
99  cname = getenv("GRASS_COMPRESSOR");
100  /* 1: RLE
101  * 2: ZLIB (DEFLATE)
102  * 3: LZ4
103  * 4: BZIP2
104  * 5: ZSTD */
105  if (cname && *cname) {
106  /* ask gislib */
108  if (R__.compression_type < 1) {
109  if (R__.compression_type < 0) {
110  G_warning(
111  _("Unknown compression method <%s>, using default %s"),
113  }
114  if (R__.compression_type == 0) {
115  G_warning(_("No compression is not supported for GRASS raster "
116  "maps, using default %s"),
118  }
119  /* use default */
121  }
123  G_warning(_("This GRASS version does not support %s compression, "
124  "using default %s"),
126  /* use default */
128  }
129  G_debug(1, "Using %s compression",
131  }
132 
133  nulls = getenv("GRASS_COMPRESS_NULLS");
134  R__.compress_nulls = (nulls && atoi(nulls) == 0) ? 0 : 1;
135 
137 
138  initialized = 1;
139 
140  return 0;
141 }
142 
143 void Rast_init_all(void)
144 {
145  Rast__init();
147  Rast_init_gdal();
148 }
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:35
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:47
int CELL
Definition: gis.h:625
#define _(str)
Definition: glocale.h:10
void Rast_init(void)
Initialize GRASS GIS engine.
Definition: raster/init.c:43
void Rast_init_all(void)
Definition: raster/init.c:143
void Rast__error_handler(void *p UNUSED)
Definition: raster/init.c:71
void Rast__check_init(void)
Checks to see if GIS engine is initialized.
Definition: raster/init.c:54
void Rast__init(void)
Definition: raster/init.c:63
#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