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