libwreport 3.40
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 <iosfwd>
6#include <string>
7#include <wreport/fwd.h>
8
9namespace wreport {
10
60typedef uint16_t Varcode;
61
63std::string varcode_format(Varcode code);
64
68#define WR_VAR(f, x, y) \
69 (static_cast<wreport::Varcode>((static_cast<unsigned>(f) << 14) | \
70 (static_cast<unsigned>(x) << 8) | \
71 static_cast<unsigned>(y)))
72
79#define WR_STRING_TO_VAR(str) \
80 static_cast<wreport::Varcode>( \
81 ((((str)[0] - '0') * 10 + ((str)[1] - '0')) << 8) | \
82 (((str)[2] - '0') * 100 + ((str)[3] - '0') * 10 + ((str)[4] - '0')))
83
85#define WR_VAR_F(code) (((code) >> 14) & 0x3)
86
88#define WR_VAR_X(code) ((code) >> 8 & 0x3f)
89
91#define WR_VAR_Y(code) ((code) & 0xff)
92
100#define WR_VAR_FXY(code) WR_VAR_F(code), WR_VAR_X(code), WR_VAR_Y(code)
101
112Varcode varcode_parse(const char* desc);
113
115enum class Vartype : unsigned {
116 // Integer value
117 Integer,
118 // Floating point value
119 Decimal,
120 // String value
121 String,
122 // Opaque binary value
123 Binary,
124};
125
127const char* vartype_format(Vartype type);
128
130Vartype vartype_parse(const char* s);
131
132std::ostream& operator<<(std::ostream& out, const Vartype& t);
133
140{
143
146
148 char desc[64];
149
152 char unit[24];
153
160 int scale;
161
163 unsigned len;
164
172
174 unsigned bit_len;
175
177 int imin;
178
180 int imax;
181
183 double dmin;
184
186 double dmax;
187
197 int encode_decimal(double fval) const;
198
202 double round_decimal(double val) const;
203
213 uint32_t encode_binary(double fval) const;
214
224 double decode_decimal(int val) const;
225
235 double decode_binary(uint32_t val) const;
236
248 [[deprecated("Use varinfo_create_bufr")]] void
249 set_bufr(Varcode code, const char* desc, const char* unit, int scale = 0,
250 unsigned len = 0, int bit_ref = 0, int bit_len = 0);
251};
252
261typedef const _Varinfo* Varinfo;
262
269Varinfo varinfo_create_bufr(Varcode code, const char* desc, const char* unit,
270 unsigned bit_len, uint32_t bit_ref = 0,
271 int scale = 0);
272
279
280} // namespace wreport
281#endif
String functions.
Definition benchmark.h:13
Vartype vartype_parse(const char *s)
Return a Vartype from its string description.
void varinfo_delete(Varinfo &&info)
Deallocate a Varinfo created with create_bufr().
Vartype
Variable type.
Definition varinfo.h:115
std::string varcode_format(Varcode code)
Format a varcode into a string.
const char * vartype_format(Vartype type)
Return a string description of a Vartype.
Varinfo varinfo_create_bufr(Varcode code, const char *desc, const char *unit, unsigned bit_len, uint32_t bit_ref=0, int scale=0)
Allocate a new Varinfo to store BUFR values.
const _Varinfo * Varinfo
Varinfo reference.
Definition fwd.h:11
Varcode varcode_parse(const char *desc)
Convert a FXXYYY string descriptor code into its short integer representation.
uint16_t Varcode
Holds the WMO variable code of a variable.
Definition fwd.h:12
Information about a variable.
Definition varinfo.h:140
double decode_decimal(int val) const
Decode a double value from a decimal integer value using Varinfo decimal encoding informations (scale...
double round_decimal(double val) const
Round val so that it only fits the significant digits given in scale.
int imin
Minimum unscaled decimal integer value the field can have.
Definition varinfo.h:177
Varcode code
Variable code, as in WMO BUFR/CREX table B.
Definition varinfo.h:142
char unit[24]
Measurement unit of the variable, using the units defined in WMO BUFR/CREX table B.
Definition varinfo.h:152
unsigned len
Length in digits of the variable encoded as a decimal integer.
Definition varinfo.h:163
double dmin
Minimum value the field can have.
Definition varinfo.h:183
int bit_ref
Binary reference value for the variable.
Definition varinfo.h:171
int scale
Scale of the variable, defining its decimal precision.
Definition varinfo.h:160
unsigned bit_len
Length in bits of the variable when encoded as an unsigned binary value.
Definition varinfo.h:174
int imax
Minimum unscaled decimal integer value the field can have.
Definition varinfo.h:180
double decode_binary(uint32_t val) const
Decode a double value from a decimal integer value using Varinfo binary encoding informations (bit_re...
char desc[64]
Freeform variable description.
Definition varinfo.h:148
double dmax
Maximum value the field can have.
Definition varinfo.h:186
uint32_t encode_binary(double fval) const
Encode a double value into a positive integer value using Varinfo binary encoding informations (bit_r...
int encode_decimal(double fval) const
Encode a double value into a decimal integer value using Varinfo decimal encoding informations (scale...
Vartype type
Type of the value stored in the variable.
Definition varinfo.h:145
void set_bufr(Varcode code, const char *desc, const char *unit, int scale=0, unsigned len=0, int bit_ref=0, int bit_len=0)
Setup this variable as a BUFR variable.