GRASS 8 Programmer's Manual 8.6.0dev(2026)-1878fdfec5
Loading...
Searching...
No Matches
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 * SPDX-FileCopyrightText: 2001-2008 GRASS Development Team
7 * SPDX-License-Identifier: GPL-2.0-or-later
8 *
9 * \author GRASS Development Team
10 *
11 * \date 2000-2008
12 */
13
14#include <stdio.h>
15#include <unistd.h>
16#include <stdlib.h>
17#include <string.h>
18#include <sys/stat.h>
19#include <locale.h>
20
21#include <grass/gis.h>
22#include <grass/raster.h>
23#include <grass/glocale.h>
24
25#include "R.h"
26
27struct R__ R__;
28
29static int initialized = 0; /** Is set when engine is initialized */
30static int init(void);
31
32/**
33 * \brief Initialize GRASS engine.
34 *
35 * Initializes GIS engine and ensures a valid mapset is available.
36 *
37 * \return always returns 0 on success
38 * \return exit() is called on error
39 */
40void Rast_init(void)
41{
42 Rast__init();
43}
44
45/**
46 * \brief Checks to see if GIS engine is initialized.
47 *
48 * \return
49 */
51{
52 if (initialized)
53 return;
54
55 G_fatal_error(_("Raster library not initialized. Programmer forgot to call "
56 "Rast_init()."));
57}
58
59void Rast__init(void)
60{
61 if (G_is_initialized(&initialized))
62 return;
63 init();
64 G_initialize_done(&initialized);
65}
66
68{
70}
71
72static int init(void)
73{
74 char *nulls, *cname;
75
77
78 /* no histograms */
80
81 /* set the write type for floating maps */
82 R__.fp_type = getenv("GRASS_FP_DOUBLE") ? DCELL_TYPE : FCELL_TYPE;
83
84 /* Set masking flag unknown */
85 R__.auto_mask = -1;
86 R__.mask_fd = -1;
87
88 R__.nbytes = sizeof(CELL);
89
92
94
95 cname = getenv("GRASS_COMPRESSOR");
96 /* 1: RLE
97 * 2: ZLIB (DEFLATE)
98 * 3: LZ4
99 * 4: BZIP2
100 * 5: ZSTD */
101 if (cname && *cname) {
102 /* ask gislib */
104 if (R__.compression_type < 1) {
105 if (R__.compression_type < 0) {
106 G_warning(
107 _("Unknown compression method <%s>, using default %s"),
109 }
110 if (R__.compression_type == 0) {
111 G_warning(_("No compression is not supported for GRASS raster "
112 "maps, using default %s"),
114 }
115 /* use default */
117 }
119 G_warning(_("This GRASS version does not support %s compression, "
120 "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
140{
141 Rast__init();
144}
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
char * G_compressor_name(int)
Definition compress.c:115
int G_default_compressor(void)
Definition compress.c:123
int G_compressor_number(char *)
Definition compress.c:97
int G_check_compressor(int)
Definition compress.c:137
void G_add_error_handler(void(*)(void *), void *)
Add new error handler.
Definition gis/handler.c:68
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:32
void Rast__unopen_all(void)
Unopen all raster maps.
void Rast_init_gdal(void)
Initialization.
Definition gdal.c:31
#define G_UNUSED
A macro for an attribute, if attached to a variable, indicating that the variable is not used.
Definition gis.h:43
int CELL
Definition gis.h:631
#define _(str)
Definition glocale.h:10
void Rast_init(void)
Initialize GRASS engine.
Definition raster/init.c:40
void Rast_init_all(void)
void Rast__error_handler(void *p)
Definition raster/init.c:67
void Rast__check_init(void)
Checks to see if GIS engine is initialized.
Definition raster/init.c:50
void Rast__init(void)
Definition raster/init.c:59
#define FCELL_TYPE
Definition raster.h:12
#define DCELL_TYPE
Definition raster.h:13
Definition R.h:82
int compress_nulls
Definition R.h:89
struct fileinfo * fileinfo
Definition R.h:96
int auto_mask
Definition R.h:85
int compression_type
Definition R.h:88
int want_histogram
Definition R.h:86
int fileinfo_count
Definition R.h:95
RASTER_MAP_TYPE fp_type
Definition R.h:83
int nbytes
Definition R.h:87
int mask_fd
Definition R.h:84