libwreport 3.38
varinfo.h File Reference

Implement fast access to information about WMO variables. More...

#include <cstdint>
#include <string>
#include <iosfwd>
#include <wreport/fwd.h>

Go to the source code of this file.

Data Structures

struct  wreport::_Varinfo
 Information about a variable. More...
 

Namespaces

namespace  wreport
 String functions.
 

Macros

#define WR_VAR(f, x, y)
 Create a WMO variable code from its F, X and Y components.
 
#define WR_STRING_TO_VAR(str)
 Convert a XXYYY string to a WMO variable code.
 
#define WR_VAR_F(code)
 Get the F part of a WMO variable code.
 
#define WR_VAR_X(code)
 Get the X part of a WMO variable code.
 
#define WR_VAR_Y(code)
 Get the Y part of a WMO variable code.
 
#define WR_VAR_FXY(code)
 Expands to WR_VAR_F(code), WR_VAR_X(code), WR_VAR_Y(code).
 

Enumerations

enum class  wreport::Vartype : unsigned { Integer , Decimal , String , Binary }
 Variable type.
 

Functions

std::string wreport::varcode_format (Varcode code)
 Format a varcode into a string.
 
Varcode wreport::varcode_parse (const char *desc)
 Convert a FXXYYY string descriptor code into its short integer representation.
 
const char * wreport::vartype_format (Vartype type)
 Return a string description of a Vartype.
 
Vartype wreport::vartype_parse (const char *s)
 Return a Vartype from its string description.
 
std::ostream & wreport::operator<< (std::ostream &out, const Vartype &t)
 

Detailed Description

Implement fast access to information about WMO variables.

The measured value of a physical quantity has little meaning without specifying what quantity it represents, what units are used to measure it, and how many digits are significant for the value.

This module provides access to all this metadata:

  • wreport::Varcode represents what is the quantity measured, and takes values from the WMO B tables used for BUFR and CREX encodings. The WR_VAR macro can be used to construct wreport::Varcode values, and the WR_VAR_F, WR_VAR_X and WR_VAR_Y macros can be used to access the various parts of the dba_varcode.
  • wreport::Varinfo contains all the expanded information about a variable: its wreport::Varcode, description, measurement units, significant digits, minimum and maximum values it can have and other information useful for serialisation and deserialisation of values.

There are many B tables with slight differences used by different meteorological centre or equipment. This module allows to access different vartables using dba_vartable_create().

wreport::Vartable and wreport::Varinfo have special memory management: they are never deallocated. This is a precise design choice to speed up passing and copying wreport::Varinfo values, that are used very intensely as they accompany all the physical values processed by wreport. This behaviour should not be a cause of memory leaks, since a software would only need to access a limited amount of B tables during its lifetime.

To construct a wreport::Varcode value one needs to provide three numbers: F, X and Y.

  • F (2 bits) identifies the type of table entry represented by the dba_varcode, and is always 0 for B tables. Different values are only used during encoding and decoding of BUFR and CREX messages and are not in use in other parts of wreport.
  • X (6 bits) identifies a section of the table.
  • Y (8 bits) identifies the value within the section.

The normal text representation of a wreport::Varcode for a WMO B table uses the format Bxxyyy.

Macro Definition Documentation

◆ WR_STRING_TO_VAR

#define WR_STRING_TO_VAR ( str)
Value:
static_cast<wreport::Varcode>( \
(( ((str)[0] - '0')*10 + ((str)[1] - '0') ) << 8) | \
( ((str)[2] - '0')*100 + ((str)[3] - '0')*10 + ((str)[4] - '0') ) \
)
uint16_t Varcode
Holds the WMO variable code of a variable.
Definition fwd.h:12

Convert a XXYYY string to a WMO variable code.

This is useful only in rare cases, such as when parsing tables; use descriptor_code() to parse proper entry names such as "B01003" or "D21301".

◆ WR_VAR

#define WR_VAR ( f,
x,
y )
Value:
(static_cast<wreport::Varcode>( (static_cast<unsigned>(f)<<14) | (static_cast<unsigned>(x)<<8) | static_cast<unsigned>(y) ))

Create a WMO variable code from its F, X and Y components.

◆ WR_VAR_F

#define WR_VAR_F ( code)
Value:
(((code) >> 14) & 0x3)

Get the F part of a WMO variable code.

◆ WR_VAR_FXY

#define WR_VAR_FXY ( code)
Value:
WR_VAR_F(code), WR_VAR_X(code), WR_VAR_Y(code)
#define WR_VAR_X(code)
Get the X part of a WMO variable code.
Definition varinfo.h:84
#define WR_VAR_Y(code)
Get the Y part of a WMO variable code.
Definition varinfo.h:87
#define WR_VAR_F(code)
Get the F part of a WMO variable code.
Definition varinfo.h:81

Expands to WR_VAR_F(code), WR_VAR_X(code), WR_VAR_Y(code).

This is intended as a convenient shortcut to pass a broken down varcode to functions like printf, but not much more than that. Of course it evaluates its argument multiple times.

◆ WR_VAR_X

#define WR_VAR_X ( code)
Value:
((code) >> 8 & 0x3f)

Get the X part of a WMO variable code.

◆ WR_VAR_Y

#define WR_VAR_Y ( code)
Value:
((code) & 0xff)

Get the Y part of a WMO variable code.