libwreport  3.23
varinfo.h
Go to the documentation of this file.
1 #ifndef WREPORT_VARINFO_H
2 #define WREPORT_VARINFO_H
3 
4 #include <cstdint>
5 #include <string>
6 #include <wreport/fwd.h>
7 
8 namespace wreport {
9 
58 typedef uint16_t Varcode;
59 
61 std::string varcode_format(Varcode code);
62 
66 #define WR_VAR(f, x, y) ((wreport::Varcode)( ((unsigned)(f)<<14) | ((unsigned)(x)<<8) | (unsigned)(y) ))
67 
74 #define WR_STRING_TO_VAR(str) ((wreport::Varcode)( \
75  (( ((str)[0] - '0')*10 + ((str)[1] - '0') ) << 8) | \
76  ( ((str)[2] - '0')*100 + ((str)[3] - '0')*10 + ((str)[4] - '0') ) \
77 ))
78 
80 #define WR_VAR_F(code) (((code) >> 14) & 0x3)
81 
83 #define WR_VAR_X(code) ((code) >> 8 & 0x3f)
84 
86 #define WR_VAR_Y(code) ((code) & 0xff)
87 
95 #define WR_VAR_FXY(code) WR_VAR_F(code), WR_VAR_X(code), WR_VAR_Y(code)
96 
107 Varcode varcode_parse(const char* desc);
108 
109 
111 enum class Vartype : unsigned
112 {
113  // Integer value
114  Integer,
115  // Floating point value
116  Decimal,
117  // String value
118  String,
119  // Opaque binary value
120  Binary,
121 };
122 
123 
125 const char* vartype_format(Vartype type);
126 
128 Vartype vartype_parse(const char* s);
129 
130 
136 struct _Varinfo
137 {
139  Varcode code;
140 
143 
145  char desc[64];
146 
149  char unit[24];
150 
157  int scale;
158 
160  unsigned len;
161 
168  int bit_ref;
169 
171  unsigned bit_len;
172 
174  int imin;
175 
177  int imax;
178 
180  double dmin;
181 
183  double dmax;
184 
194  int encode_decimal(double fval) const;
195 
199  double round_decimal(double val) const;
200 
210  uint32_t encode_binary(double fval) const;
211 
221  double decode_decimal(int val) const;
222 
232  double decode_binary(uint32_t val) const;
233 
235  void set_bufr(Varcode code,
236  const char* desc,
237  const char* unit,
238  int scale=0, unsigned len=0,
239  int bit_ref=0, int bit_len=0);
240 
242  void set_crex(Varcode code,
243  const char* desc,
244  const char* unit,
245  int scale=0, unsigned len=0);
246 
254  void set_string(Varcode code, const char* desc, unsigned len);
255 
263  void set_binary(Varcode code, const char* desc, unsigned bit_len);
264 
270  void compute_range();
271 };
272 
273 
282 typedef const _Varinfo* Varinfo;
283 
284 }
285 #endif
Vartype vartype_parse(const char *s)
Return a Vartype from its string description.
Varcode varcode_parse(const char *desc)
Convert a FXXYYY string descriptor code into its short integer representation.
double dmax
Maximum value the field can have.
Definition: varinfo.h:183
Vartype type
Type of the value stored in the variable.
Definition: varinfo.h:142
int scale
Scale of the variable, defining its decimal precision.
Definition: varinfo.h:157
Vartype
Variable type.
Definition: varinfo.h:111
Varcode code
Variable code, as in WMO BUFR/CREX table B.
Definition: varinfo.h:139
const _Varinfo * Varinfo
Varinfo reference.
Definition: fwd.h:9
double dmin
Minimum value the field can have.
Definition: varinfo.h:180
uint16_t Varcode
Holds the WMO variable code of a variable.
Definition: fwd.h:11
Information about a variable.
Definition: varinfo.h:136
int bit_ref
Binary reference value for the variable.
Definition: varinfo.h:168
std::string varcode_format(Varcode code)
Format a varcode into a string.
unsigned bit_len
Length in bits of the variable when encoded as an unsigned binary value.
Definition: varinfo.h:171
String functions.
Definition: benchmark.h:13
int imax
Minimum unscaled decimal integer value the field can have.
Definition: varinfo.h:177
const char * vartype_format(Vartype type)
Return a string description of a Vartype.
unsigned len
Length in digits of the variable encoded as a decimal integer.
Definition: varinfo.h:160
int imin
Minimum unscaled decimal integer value the field can have.
Definition: varinfo.h:174