-
-
Notifications
You must be signed in to change notification settings - Fork 294
/
param.c
143 lines (113 loc) · 4.02 KB
/
param.c
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
#include <string.h>
#include <grass/gis.h>
#include <grass/glocale.h>
#include "raster3d_intern.h"
/*----------------------------------------------------------------------------*/
typedef struct
{
struct Option *type;
struct Option *precision;
struct Option *compression;
struct Option *dimension;
struct Option *cache;
} Rast3d_paramType;
/*----------------------------------------------------------------------------*/
static Rast3d_paramType *param;
/*!
* \brief
*
* Initializes a parameter
* structure for the subset of command line arguments which lets the user
* overwrite the default properties of the new file. Applications are
* encouraged to use this function in order to provide a uniform style. The
* command line arguments provided are the <em>type</em> of the cell values, the
* <em>precision</em>, the properties of the <em>compression</em>, and the dimension
* of the tiles (<em>tiledimension</em>). Every of these values defaults to the
* value described in RASTER3D Defaults.
* This function has to be used in conjunction with
* Rast3d_getStandard3dInputParams() (cf.{g3d:G3d.getStandard3dInputParams}).
*
* \return void
*/
void Rast3d_set_standard3d_input_params()
{
param = Rast3d_malloc(sizeof(Rast3d_paramType));
param->type = G_define_standard_option(G_OPT_R3_TYPE);
param->precision = G_define_standard_option(G_OPT_R3_PRECISION);
param->compression = G_define_standard_option(G_OPT_R3_COMPRESSION);
param->dimension = G_define_standard_option(G_OPT_R3_TILE_DIMENSION);
}
/*----------------------------------------------------------------------------*/
int Rast3d_get_standard3d_params(int *useTypeDefault, int *type,
int *useCompressionDefault, int *doCompression,
int *usePrecisionDefault, int *precision,
int *useDimensionDefault, int *tileX, int *tileY,
int *tileZ)
{
*useTypeDefault = *useCompressionDefault = 0;
*usePrecisionDefault = *useDimensionDefault = 0;
Rast3d_init_defaults();
if (strcmp(param->type->answer, "double") == 0)
*type = DCELL_TYPE;
else if (strcmp(param->type->answer, "float") == 0)
*type = FCELL_TYPE;
else {
*type = Rast3d_get_file_type();
*useTypeDefault = 1;
}
Rast3d_get_compression_mode(doCompression, precision);
if (strcmp(param->precision->answer, "default") != 0) {
if (strcmp(param->precision->answer, "max") == 0)
*precision = -1;
else if ((sscanf(param->precision->answer, "%d", precision) != 1) ||
(*precision < 0)) {
Rast3d_error(_("Rast3d_get_standard3d_params: precision value invalid"));
return 0;
}
}
else
*usePrecisionDefault = 1;
if (strcmp(param->compression->answer, "default") != 0) {
if (strcmp(param->compression->answer, "zip") == 0)
*doCompression = RASTER3D_COMPRESSION;
else
*doCompression = RASTER3D_NO_COMPRESSION;
} else {
*useCompressionDefault = 1;
}
Rast3d_get_tile_dimension(tileX, tileY, tileZ);
if (strcmp(param->dimension->answer, "default") != 0) {
if (sscanf(param->dimension->answer, "%dx%dx%d",
tileX, tileY, tileZ) != 3) {
Rast3d_error(_("Rast3d_get_standard3d_params: tile dimension value invalid"));
return 0;
}
}
else
*useDimensionDefault = 1;
Rast3d_free(param);
return 1;
}
/*----------------------------------------------------------------------------*/
static struct Option *windowParam = NULL;
void Rast3d_set_window_params(void)
{
windowParam = G_define_option();
windowParam->key = "region3";
windowParam->type = TYPE_STRING;
windowParam->required = NO;
windowParam->multiple = NO;
windowParam->answer = NULL;
windowParam->description = _("Window replacing the default");
}
/*----------------------------------------------------------------------------*/
char *Rast3d_get_window_params(void)
{
if (windowParam == NULL)
return NULL;
if (windowParam->answer == NULL)
return NULL;
if (strcmp(windowParam->answer, RASTER3D_WINDOW_ELEMENT) == 0)
return G_store(RASTER3D_WINDOW_ELEMENT);
return G_store(windowParam->answer);
}