GRASS Programmer's Manual  6.5.svn(2014)-r66266
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
g3dparam.c
Go to the documentation of this file.
1 #include <string.h>
2 #include <grass/gis.h>
3 #include <grass/glocale.h>
4 #include "G3d_intern.h"
5 
6 /*----------------------------------------------------------------------------*/
7 
8 typedef struct
9 {
10 
11  struct Option *type;
12  struct Option *precision;
13  struct Option *compression;
14  struct Option *dimension;
15  struct Option *cache;
16 
18 
19 /*----------------------------------------------------------------------------*/
20 
21 static G3d_paramType *param;
22 
23 
42 {
43  param = G3d_malloc(sizeof(G3d_paramType));
44 
45  param->type = G_define_option();
46  param->type->key = "type";
47  param->type->type = TYPE_STRING;
48  param->type->required = NO;
49  param->type->multiple = NO;
50  param->type->answer = "default";
51  param->type->options = "default,double,float";
52  param->type->description = _("Data type used in the output file");
53 
54  param->precision = G_define_option();
55  param->precision->key = "precision";
56  param->precision->type = TYPE_STRING;
57  param->precision->required = NO;
58  param->precision->multiple = NO;
59  param->precision->answer = "default";
60  param->precision->description =
61  _("Precision used in the output file (default, max, or 0 to 52)");
62 
63  param->compression = G_define_option();
64  param->compression->key = "compression";
65  param->compression->type = TYPE_STRING;
66  param->compression->required = NO;
67  param->compression->multiple = NO;
68  param->compression->answer = "default";
69  param->compression->options = "default,rle,none";
70  param->compression->description =
71  _("The compression method used in the output file");
72 
73  param->dimension = G_define_option();
74  param->dimension->key = "tiledimension";
75  param->dimension->type = TYPE_STRING;
76  param->dimension->required = NO;
77  param->dimension->multiple = NO;
78  param->dimension->key_desc = "XxYxZ";
79  param->dimension->answer = "default";
80  param->dimension->description =
81  _("The dimensions of the tiles used in the output file");
82 }
83 
84 /*----------------------------------------------------------------------------*/
85 
86 int G3d_getStandard3dParams(int *useTypeDefault, int *type,
87  int *useLzwDefault, int *doLzw,
88  int *useRleDefault, int *doRle,
89  int *usePrecisionDefault, int *precision,
90  int *useDimensionDefault, int *tileX, int *tileY,
91  int *tileZ)
92 {
93  int doCompress;
94 
95  *useTypeDefault = *useLzwDefault = *useRleDefault = 0;
96  *usePrecisionDefault = *useDimensionDefault = 0;
97 
99 
100  if (strcmp(param->type->answer, "double") == 0)
101  *type = DCELL_TYPE;
102  else if (strcmp(param->type->answer, "float") == 0)
103  *type = FCELL_TYPE;
104  else {
105  *type = G3d_getFileType();
106  *useTypeDefault = 1;
107  }
108 
109  G3d_getCompressionMode(&doCompress, doLzw, doRle, precision);
110 
111  if (strcmp(param->precision->answer, "default") != 0) {
112  if (strcmp(param->precision->answer, "max") == 0)
113  *precision = -1;
114  else if ((sscanf(param->precision->answer, "%d", precision) != 1) ||
115  (*precision < 0)) {
116  G3d_error(_("G3d_getStandard3dParams: precision value invalid"));
117  return 0;
118  }
119  }
120  else
121  *usePrecisionDefault = 1;
122 
123 
124  if (strcmp(param->compression->answer, "default") != 0) {
125  if (strcmp(param->compression->answer, "rle") == 0) {
126  *doRle = G3D_USE_RLE;
127  *doLzw = G3D_NO_LZW;
128  }
129  else if (strcmp(param->compression->answer, "lzw") == 0) {
130  *doRle = G3D_NO_RLE;
131  *doLzw = G3D_USE_LZW;
132  }
133  else if (strcmp(param->compression->answer, "rle+lzw") == 0) {
134  *doRle = G3D_USE_RLE;
135  *doLzw = G3D_USE_LZW;
136  }
137  else {
138  *doRle = G3D_NO_RLE;
139  *doLzw = G3D_NO_LZW;
140  }
141  }
142  else
143  *useLzwDefault = *useRleDefault = 1;
144 
145  G3d_getTileDimension(tileX, tileY, tileZ);
146  if (strcmp(param->dimension->answer, "default") != 0) {
147  if (sscanf(param->dimension->answer, "%dx%dx%d",
148  tileX, tileY, tileZ) != 3) {
149  G3d_error(_("G3d_getStandard3dParams: tile dimension value invalid"));
150  return 0;
151  }
152  }
153  else
154  *useDimensionDefault = 1;
155 
156  G3d_free(param);
157 
158  return 1;
159 }
160 
161 /*----------------------------------------------------------------------------*/
162 
163 static struct Option *windowParam = NULL;
164 
166 {
167  windowParam = G_define_option();
168  windowParam->key = "region3";
169  windowParam->type = TYPE_STRING;
170  windowParam->required = NO;
171  windowParam->multiple = NO;
172  windowParam->answer = NULL;
173  windowParam->description = _("Window replacing the default");
174 }
175 
176 /*----------------------------------------------------------------------------*/
177 
179 {
180  if (windowParam == NULL)
181  return NULL;
182  if (windowParam->answer == NULL)
183  return NULL;
184  if (strcmp(windowParam->answer, G3D_WINDOW_ELEMENT) == 0)
185  return G_store(G3D_WINDOW_ELEMENT);
186  return G_store(windowParam->answer);
187 }
char * G_store(const char *s)
Copy string to allocated memory.
Definition: store.c:32
void G3d_free(void *buf)
Same as free (ptr).
Definition: g3dalloc.c:71
void G3d_error(const char *msg,...)
Definition: g3derror.c:75
struct Option * precision
Definition: g3dparam.c:12
void G3d_getCompressionMode(int *doCompress, int *doLzw, int *doRle, int *precision)
Definition: g3ddefaults.c:125
struct Option * G_define_option(void)
Initializes an Option struct.
Definition: parser.c:247
struct Option * cache
Definition: g3dparam.c:15
void G3d_getTileDimension(int *tileX, int *tileY, int *tileZ)
get Tile Dimension
Definition: g3ddefaults.c:291
char * G3d_getWindowParams(void)
Definition: g3dparam.c:178
struct Option * compression
Definition: g3dparam.c:13
struct Option * type
Definition: g3dparam.c:11
void G3d_setStandard3dInputParams()
Initializes a parameter structure for the subset of command line arguments which lets the user overwr...
Definition: g3dparam.c:41
struct Option * dimension
Definition: g3dparam.c:14
return NULL
Definition: dbfopen.c:1394
void * G3d_malloc(int nBytes)
Same as malloc (nBytes), except that in case of error G3d_error() is invoked.
Definition: g3dalloc.c:24
void G3d_initDefaults(void)
Initializes the default values described in G3D Defaults. Applications have to use this function only...
Definition: g3ddefaults.c:347
int G3d_getStandard3dParams(int *useTypeDefault, int *type, int *useLzwDefault, int *doLzw, int *useRleDefault, int *doRle, int *usePrecisionDefault, int *precision, int *useDimensionDefault, int *tileX, int *tileY, int *tileZ)
Definition: g3dparam.c:86
void G3d_setWindowParams(void)
Definition: g3dparam.c:165
int G3d_getFileType()
get G3d file type
Definition: g3ddefaults.c:243