varinfo.h
Go to the documentation of this file.
#ifndef WREPORT_VARINFO_H
#define WREPORT_VARINFO_H
#include <cstdint>
#include <string>
#include <iosfwd>
#include <wreport/fwd.h>
namespace wreport {
typedef uint16_t Varcode;
std::string varcode_format(Varcode code);
#define WR_VAR(f, x, y) ((wreport::Varcode)( ((unsigned)(f)<<14) | ((unsigned)(x)<<8) | (unsigned)(y) ))
#define WR_STRING_TO_VAR(str) ((wreport::Varcode)( \
(( ((str)[0] - '0')*10 + ((str)[1] - '0') ) << 8) | \
( ((str)[2] - '0')*100 + ((str)[3] - '0')*10 + ((str)[4] - '0') ) \
))
#define WR_VAR_F(code) (((code) >> 14) & 0x3)
#define WR_VAR_X(code) ((code) >> 8 & 0x3f)
#define WR_VAR_Y(code) ((code) & 0xff)
#define WR_VAR_FXY(code) WR_VAR_F(code), WR_VAR_X(code), WR_VAR_Y(code)
Varcode varcode_parse(const char* desc);
enum class Vartype : unsigned
{
// Integer value
Integer,
// Floating point value
Decimal,
// String value
String,
// Opaque binary value
Binary,
};
const char* vartype_format(Vartype type);
Vartype vartype_parse(const char* s);
std::ostream& operator<<(std::ostream& out, const Vartype& t);
struct _Varinfo
{
Varcode code;
Vartype type;
char desc[64];
char unit[24];
int scale;
unsigned len;
int bit_ref;
unsigned bit_len;
int imin;
int imax;
double dmin;
double dmax;
int encode_decimal(double fval) const;
double round_decimal(double val) const;
uint32_t encode_binary(double fval) const;
double decode_decimal(int val) const;
double decode_binary(uint32_t val) const;
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);
void set_crex(Varcode code,
const char* desc,
const char* unit,
int scale=0, unsigned len=0);
void set_string(Varcode code, const char* desc, unsigned len);
void set_binary(Varcode code, const char* desc, unsigned bit_len);
void compute_range();
};
typedef const _Varinfo* Varinfo;
}
#endif
wreport
String functions.
Definition benchmark.h:13
wreport::vartype_parse
Vartype vartype_parse(const char *s)
Return a Vartype from its string description.
wreport::Vartype
Vartype
Variable type.
Definition varinfo.h:113
wreport::varcode_format
std::string varcode_format(Varcode code)
Format a varcode into a string.
wreport::vartype_format
const char * vartype_format(Vartype type)
Return a string description of a Vartype.
wreport::Varinfo
const _Varinfo * Varinfo
Varinfo reference.
Definition fwd.h:11
wreport::varcode_parse
Varcode varcode_parse(const char *desc)
Convert a FXXYYY string descriptor code into its short integer representation.
wreport::Varcode
uint16_t Varcode
Holds the WMO variable code of a variable.
Definition fwd.h:12
wreport::_Varinfo
Information about a variable.
Definition varinfo.h:139
wreport::_Varinfo::decode_decimal
double decode_decimal(int val) const
Decode a double value from a decimal integer value using Varinfo decimal encoding informations (scale...
wreport::_Varinfo::round_decimal
double round_decimal(double val) const
Round val so that it only fits the significant digits given in scale.
wreport::_Varinfo::imin
int imin
Minimum unscaled decimal integer value the field can have.
Definition varinfo.h:176
wreport::_Varinfo::code
Varcode code
Variable code, as in WMO BUFR/CREX table B.
Definition varinfo.h:141
wreport::_Varinfo::unit
char unit[24]
Measurement unit of the variable, using the units defined in WMO BUFR/CREX table B.
Definition varinfo.h:151
wreport::_Varinfo::len
unsigned len
Length in digits of the variable encoded as a decimal integer.
Definition varinfo.h:162
wreport::_Varinfo::dmin
double dmin
Minimum value the field can have.
Definition varinfo.h:182
wreport::_Varinfo::bit_ref
int bit_ref
Binary reference value for the variable.
Definition varinfo.h:170
wreport::_Varinfo::scale
int scale
Scale of the variable, defining its decimal precision.
Definition varinfo.h:159
wreport::_Varinfo::bit_len
unsigned bit_len
Length in bits of the variable when encoded as an unsigned binary value.
Definition varinfo.h:173
wreport::_Varinfo::imax
int imax
Minimum unscaled decimal integer value the field can have.
Definition varinfo.h:179
wreport::_Varinfo::decode_binary
double decode_binary(uint32_t val) const
Decode a double value from a decimal integer value using Varinfo binary encoding informations (bit_re...
wreport::_Varinfo::desc
char desc[64]
Freeform variable description.
Definition varinfo.h:147
wreport::_Varinfo::set_crex
void set_crex(Varcode code, const char *desc, const char *unit, int scale=0, unsigned len=0)
Set all the base Varinfo fields, then call compute_range.
wreport::_Varinfo::compute_range
void compute_range()
Compute the widest ranges for imin, imax, dmin and dmax that can fit any value that can be encoded bo...
wreport::_Varinfo::dmax
double dmax
Maximum value the field can have.
Definition varinfo.h:185
wreport::_Varinfo::encode_binary
uint32_t encode_binary(double fval) const
Encode a double value into a positive integer value using Varinfo binary encoding informations (bit_r...
wreport::_Varinfo::set_string
void set_string(Varcode code, const char *desc, unsigned len)
Set all the fields to represent a string variable.
wreport::_Varinfo::encode_decimal
int encode_decimal(double fval) const
Encode a double value into a decimal integer value using Varinfo decimal encoding informations (scale...
wreport::_Varinfo::type
Vartype type
Type of the value stored in the variable.
Definition varinfo.h:144
wreport::_Varinfo::set_binary
void set_binary(Varcode code, const char *desc, unsigned bit_len)
Set all the fields to represent an opaque binary variable.
wreport::_Varinfo::set_bufr
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)
Set all the base Varinfo fields, then call compute_range.