4
#include "G3d_intern.h"
6
/*---------------------------------------------------------------------------*/
8
#define G3D_NO_DEFAULT -10
10
#define G3D_COMPRESSION_DEFAULT G3D_COMPRESSION
11
#define G3D_USE_LZW_DEFAULT G3D_NO_LZW
12
#define G3D_USE_RLE_DEFAULT G3D_USE_RLE
13
#define G3D_PRECISION_DEFAULT G3D_MAX_PRECISION
14
#define G3D_CACHE_SIZE_DEFAULT 1000
15
#define G3D_CACHE_SIZE_MAX_DEFAULT 2000000
16
#define G3D_FILE_TYPE_DEFAULT DCELL_TYPE
17
#define G3D_TILE_X_DEFAULT 8
18
#define G3D_TILE_Y_DEFAULT 8
19
#define G3D_TILE_Z_DEFAULT 8
20
#define G3D_ERROR_FUN_DEFAULT G3d_skipError
21
#define G3D_UNIT_DEFAULT "none"
23
/*---------------------------------------------------------------------------*/
25
#define G3D_COMPRESSION_ENV_VAR_YES "G3D_USE_COMPRESSION"
26
#define G3D_COMPRESSION_ENV_VAR_NO "G3D_NO_COMPRESSION"
28
#define G3D_LZW_ENV_VAR_YES "G3D_USE_LZW"
29
#define G3D_LZW_ENV_VAR_NO "G3D_NO_LZW"
31
#define G3D_RLE_ENV_VAR_YES "G3D_USE_RLE"
32
#define G3D_RLE_ENV_VAR_NO "G3D_NO_RLE"
34
#define G3D_PRECISION_ENV_VAR "G3D_PRECISION"
35
#define G3D_PRECISION_ENV_VAR_MAX "G3D_MAX_PRECISION"
37
#define G3D_CACHE_SIZE_ENV_VAR "G3D_DEFAULT_CACHE_SIZE"
38
#define G3D_CACHE_SIZE_MAX_ENV_VAR "G3D_MAX_CACHE_SIZE"
40
#define G3D_FILE_FLOAT_ENV_VAR "G3D_WRITE_FLOAT"
41
#define G3D_FILE_DOUBLE_ENV_VAR "G3D_WRITE_DOUBLE"
43
#define G3D_TILE_DIM_X_ENV_VAR "G3D_TILE_DIMENSION_X"
44
#define G3D_TILE_DIM_Y_ENV_VAR "G3D_TILE_DIMENSION_Y"
45
#define G3D_TILE_DIM_Z_ENV_VAR "G3D_TILE_DIMENSION_Z"
47
#define G3D_FATAL_ERROR_ENV_VAR "G3D_USE_FATAL_ERROR"
48
#define G3D_PRINT_ERROR_ENV_VAR "G3D_USE_PRINT_ERROR"
50
#define G3D_DEFAULT_WINDOW3D "G3D_DEFAULT_WINDOW3D"
52
/*---------------------------------------------------------------------------*/
54
int g3d_do_compression = G3D_NO_DEFAULT;
55
int g3d_do_lzw_compression = G3D_NO_DEFAULT;
56
int g3d_do_rle_compression = G3D_NO_DEFAULT;
57
int g3d_precision = G3D_NO_DEFAULT;
58
int g3d_cache_default = G3D_NO_DEFAULT;
59
int g3d_cache_max = G3D_NO_DEFAULT;
60
int g3d_file_type = G3D_NO_DEFAULT;
61
int g3d_tile_dimension[3] =
62
{ G3D_NO_DEFAULT, G3D_NO_DEFAULT, G3D_NO_DEFAULT };
63
void (*g3d_error_fun) (const char *) = NULL;
64
char *g3d_unit_default = NULL;
66
/*---------------------------------------------------------------------------*/
72
* <em>doCompress</em> should be one of G3D_NO_COMPRESSION and
73
* G3D_COMPRESSION, <em>doRle</em> should be either G3D_NO_RLE or
74
* G3D_USE_RLE, and <em>precision</em> should be either G3D_MAX_PRECISION or
85
G3d_setCompressionMode(int doCompress, int doLzw, int doRle, int precision)
87
if ((doCompress != G3D_NO_COMPRESSION) && (doCompress != G3D_COMPRESSION))
88
G3d_fatalError("G3d_setCompressionMode: wrong value for doCompress.");
90
g3d_do_compression = doCompress;
92
if (doCompress == G3D_NO_COMPRESSION)
95
if ((doLzw != G3D_NO_LZW) && (doLzw != G3D_USE_LZW))
96
G3d_fatalError("G3d_setCompressionMode: wrong value for doLzw.");
98
if ((doRle != G3D_NO_RLE) && (doRle != G3D_USE_RLE))
99
G3d_fatalError("G3d_setCompressionMode: wrong value for doRle.");
102
G3d_fatalError("G3d_setCompressionMode: wrong value for precision.");
104
g3d_do_lzw_compression = doLzw;
105
g3d_do_rle_compression = doRle;
106
g3d_precision = precision;
109
/*---------------------------------------------------------------------------*/
125
G3d_getCompressionMode(int *doCompress, int *doLzw, int *doRle,
128
if (doCompress != NULL)
129
*doCompress = g3d_do_compression;
131
*doLzw = g3d_do_lzw_compression;
133
*doRle = g3d_do_rle_compression;
134
if (precision != NULL)
135
*precision = g3d_precision;
138
/*---------------------------------------------------------------------------*/
150
void G3d_setCacheSize(int nTiles)
153
G3d_fatalError("G3d_setCacheSize: size out of range.");
155
g3d_cache_default = nTiles;
158
/*---------------------------------------------------------------------------*/
169
int G3d_getCacheSize()
171
return g3d_cache_default;
174
/*---------------------------------------------------------------------------*/
178
* \brief Set cache limit
186
void G3d_setCacheLimit(int nBytes)
189
G3d_fatalError("G3d_setCacheLimit: size out of range.");
191
g3d_cache_max = nBytes;
194
/*---------------------------------------------------------------------------*/
198
* \brief Get cache limit
206
int G3d_getCacheLimit()
208
return g3d_cache_max;
211
/*---------------------------------------------------------------------------*/
223
void G3d_setFileType(int type)
225
if ((type != FCELL_TYPE) && (type != DCELL_TYPE))
226
G3d_fatalError("G3d_setFileTypeDefault: invalid type");
228
g3d_file_type = type;
231
/*---------------------------------------------------------------------------*/
243
int G3d_getFileType()
245
return g3d_file_type;
248
/*---------------------------------------------------------------------------*/
262
void G3d_setTileDimension(int tileX, int tileY, int tileZ)
264
if ((g3d_tile_dimension[0] = tileX) <= 0)
266
("G3d_setTileDimension: value for tile x environment variable out of range");
268
if ((g3d_tile_dimension[1] = tileY) <= 0)
270
("G3d_setTileDimension: value for tile y environment variable out of range");
272
if ((g3d_tile_dimension[2] = tileZ) <= 0)
274
("G3d_setTileDimension: value for tile z environment variable out of range");
277
/*---------------------------------------------------------------------------*/
291
void G3d_getTileDimension(int *tileX, int *tileY, int *tileZ)
293
*tileX = g3d_tile_dimension[0];
294
*tileY = g3d_tile_dimension[1];
295
*tileZ = g3d_tile_dimension[2];
298
/*---------------------------------------------------------------------------*/
310
void G3d_setErrorFun(void (*fun) (const char *))
315
/*---------------------------------------------------------------------------*/
327
void G3d_setUnit(const char *unit)
329
G3d_free(g3d_unit_default);
330
g3d_unit_default = G_store(unit);
333
/*---------------------------------------------------------------------------*/
339
* Initializes the default values described
340
* in G3D Defaults. Applications have to use this function only if they need to
341
* query the default values before the first file (either old or new) has been
347
void G3d_initDefaults(void)
349
static int firstTime = 1;
350
const char *value, *windowName;
357
if (g3d_do_compression == G3D_NO_DEFAULT) {
358
if (NULL != getenv(G3D_COMPRESSION_ENV_VAR_YES)) {
359
g3d_do_compression = G3D_COMPRESSION;
362
if (NULL != getenv(G3D_COMPRESSION_ENV_VAR_NO)) {
363
g3d_do_compression = G3D_NO_COMPRESSION;
366
g3d_do_compression = G3D_COMPRESSION_DEFAULT;
371
if (g3d_do_lzw_compression == G3D_NO_DEFAULT) {
372
if (NULL != getenv(G3D_LZW_ENV_VAR_YES)) {
373
g3d_do_lzw_compression = G3D_USE_LZW;
376
if (NULL != getenv(G3D_LZW_ENV_VAR_NO)) {
377
g3d_do_lzw_compression = G3D_NO_LZW;
380
g3d_do_lzw_compression = G3D_USE_LZW_DEFAULT;
385
if (g3d_do_rle_compression == G3D_NO_DEFAULT) {
386
if (NULL != getenv(G3D_RLE_ENV_VAR_YES)) {
387
g3d_do_rle_compression = G3D_USE_RLE;
390
if (NULL != getenv(G3D_RLE_ENV_VAR_NO)) {
391
g3d_do_rle_compression = G3D_NO_RLE;
394
g3d_do_rle_compression = G3D_USE_RLE_DEFAULT;
399
if (g3d_precision == G3D_NO_DEFAULT) {
400
if (NULL != getenv(G3D_PRECISION_ENV_VAR_MAX)) {
401
g3d_precision = G3D_MAX_PRECISION;
404
value = getenv(G3D_PRECISION_ENV_VAR);
406
g3d_precision = G3D_PRECISION_DEFAULT;
409
if (sscanf(value, "%d", &g3d_precision) != 1) {
411
("G3d_initDefaults: precision environment variable has invalid value");
414
if (g3d_precision < -1) {
416
("G3d_initDefaults: value for cache environment variable out of range");
423
if (g3d_file_type == G3D_NO_DEFAULT) {
424
if (NULL != getenv(G3D_FILE_FLOAT_ENV_VAR)) {
425
g3d_file_type = FCELL_TYPE;
428
if (NULL != getenv(G3D_FILE_DOUBLE_ENV_VAR)) {
429
g3d_file_type = DCELL_TYPE;
432
g3d_file_type = G3D_FILE_TYPE_DEFAULT;
437
if (g3d_cache_default == G3D_NO_DEFAULT) {
438
value = getenv(G3D_CACHE_SIZE_ENV_VAR);
441
g3d_cache_default = G3D_CACHE_SIZE_DEFAULT;
444
if (sscanf(value, "%d", &g3d_cache_default) != 1) {
446
("G3d_initDefaults: cache environment variable has invalid value");
448
if (g3d_cache_default < 0) {
450
("G3d_initDefaults: value for cache environment variable out of range");
455
if (g3d_cache_max == G3D_NO_DEFAULT) {
456
value = getenv(G3D_CACHE_SIZE_MAX_ENV_VAR);
459
g3d_cache_max = G3D_CACHE_SIZE_MAX_DEFAULT;
462
if (sscanf(value, "%d", &g3d_cache_max) != 1) {
464
("G3d_initDefaults: cache environment variable has invalid value");
466
if (g3d_cache_max < 0) {
468
("G3d_initDefaults: value for cache environment variable out of range");
473
if (g3d_tile_dimension[0] == G3D_NO_DEFAULT) {
474
value = getenv(G3D_TILE_DIM_X_ENV_VAR);
477
g3d_tile_dimension[0] = G3D_TILE_X_DEFAULT;
480
if (sscanf(value, "%d", g3d_tile_dimension) != 1) {
482
("G3d_initDefaults: tile dimension x environment variable has invalid value");
484
if (g3d_tile_dimension[0] <= 0) {
486
("G3d_initDefaults: value for tile x environment variable out of range");
490
value = getenv(G3D_TILE_DIM_Y_ENV_VAR);
493
g3d_tile_dimension[1] = G3D_TILE_Y_DEFAULT;
496
if (sscanf(value, "%d", g3d_tile_dimension + 1) != 1) {
498
("G3d_initDefaults: tile dimension y environment variable has invalid value");
500
if (g3d_tile_dimension[1] <= 0) {
502
("G3d_initDefaults: value for tile y environment variable out of range");
506
value = getenv(G3D_TILE_DIM_Z_ENV_VAR);
509
g3d_tile_dimension[2] = G3D_TILE_Z_DEFAULT;
512
if (sscanf(value, "%d", g3d_tile_dimension + 2) != 1) {
514
("G3d_initDefaults: tile dimension z environment variable has invalid value");
516
if (g3d_tile_dimension[2] <= 0) {
518
("G3d_initDefaults: value for tile z environment variable out of range");
523
if (g3d_error_fun == NULL) {
524
value = getenv(G3D_FATAL_ERROR_ENV_VAR);
527
g3d_error_fun = G3d_fatalError_noargs;
530
value = getenv(G3D_PRINT_ERROR_ENV_VAR);
533
g3d_error_fun = G3d_printError;
536
g3d_error_fun = G3D_ERROR_FUN_DEFAULT;
541
if (g3d_unit_default == NULL)
542
g3d_unit_default = G_store(G3D_UNIT_DEFAULT);
544
windowName = G3d_getWindowParams();
545
if (windowName == NULL) {
546
value = getenv(G3D_DEFAULT_WINDOW3D);
552
if (!G3d_readWindow(&window, windowName))
553
G3d_fatalError("G3d_initDefaults: Error reading window");
554
G3d_setWindow(&window);