~ubuntu-branches/ubuntu/vivid/grass/vivid-proposed

« back to all changes in this revision

Viewing changes to lib/g3d/g3ddefaults.c

  • Committer: Package Import Robot
  • Author(s): Bas Couwenberg
  • Date: 2015-02-20 23:12:08 UTC
  • mfrom: (8.2.6 experimental)
  • Revision ID: package-import@ubuntu.com-20150220231208-1u6qvqm84v430b10
Tags: 7.0.0-1~exp1
* New upstream release.
* Update python-ctypes-ternary.patch to use if/else instead of and/or.
* Drop check4dev patch, rely on upstream check.
* Add build dependency on libpq-dev to grass-dev for libpq-fe.h.
* Drop patches applied upstream, refresh remaining patches.
* Update symlinks for images switched from jpg to png.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#include <stdlib.h>
2
 
#include <stdio.h>
3
 
#include <grass/G3d.h>
4
 
#include "G3d_intern.h"
5
 
 
6
 
/*---------------------------------------------------------------------------*/
7
 
 
8
 
#define G3D_NO_DEFAULT -10
9
 
 
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"
22
 
 
23
 
/*---------------------------------------------------------------------------*/
24
 
 
25
 
#define G3D_COMPRESSION_ENV_VAR_YES "G3D_USE_COMPRESSION"
26
 
#define G3D_COMPRESSION_ENV_VAR_NO "G3D_NO_COMPRESSION"
27
 
 
28
 
#define G3D_LZW_ENV_VAR_YES "G3D_USE_LZW"
29
 
#define G3D_LZW_ENV_VAR_NO "G3D_NO_LZW"
30
 
 
31
 
#define G3D_RLE_ENV_VAR_YES "G3D_USE_RLE"
32
 
#define G3D_RLE_ENV_VAR_NO "G3D_NO_RLE"
33
 
 
34
 
#define G3D_PRECISION_ENV_VAR "G3D_PRECISION"
35
 
#define G3D_PRECISION_ENV_VAR_MAX "G3D_MAX_PRECISION"
36
 
 
37
 
#define G3D_CACHE_SIZE_ENV_VAR "G3D_DEFAULT_CACHE_SIZE"
38
 
#define G3D_CACHE_SIZE_MAX_ENV_VAR "G3D_MAX_CACHE_SIZE"
39
 
 
40
 
#define G3D_FILE_FLOAT_ENV_VAR "G3D_WRITE_FLOAT"
41
 
#define G3D_FILE_DOUBLE_ENV_VAR "G3D_WRITE_DOUBLE"
42
 
 
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"
46
 
 
47
 
#define G3D_FATAL_ERROR_ENV_VAR "G3D_USE_FATAL_ERROR"
48
 
#define G3D_PRINT_ERROR_ENV_VAR "G3D_USE_PRINT_ERROR"
49
 
 
50
 
#define G3D_DEFAULT_WINDOW3D "G3D_DEFAULT_WINDOW3D"
51
 
 
52
 
/*---------------------------------------------------------------------------*/
53
 
 
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;
65
 
 
66
 
/*---------------------------------------------------------------------------*/
67
 
 
68
 
 
69
 
/*!
70
 
 * \brief 
71
 
 *
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
75
 
 * a positive integer.
76
 
 *
77
 
 *  \param doCompress
78
 
 *  \param doLzw
79
 
 *  \param doRle
80
 
 *  \param precision
81
 
 *  \return void
82
 
 */
83
 
 
84
 
void
85
 
G3d_setCompressionMode(int doCompress, int doLzw, int doRle, int precision)
86
 
