GRASS GIS 8 Programmer's Manual  8.4.0dev(2024)-f8115df121
param.c
Go to the documentation of this file.
1 #include <string.h>
2 #include <grass/gis.h>
3 #include <grass/glocale.h>
4 #include "raster3d_intern.h"
5 
6 /*----------------------------------------------------------------------------*/
7 
8 typedef struct {
9 
10  struct Option *type;
11  struct Option *precision;
12  struct Option *compression;
13  struct Option *dimension;
14  struct Option *cache;
15 
16 } Rast3d_paramType;
17 
18 /*----------------------------------------------------------------------------*/
19 
20 static Rast3d_paramType *param;
21 
22 /*!
23  * \brief
24  *
25  * Initializes a parameter
26  * structure for the subset of command line arguments which lets the user
27  * overwrite the default properties of the new file. Applications are
28  * encouraged to use this function in order to provide a uniform style. The
29  * command line arguments provided are the <em>type</em> of the cell values, the
30  * <em>precision</em>, the properties of the <em>compression</em>, and the
31  * dimension of the tiles (<em>tiledimension</em>). Every of these values
32  * defaults to the value described in RASTER3D Defaults. This function has to be
33  * used in conjunction with Rast3d_getStandard3dInputParams()
34  * (cf.{g3d:G3d.getStandard3dInputParams}).
35  *
36  * \return void
37  */
38 
40 {
41  param = Rast3d_malloc(sizeof(Rast3d_paramType));
42 
44 
45  param->precision = G_define_standard_option(G_OPT_R3_PRECISION);
46 
47  param->compression = G_define_standard_option(G_OPT_R3_COMPRESSION);
48 
50 }
51 
52 /*----------------------------------------------------------------------------*/
53 
54 int Rast3d_get_standard3d_params(int *useTypeDefault, int *type,
55  int *useCompressionDefault, int *doCompression,
56  int *usePrecisionDefault, int *precision,
57  int *useDimensionDefault, int *tileX,
58  int *tileY, int *tileZ)
59 {
60 
61  *useTypeDefault = *useCompressionDefault = 0;
62  *usePrecisionDefault = *useDimensionDefault = 0;
63 
65 
66  if (strcmp(param->type->answer, "double") == 0)
67  *type = DCELL_TYPE;
68  else if (strcmp(param->type->answer, "float") == 0)
69  *type = FCELL_TYPE;
70  else {
72  *useTypeDefault = 1;
73  }
74 
75  Rast3d_get_compression_mode(doCompression, precision);
76 
77  if (strcmp(param->precision->answer, "default") != 0) {
78  if (strcmp(param->precision->answer, "max") == 0)
79  *precision = -1;
80  else if ((sscanf(param->precision->answer, "%d", precision) != 1) ||
81  (*precision < 0)) {
83  _("Rast3d_get_standard3d_params: precision value invalid"));
84  return 0;
85  }
86  }
87  else
88  *usePrecisionDefault = 1;
89 
90  if (strcmp(param->compression->answer, "default") != 0) {
91  if (strcmp(param->compression->answer, "zip") == 0)
92  *doCompression = RASTER3D_COMPRESSION;
93  else
94  *doCompression = RASTER3D_NO_COMPRESSION;
95  }
96  else {
97  *useCompressionDefault = 1;
98  }
99 
100  Rast3d_get_tile_dimension(tileX, tileY, tileZ);
101  if (strcmp(param->dimension->answer, "default") != 0) {
102  if (sscanf(param->dimension->answer, "%dx%dx%d", tileX, tileY, tileZ) !=
103  3) {
104  Rast3d_error(_(
105  "Rast3d_get_standard3d_params: tile dimension value invalid"));
106  return 0;
107  }
108  }
109  else
110  *useDimensionDefault = 1;
111 
112  Rast3d_free(param);
113 
114  return 1;
115 }
116 
117 /*----------------------------------------------------------------------------*/
118 
119 static struct Option *windowParam = NULL;
120 
122 {
123  windowParam = G_define_option();
124  windowParam->key = "region3";
125  windowParam->type = TYPE_STRING;
126  windowParam->required = NO;
127  windowParam->multiple = NO;
128  windowParam->answer = NULL;
129  windowParam->description = _("Window replacing the default");
130 }
131 
132 /*----------------------------------------------------------------------------*/
133 
135 {
136  if (windowParam == NULL)
137  return NULL;
138  if (windowParam->answer == NULL)
139  return NULL;
140  if (strcmp(windowParam->answer, RASTER3D_WINDOW_ELEMENT) == 0)
142  return G_store(windowParam->answer);
143 }
#define NULL
Definition: ccmath.h:32
struct Option * G_define_standard_option(int)
Create standardised Option structure.
struct Option * G_define_option(void)
Initializes an Option struct.
Definition: parser.c:211
char * G_store(const char *)
Copy string to allocated memory.
Definition: strings.c:87
void Rast3d_free(void *)
Same as free (ptr).
void Rast3d_get_tile_dimension(int *, int *, int *)
get Tile Dimension
Definition: defaults.c:262
int Rast3d_get_file_type(void)
get G3d file type
Definition: defaults.c:220
void Rast3d_get_compression_mode(int *, int *)
Gets compression mode.
Definition: defaults.c:127
void Rast3d_init_defaults(void)
Initializes the default values described in RASTER3D Defaults. Applications have to use this function...
Definition: defaults.c:294
void Rast3d_error(const char *,...) __attribute__((format(printf
void * Rast3d_malloc(int)
Same as malloc (nBytes), except that in case of error Rast3d_error() is invoked.
#define TYPE_STRING
Definition: gis.h:186
@ G_OPT_R3_TYPE
Definition: gis.h:293
@ G_OPT_R3_PRECISION
Definition: gis.h:294
@ G_OPT_R3_TILE_DIMENSION
Definition: gis.h:295
@ G_OPT_R3_COMPRESSION
Definition: gis.h:297
#define NO
Definition: gis.h:188
#define _(str)
Definition: glocale.h:10
unsigned short compression
Definition: gsd_img_tif.c:42
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)
Definition: param.c:54
void Rast3d_set_standard3d_input_params(void)
Initializes a parameter structure for the subset of command line arguments which lets the user overwr...
Definition: param.c:39
char * Rast3d_get_window_params(void)
Definition: param.c:134
void Rast3d_set_window_params(void)
Definition: param.c:121
#define RASTER3D_COMPRESSION
Definition: raster3d.h:14
#define RASTER3D_NO_COMPRESSION
Definition: raster3d.h:13
#define RASTER3D_WINDOW_ELEMENT
Definition: raster3d.h:40
#define FCELL_TYPE
Definition: raster.h:12
#define DCELL_TYPE
Definition: raster.h:13
Structure that stores option information.
Definition: gis.h:554
const char * key
Definition: gis.h:555
int type
Definition: gis.h:556
const char * description
Definition: gis.h:563
char * answer
Definition: gis.h:568
int required
Definition: gis.h:557
int multiple
Definition: gis.h:558