GRASS GIS 7 Programmer's Manual  7.9.dev(2021)-e5379bbd7
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 
11  struct Option *type;
12  struct Option *precision;
13  struct Option *compression;
14  struct Option *dimension;
15  struct Option *cache;
16 
17 } Rast3d_paramType;
18 
19 /*----------------------------------------------------------------------------*/
20 
21 static Rast3d_paramType *param;
22 
23 
24 /*!
25  * \brief
26  *
27  * Initializes a parameter
28  * structure for the subset of command line arguments which lets the user
29  * overwrite the default properties of the new file. Applications are
30  * encouraged to use this function in order to provide a uniform style. The
31  * command line arguments provided are the <em>type</em> of the cell values, the
32  * <em>precision</em>, the properties of the <em>compression</em>, and the dimension
33  * of the tiles (<em>tiledimension</em>). Every of these values defaults to the
34  * value described in RASTER3D Defaults.
35  * This function has to be used in conjunction with
36  * Rast3d_getStandard3dInputParams() (cf.{g3d:G3d.getStandard3dInputParams}).
37  *
38  * \return void
39  */
40 
42 {
43  param = Rast3d_malloc(sizeof(Rast3d_paramType));
44 
46 
47  param->precision = G_define_standard_option(G_OPT_R3_PRECISION);
48 
49  param->compression = G_define_standard_option(G_OPT_R3_COMPRESSION);
50 
52 }
53 
54 /*----------------------------------------------------------------------------*/
55 
56 int Rast3d_get_standard3d_params(int *useTypeDefault, int *type,
57  int *useCompressionDefault, int *doCompression,
58  int *usePrecisionDefault, int *precision,
59  int *useDimensionDefault, int *tileX, int *tileY,
60  int *tileZ)
61 {
62 
63  *useTypeDefault = *useCompressionDefault = 0;
64  *usePrecisionDefault = *useDimensionDefault = 0;
65 
67 
68  if (strcmp(param->type->answer, "double") == 0)
69  *type = DCELL_TYPE;
70  else if (strcmp(param->type->answer, "float") == 0)
71  *type = FCELL_TYPE;
72  else {
73  *type = Rast3d_get_file_type();
74  *useTypeDefault = 1;
75  }
76 
77  Rast3d_get_compression_mode(doCompression, precision);
78 
79  if (strcmp(param->precision->answer, "default") != 0) {
80  if (strcmp(param->precision->answer, "max") == 0)
81  *precision = -1;
82  else if ((sscanf(param->precision->answer, "%d", precision) != 1) ||
83  (*precision < 0)) {
84  Rast3d_error(_("Rast3d_get_standard3d_params: precision value invalid"));
85  return 0;
86  }
87  }
88  else
89  *usePrecisionDefault = 1;
90 
91 
92  if (strcmp(param->compression->answer, "default") != 0) {
93  if (strcmp(param->compression->answer, "zip") == 0)
94  *doCompression = RASTER3D_COMPRESSION;
95  else
96  *doCompression = RASTER3D_NO_COMPRESSION;
97  } else {
98  *useCompressionDefault = 1;
99  }
100 
101  Rast3d_get_tile_dimension(tileX, tileY, tileZ);
102  if (strcmp(param->dimension->answer, "default") != 0) {
103  if (sscanf(param->dimension->answer, "%dx%dx%d",
104  tileX, tileY, tileZ) != 3) {
105  Rast3d_error(_("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 }
char * Rast3d_get_window_params(void)
Definition: param.c:134
void Rast3d_init_defaults(void)
Initializes the default values described in RASTER3D Defaults. Applications have to use this function...
Definition: defaults.c:305
#define NO
Definition: gis.h:164
unsigned short compression
Definition: gsd_img_tif.c:42
void Rast3d_set_window_params(void)
Definition: param.c:121
void * Rast3d_malloc(int)
Same as malloc (nBytes), except that in case of error Rast3d_error() is invoked.
#define RASTER3D_WINDOW_ELEMENT
Definition: raster3d.h:40
#define TYPE_STRING
Definition: gis.h:162
#define NULL
Definition: ccmath.h:32
void Rast3d_error(const char *,...) __attribute__((format(printf
const char * description
Definition: gis.h:541
int type
Definition: gis.h:534
struct Option * G_define_standard_option(int)
Create standardised Option structure.
#define DCELL_TYPE
Definition: raster.h:13
void Rast3d_get_compression_mode(int *, int *)
Gets compression mode.
Definition: defaults.c:128
char * answer
Definition: gis.h:544
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:56
struct Option * G_define_option(void)
Initializes an Option struct.
Definition: parser.c:210
int multiple
Definition: gis.h:536
int required
Definition: gis.h:535
#define RASTER3D_NO_COMPRESSION
Definition: raster3d.h:14
void Rast3d_set_standard3d_input_params()
Initializes a parameter structure for the subset of command line arguments which lets the user overwr...
Definition: param.c:41
int Rast3d_get_file_type(void)
get G3d file type
Definition: defaults.c:227
void Rast3d_get_tile_dimension(int *, int *, int *)
get Tile Dimension
Definition: defaults.c:271
Structure that stores option information.
Definition: gis.h:531
#define _(str)
Definition: glocale.h:10
#define FCELL_TYPE
Definition: raster.h:12
char * G_store(const char *)
Copy string to allocated memory.
Definition: strings.c:87
const char * key
Definition: gis.h:533
#define RASTER3D_COMPRESSION
Definition: raster3d.h:15
void Rast3d_free(void *)
Same as free (ptr).