{
87
 
    if ((doCompress != G3D_NO_COMPRESSION) && (doCompress != G3D_COMPRESSION))
88
 
        G3d_fatalError("G3d_setCompressionMode: wrong value for doCompress.");
89
 
 
90
 
    g3d_do_compression = doCompress;
91
 
 
92
 
    if (doCompress == G3D_NO_COMPRESSION)
93
 
        return;
94
 
 
95
 
    if ((doLzw != G3D_NO_LZW) && (doLzw != G3D_USE_LZW))
96
 
        G3d_fatalError("G3d_setCompressionMode: wrong value for doLzw.");
97
 
 
98
 
    if ((doRle != G3D_NO_RLE) && (doRle != G3D_USE_RLE))
99
 
        G3d_fatalError("G3d_setCompressionMode: wrong value for doRle.");
100
 
 
101
 
    if (precision < -1)
102
 
        G3d_fatalError("G3d_setCompressionMode: wrong value for precision.");
103
 
 
104
 
    g3d_do_lzw_compression = doLzw;
105
 
    g3d_do_rle_compression = doRle;
106
 
    g3d_precision = precision;
107
 
}
108
 
 
109
 
/*---------------------------------------------------------------------------*/
110
 
 
111
 
 
112
 
/*!
113
 
 * \brief 
114
 
 *
115
 
 * 
116
 
 *
117
 
 *  \param doCompress
118
 
 *  \param doLzw
119
 
 *  \param doRle
120
 
 *  \param precision
121
 
 *  \return void
122
 
 */
123
 
 
124
 
void
125
 
G3d_getCompressionMode(int *doCompress, int *doLzw, int *doRle,
126
 
                       int *precision)
127
 
{
128
 
    if (doCompress != NULL)
129
 
        *doCompress = g3d_do_compression;
130
 
    if (doLzw != NULL)
131
 
        *doLzw = g3d_do_lzw_compression;
132
 
    if (doRle != NULL)
133
 
        *doRle = g3d_do_rle_compression;
134
 
    if (precision != NULL)
135
 
        *precision = g3d_precision;
136
 
}
137
 
 
138
 
/*---------------------------------------------------------------------------*/
139
 
 
140
 
 
141
 
/*!
142
 
 * \brief 
143
 
 *
144
 
 *  set cache size
145
 
 *
146
 
 *  \param nTiles
147
 
 *  \return void
148
 
 */
149
 
 
150
 
void G3d_setCacheSize(int nTiles)
151
 
{
152
 
    if (nTiles < 0)
153
 
        G3d_fatalError("G3d_setCacheSize: size out of range.");
154
 
 
155
 
    g3d_cache_default = nTiles;
156
 
}
157
 
 
158
 
/*---------------------------------------------------------------------------*/
159
 
 
160
 
 
161
 
/*!
162
 
 * \brief 
163
 
 *
164
 
 *  get cache size
165
 
 *
166
 
 *  \return int
167
 
 */
168
 
 
169
 
int G3d_getCacheSize()
170
 
{
171
 
    return g3d_cache_default;
172
 
}
173
 
 
174
 
/*---------------------------------------------------------------------------*/
175
 
 
176
 
 
177
 
/*!
178
 
 * \brief Set cache limit
179
 
 *
180
 
 *  set cache limit
181
 
 *
182
 
 *  \param nBytes
183
 
 *  \return void
184
 
 */
185
 
 
186
 
void G3d_setCacheLimit(int nBytes)
187
 
{
188
 
    if (nBytes <= 0)
189
 
        G3d_fatalError("G3d_setCacheLimit: size out of range.");
190
 
 
191
 
    g3d_cache_max = nBytes;
192
 
}
193
 
 
194
 
/*---------------------------------------------------------------------------*/
195
 
 
196
 
 
197
 
/*!
198
 
 * \brief Get cache limit
199
 
 *
200
 
 *  get cache limit
201
 
 *
202
 
 *  \param nBytes
203
 
 *  \return int
204
 
 */
205
 
 
206
 
int G3d_getCacheLimit()
207
 
{
208
 
    return g3d_cache_max;
209
 
}
210
 
 
211
 
/*---------------------------------------------------------------------------*/
212
 
 
213
 
 
214
 
/*!
215
 
 * \brief 
216
 
 *
217
 
 *  set G3d file type
218
 
 *
219
 
 *  \param type
220
 
 *  \return void
221
 
 */
222
 
 
223
 
void G3d_setFileType(int type)
224
 
