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