GRASS GIS 7 Programmer's Manual  7.7.svn(2018)-r73390
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 
97 
98  cname = getenv("GRASS_COMPRESSOR");
99  /* 1: RLE
100  * 2: ZLIB (DEFLATE)
101  * 3: LZ4
102  * 4: BZIP2
103  * 5: ZSTD */
104  if (cname && *cname) {
105  /* ask gislib */
107  if (R__.compression_type < 1) {
108  if (R__.compression_type < 0) {
109  G_warning(_("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 maps, using default %s"),
115  }
116  /* use default */
118  }
120  G_warning(_("This GRASS version does not support %s compression, using default %s"),
122  /* use default */
124  }
125  G_debug(1, "Using %s compression",
127  }
128 
129  nulls = getenv("GRASS_COMPRESS_NULLS");
130  R__.compress_nulls = (nulls && atoi(nulls) == 0) ? 0 : 1;
131 
133 
134  initialized = 1;
135 
136  return 0;
137 }
138 
139 void Rast_init_all(void)
140 {
141  Rast__init();
143  Rast_init_gdal();
144 }
int G_default_compressor(void)
Definition: compress.c:126
int Rast__check_for_auto_masking(void)
Checks for auto masking.
Definition: auto_mask.c:37
void Rast_init_all(void)
Definition: raster/init.c:139
void G_add_error_handler(void(*func)(void *), void *closure)
Add new error handler.
Definition: gis/handler.c:70
Definition: R.h:88
void Rast__init_window(void)
void Rast_init(void)
Initialize GRASS GIS engine.
Definition: raster/init.c:44
char * G_compressor_name(int number)
Definition: compress.c:118
RASTER_MAP_TYPE fp_type
Definition: R.h:90
void Rast__init(void)
Definition: raster/init.c:65
int G_is_initialized(int *p)
Definition: counter.c:59
#define NULL
Definition: ccmath.h:32
void G_initialize_done(int *p)
Definition: counter.c:76
void G_fatal_error(const char *msg,...)
Print a fatal error message to stderr.
Definition: gis/error.c:160
#define DCELL_TYPE
Definition: raster.h:13
void Rast__unopen_all(void)
Unopen all raster maps.
Definition: raster/close.c:129
int G_debug(int level, const char *msg,...)
Print debugging message.
Definition: debug.c:65
void Rast__error_handler(void *p)
Definition: raster/init.c:73
int mask_fd
Definition: R.h:91
int auto_mask
Definition: R.h:92
int G_check_compressor(int number)
Definition: compress.c:140
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
int G_compressor_number(char *name)
Definition: compress.c:100
int CELL
Definition: gis.h:580
void Rast_init_gdal(void)
Initialization.
Definition: gdal.c:214
#define _(str)
Definition: glocale.h:13
#define FCELL_TYPE
Definition: raster.h:12
int want_histogram
Definition: R.h:93
int nbytes
Definition: R.h:94
char * getenv()
void G_warning(const char *msg,...)
Print a warning message to stderr.
Definition: gis/error.c:204
void init(double work[])
Definition: as177.c:65
int compression_type
Definition: R.h:95