{
225
 
    if ((type != FCELL_TYPE) && (type != DCELL_TYPE))
226
 
        G3d_fatalError("G3d_setFileTypeDefault: invalid type");
227
 
 
228
 
    g3d_file_type = type;
229
 
}
230
 
 
231
 
/*---------------------------------------------------------------------------*/
232
 
 
233
 
 
234
 
/*!
235
 
 * \brief 
236
 
 *
237
 
 * get G3d file type
238
 
 *
239
 
 *  \param type
240
 
 *  \return int
241
 
 */
242
 
 
243
 
int G3d_getFileType()
244
 
{
245
 
    return g3d_file_type;
246
 
}
247
 
 
248
 
/*---------------------------------------------------------------------------*/
249
 
 
250
 
 
251
 
/*!
252
 
 * \brief 
253
 
 *
254
 
 * set Tile Dimension
255
 
 *
256
 
 *  \param tileX
257
 
 *  \param tileY
258
 
 *  \param tileZ
259
 
 *  \return void
260
 
 */
261
 
 
262
 
void G3d_setTileDimension(int tileX, int tileY, int tileZ)
263
 
{
264
 
    if ((g3d_tile_dimension[0] = tileX) <= 0)
265
 
        G3d_fatalError
266
 
            ("G3d_setTileDimension: value for tile x environment variable out of range");
267
 
 
268
 
    if ((g3d_tile_dimension[1] = tileY) <= 0)
269
 
        G3d_fatalError
270
 
            ("G3d_setTileDimension: value for tile y environment variable out of range");
271
 
 
272
 
    if ((g3d_tile_dimension[2] = tileZ) <= 0)
273
 
        G3d_fatalError
274
 
            ("G3d_setTileDimension: value for tile z environment variable out of range");
275
 
}
276
 
 
277
 
/*---------------------------------------------------------------------------*/
278
 
 
279
 
 
280
 
/*!
281
 
 * \brief 
282
 
 *
283
 
 *  get Tile Dimension
284
 
 *
285
 
 *  \param tileX
286
 
 *  \param tileY
287
 
 *  \param tileZ
288
 
 *  \return void
289
 
 */
290
 
 
291
 
void G3d_getTileDimension(int *tileX, int *tileY, int *tileZ)
292
 
{
293
 
    *tileX = g3d_tile_dimension[0];
294
 
    *tileY = g3d_tile_dimension[1];
295
 
    *tileZ = g3d_tile_dimension[2];
296
 
}
297
 
 
298
 
/*---------------------------------------------------------------------------*/
299
 
 
300
 
 
301
 
/*!
302
 
 * \brief 
303
 
 *
304
 
 *  set error function
305
 
 *
306
 
 *  \param 
307
 
 *  \return void
308
 
 */
309
 
 
310
 
void G3d_setErrorFun(void (*fun) (const char *))
311
 
{
312
 
    g3d_error_fun = fun;
313
 
}
314
 
 
315
 
/*---------------------------------------------------------------------------*/
316
 
 
317
 
 
318
 
/*!
319
 
 * \brief 
320
 
 *
321
 
 *  set G3d unit
322
 
 *
323
 
 *  \param unit
324
 
 *  \return void
325
 
 */
326
 
 
327
 
void G3d_setUnit(const char *unit)
328
 
{
329
 
    G3d_free(g3d_unit_default);
330
 
    g3d_unit_default = G_store(unit);
331
 
}
332
 
 
333
 
/*---------------------------------------------------------------------------*/
334
 
 
335
 
 
336
 
/*!
337
 
 * \brief 
338
 
 *
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
342
 
 * opened.
343
 
 *
344
 
 *  \return void
345
 
 */
346
 
 
347
 
void G3d_initDefaults(void)
348
 
{
349
 
    static int firstTime = 1;
350
 
    const char *value, *windowName;
351
 
    G3D_Region window;
352
 
 
353
 
    if (!firstTime)
354
 
        return;
355
 
    firstTime = 0;
356
 
 
357
 
    if (g3d_do_compression == G3D_NO_DEFAULT) {
358
 
        if (NULL != getenv(G3D_COMPRESSION_ENV_VAR_YES)) {
359
 
            g3d_do_compression = G3D_COMPRESSION;
360
 
        }
361
 
        else {
362
 
            if (NULL != getenv(G3D_COMPRESSION_ENV_VAR_NO)) {
363
 
                g3d_do_compression = G3D_NO_COMPRESSION;
364
 
            }
365
 
            else {
366
 
                g3d_do_compression = G3D_COMPRESSION_DEFAULT;
367
 
            }
368
 
        }
369
 
    }
370
 
 
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;
374
 
        }
375
 
        else {
376
 
            if (NULL != getenv(G3D_LZW_ENV_VAR_NO)) {
377
 
                g3d_do_lzw_compression = G3D_NO_LZW;
378
 
            }
379
 
            else {
380
 
                g3d_do_lzw_compression = G3D_USE_LZW_DEFAULT;
381
 
            }
382
 
        }
383
 
    }
384
 
 
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;
388
 
        }
389
 
        else {
390
 
            if (NULL != getenv(G3D_RLE_ENV_VAR_NO)) {
391
 
                g3d_do_rle_compression = G3D_NO_RLE;
392
 
            }
393
 
            else {
394
 
                g3d_do_rle_compression = G3D_USE_RLE_DEFAULT;
395
 
            }
396
 
        }
397
 
    }
398
 
 
399
 
    if (g3d_precision == G3D_NO_DEFAULT) {
400
 
        if (NULL != getenv(G3D_PRECISION_ENV_VAR_MAX)) {
401
 
            g3d_precision = G3D_MAX_PRECISION;
402
 
        }
403
 
        else {
404
 
            value = getenv(G3D_PRECISION_ENV_VAR);
405
 
            if (value == NULL) {
406
 
                g3d_precision = G3D_PRECISION_DEFAULT;
407
 
            }
408
 
            else {
409
 
                if (sscanf(value, "%d", &g3d_precision) != 1) {
410
 
                    G3d_fatalError
411
 
                        ("G3d_initDefaults: precision environment variable has invalid value");
412
 
                }
413
 
                else {
414
 
                    if (g3d_precision < -1) {
415
 
                        G3d_fatalError
416
 
                            ("G3d_initDefaults: value for cache environment variable out of range");
417
 
                    }
418
 
                }
419
 
            }
420
 
        }
421
 
    }
422
 
 
423
 
    if (g3d_file_type == G3D_NO_DEFAULT) {
424
 
        if (NULL != getenv(G3D_FILE_FLOAT_ENV_VAR)) {
425
 
            g3d_file_type = FCELL_TYPE;
426
 
        }
427
 
        else {
428
 
            if (NULL != getenv(G3D_FILE_DOUBLE_ENV_VAR)) {
429
 
                g3d_file_type = DCELL_TYPE;
430
 
            }
431
 
            else {
432
 
                g3d_file_type = G3D_FILE_TYPE_DEFAULT;
433
 
            }
434
 
        }
435
 
    }
436
 
 
437
 
    if (g3d_cache_default == G3D_NO_DEFAULT) {
438
 
        value = getenv(G3D_CACHE_SIZE_ENV_VAR);
439
 
 
440
 
        if (value == NULL) {
441
 
            g3d_cache_default = G3D_CACHE_SIZE_DEFAULT;
442
 
        }
443
 
        else {
444
 
            if (sscanf(value, "%d", &g3d_cache_default) != 1) {
445
 
                G3d_fatalError
446
 
                    ("G3d_initDefaults: cache environment variable has invalid value");
447
 
            }
448
 
            if (g3d_cache_default < 0) {
449
 
                G3d_fatalError
450
 
                    ("G3d_initDefaults: value for cache environment variable out of range");
451
 
            }
452
 
        }
453
 
    }
454
 
 
455
 
    if (g3d_cache_max == G3D_NO_DEFAULT) {
456
 
        value = getenv(G3D_CACHE_SIZE_MAX_ENV_VAR);
457
 
 
458
 
        if (value == NULL) {
459
 
            g3d_cache_max = G3D_CACHE_SIZE_MAX_DEFAULT;
460
 
        }
461
 
        else {
462
 
            if (sscanf(value, "%d", &g3d_cache_max) != 1) {
463
 
                G3d_fatalError
464
 
                    ("G3d_initDefaults: cache environment variable has invalid value");
465
 
            }
466
 
            if (g3d_cache_max < 0) {
467
 
                G3d_fatalError
468
 
                    ("G3d_initDefaults: value for cache environment variable out of range");
469
 
            }
470
 
        }
471
 
    }
472
 
 
473
 
    if (g3d_tile_dimension[0] == G3D_NO_DEFAULT) {
474
 
        value = getenv(G3D_TILE_DIM_X_ENV_VAR);
475
 
 
476
 
        if (value == NULL) {
477
 
            g3d_tile_dimension[0] = G3D_TILE_X_DEFAULT;
478
 
        }
479
 
        else {
480
 
            if (sscanf(value, "%d", g3d_tile_dimension) != 1) {
481
 
                G3d_fatalError
482
 
                    ("G3d_initDefaults: tile dimension x environment variable has invalid value");
483
 
            }
484
 
            if (g3d_tile_dimension[0] <= 0) {
485
 
                G3d_fatalError
486
 
                    ("G3d_initDefaults: value for tile x environment variable out of range");
487
 
            }
488
 
        }
489
 
 
490
 
        value = getenv(G3D_TILE_DIM_Y_ENV_VAR);
491
 
 
492
 
        if (value == NULL) {
493
 
            g3d_tile_dimension[1] = G3D_TILE_Y_DEFAULT;
494
 
        }
495
 
        else {
496
 
            if (sscanf(value, "%d", g3d_tile_dimension + 1) != 1) {
497
 
                G3d_fatalError
498
 
                    ("G3d_initDefaults: tile dimension y environment variable has invalid value");
499
 
            }
500
 
            if (g3d_tile_dimension[1] <= 0) {
501
 
                G3d_fatalError
502
 
                    ("G3d_initDefaults: value for tile y environment variable out of range");
503
 
            }
504
 
        }
505
 
 
506
 
        value = getenv(G3D_TILE_DIM_Z_ENV_VAR);
507
 
 
508
 
        if (value == NULL) {
509
 
            g3d_tile_dimension[2] = G3D_TILE_Z_DEFAULT;
510
 
        }
511
 
        else {
512
 
            if (sscanf(value, "%d", g3d_tile_dimension + 2) != 1) {
513
 
                G3d_fatalError
514
 
                    ("G3d_initDefaults: tile dimension z environment variable has invalid value");
515
 
            }
516
 
            if (g3d_tile_dimension[2] <= 0) {
517
 
                G3d_fatalError
518
 
                    ("G3d_initDefaults: value for tile z environment variable out of range");
519
 
            }
520
 
        }
521
 
    }
522
 
 
523
 
    if (g3d_error_fun == NULL) {
524
 
        value = getenv(G3D_FATAL_ERROR_ENV_VAR);
525
 
 
526
 
        if (value != NULL) {
527
 
            g3d_error_fun = G3d_fatalError_noargs;
528
 
        }
529
 
        else {
530
 
            value = getenv(G3D_PRINT_ERROR_ENV_VAR);
531
 
 
532
 
            if (value != NULL) {
533
 
                g3d_error_fun = G3d_printError;
534
 
            }
535
 
            else {
536
 
                g3d_error_fun = G3D_ERROR_FUN_DEFAULT;
537
 
            }
538
 
        }
539
 
    }
540
 
 
541
 
    if (g3d_unit_default == NULL)
542
 
        g3d_unit_default = G_store(G3D_UNIT_DEFAULT);
543
 
 
544
 
    windowName = G3d_getWindowParams();
545
 
    if (windowName == NULL) {
546
 
        value = getenv(G3D_DEFAULT_WINDOW3D);
547
 
        if (value != NULL)
548
 
            if (*value != 0)
549
 
                windowName = value;
550
 
    }
551
 
 
552
 
    if (!G3d_readWindow(&window, windowName))
553
 
        G3d_fatalError("G3d_initDefaults: Error reading window");
554
 
    G3d_setWindow(&window);
555
 
 
556
 
}