26#define BUFR_TABLEB_CHANGED_BITS (1)
27#define BUFR_TABLEB_CHANGED_SCALE (2)
28#define BUFR_TABLEB_CHANGED_REFERENCE (4)
30const int32_t
pow10pos_int[10]= {1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000};
31const double pow10pos[8]= {1.0, 10.0, 100.0, 1000.0, 10000.0, 100000.0, 1000000.0, 10000000.0};
32const double pow10neg[8]= {1.0, 0.1, 0.01, 0.001, 0.0001, 0.00001, 0.000001, 0.0000001};
58 if ( tb->
path[0] == 0 )
67 printf (
"# Reused table %s\n", tb->
path);
69 for ( i = 0; i < tb->
nlines ; i++ )
79 strcpy ( caux, tb->
path );
81 strcpy ( tb->
path, caux );
82 if ( ( t = fopen ( tb->
path,
"r" ) ) == NULL )
84 snprintf ( b->
error, sizeof (b->
error),
"Unable to open table B file '%s'\n", tb->
path );
96 snprintf ( b->
error, sizeof (b->
error),
"Error parsing csv line from table B file '%s'\n", tb->
path );
101 ix = strtoul ( tk[0], &
c, 10 );
107 if ( tb->
num[desc.
x] == 0 )
112 ( tb->
num[desc.
x] )++;
117 sprintf ( caux,
"%s %s", tk[1], tk[2] );
121 strcpy ( caux, tk[1] );
128 strcpy ( caux, tk[3] );
171 snprintf (b->
error, sizeof (b->
error),
"%s(): descriptor '%s' not found in table B\n", __func__, key );
214 ix = strtoul ( key, &
c, 10 );
219 if ( tb->
item[i0].
x == desc.
x && tb->
item[i0].
y == desc.
y )
226 for ( i = i0 ; i < i0 + tb->
num[desc.
x] ; i++ )
228 if ( tb->
item[i].
x != desc.
x )
232 if ( tb->
item[i].
y == desc.
y )
287 snprintf (b->
error, sizeof (b->
error),
"%s(): Cannot get bits from '%s'\n", __func__, d->
c );
294 snprintf (b->
error, sizeof (b->
error),
"%s(): Cannot get 6 bits for inc_bits from '%s'\n", __func__, d->
c );
320 if ( strstr ( r->
unit,
"CODE TABLE" ) != r->
unit && strstr ( r->
unit,
"FLAG" ) != r->
unit &&
321 strstr ( r->
unit,
"Code table" ) != r->
unit && strstr ( r->
unit,
"Flag" ) != r->
unit )
336 snprintf (b->
error, sizeof (b->
error),
"%s(): Cannot get bits from '%s'\n", __func__, d->
c );
344 snprintf (b->
error, sizeof (b->
error),
"%s(): Cannot change reference in 2 03 YYY operator for '%s'\n", __func__, d->
c );
354 snprintf (b->
error, sizeof (b->
error),
"%s(): Cannot get 6 bits for inc_bits from '%s'\n", __func__, d->
c );
361 snprintf (b->
error, sizeof (b->
error),
"%s(): Bad format for compressed data when changing reference from '%s'\n", __func__, d->
c );
369 if ( strstr ( r->
unit,
"CCITT" ) != NULL )
378 snprintf (b->
error, sizeof (b->
error),
"%s(): Cannot get uchars from '%s'\n", __func__, d->
c );
384 snprintf (b->
error, sizeof (b->
error),
"%s(): Cannot get 6 bits for inc_bits from '%s'\n", __func__, d->
c );
403 snprintf (b->
error, sizeof (b->
error),
"%s(): Cannot get associated bits from '%s'\n", __func__, d->
c );
414 snprintf (b->
error, sizeof (b->
error),
"%s(): Cannot get the data bits from '%s'\n", __func__, d->
c );
425 snprintf (b->
error, sizeof (b->
error),
"%s(): Cannot get 6 bits for inc_bits from '%s'\n", __func__, d->
c );
433 snprintf (b->
error, sizeof (b->
error),
"%s(): Found a delayed descriptor with inc_bits != 0\n", __func__ );
456 int32_t reference = 0;
471 snprintf (b->
error, sizeof (b->
error),
"%s(): Cannot get bits from '%s'\n", __func__, d->
c );
499 snprintf (b->
error, sizeof (b->
error),
"%s(): Cannot get bits from '%s'\n", __func__, d->
c );
506 snprintf (b->
error, sizeof (b->
error),
"%s(): Cannot change reference in 2 03 YYY operator for '%s'\n", __func__, d->
c );
516 reference = - ( ( int32_t ) 1 << ( tb->
item[i].
nbits ) );
521 if ( strstr ( a->
unit,
"CCITT" ) != NULL )
528 snprintf (b->
error, sizeof (b->
error),
"%s(): Cannot get uchars from '%s'\n", __func__, d->
c );
548 snprintf (b->
error, sizeof (b->
error),
"%s(): Cannot get associated bits from '%s'\n", __func__, d->
c );
556 if ( strstr ( a->
unit,
"CODE TABLE" ) != a->
unit && strstr ( a->
unit,
"FLAG" ) != a->
unit &&
557 strstr ( a->
unit,
"Code table" ) != a->
unit && strstr ( a->
unit,
"Flag" ) != a->
unit )
565 snprintf (b->
error, sizeof (b->
error),
"%s(): Cannot get bits from '%s'\n", __func__, d->
c );
570 if ( a->
desc.
x == 31 )
575 if ( strstr ( a->
unit,
"CODE TABLE" ) != a->
unit && strstr ( a->
unit,
"FLAG" ) != a->
unit &&
576 strstr ( a->
unit,
"Code table" ) != a->
unit && strstr ( a->
unit,
"Flag" ) != a->
unit )
586 a->
val = ( double ) ( ( int32_t ) ival + reference ) *
pow10neg[ (
size_t ) a->
escale];
590 a->
val = ( double ) ( ( int32_t ) ival + reference ) *
pow10pos[ (
size_t ) ( -a->
escale )];
594 a->
val = ( double ) ( ( int32_t ) ival + reference ) * exp10 ( (
double ) ( -a->
escale ) );
597 if ( strstr ( a->
unit,
"CODE TABLE" ) == a->
unit || strstr ( a->
unit,
"Code table" ) == a->
unit )
599 ival = ( uint32_t ) ( a->
val + 0.5 );
606 else if ( strstr ( a->
unit,
"FLAG" ) == a->
unit || strstr ( a->
unit,
"Flag" ) == a->
unit )
608 ival = ( uint32_t ) ( a->
val + 0.5 );
Include header file for bufrdeco library.
uint32_t buf_t
Type to set offsets and dimension of arrays or counters used in bufrdeco.
#define bufrdeco_assert(__my_expr__)
Check a expression and exit if it fails.
int get_table_b_reference_from_uint32_t(int32_t *target, uint8_t bits, uint32_t source)
Get an int32_t from bits according with bufr criteria to change the reference of a descritor....
#define strcpy_safe(_target_, _src_)
Macro to make safely a strcpy when we know in calling function the size of string target with sizeof(...
int uint32_t_to_descriptor(struct bufr_descriptor *d, uint32_t id)
parse an integer with a descriptor fom bufr ECWMF libary
int is_a_local_descriptor(struct bufr_descriptor *d)
check if a descriptor is a local descriptor
char * bufrdeco_explained_table_val(char *expl, size_t dim, struct bufr_tableC *tc, uint32_t *index, struct bufr_descriptor *d, uint32_t ival)
#define DESCRIPTOR_HAVE_FLAG_TABLE_STRING
Bit mask for a flag table string in a struct bufr_atom_data.
#define BUFR_MAXLINES_TABLEB
The maximum expected lines in a Table B file.
#define CSV_MAXL
Maximum length in a string to be parsed as csv.
uint32_t get_bits_as_char_array(char *target, uint8_t *has_data, uint8_t *source, buf_t *bit0_offset, buf_t bit_length)
char * bufrdeco_explained_flag_val(char *expl, size_t dim, struct bufr_tableC *tc, struct bufr_descriptor *d, uint64_t ival, uint8_t nbits)
#define DESCRIPTOR_HAVE_STRING_VALUE
Bit mask for a string in a struct bufr_atom_data.
#define DESCRIPTOR_IS_LOCAL
Bit mask for a flag table string in a struct bufr_atom_data.
#define MISSING_REAL
The missing default value for real values.
#define MISSING_INTEGER
The missing default value for integer values.
int parse_csv_line(int *nt, char *tk[], char *lin)
Parse a csv line.
uint32_t get_bits_as_uint32_t(uint32_t *target, uint8_t *has_data, uint8_t *source, buf_t *bit0_offset, buf_t bit_length)
#define DESCRIPTOR_IS_FLAG_TABLE
Bit mask for a flag table in a struct bufr_atom_data.
#define DESCRIPTOR_IS_CODE_TABLE
Bit mask for a code table in a struct bufr_atom_data.
int is_a_delayed_descriptor(struct bufr_descriptor *d)
check if a descriptor is a delayed descriptor
#define DESCRIPTOR_VALUE_MISSING
Bit mask for a missing value in a struct bufr_atom_data.
int is_a_short_delayed_descriptor(struct bufr_descriptor *d)
check if a descriptor is a short delayed descriptor
#define DESCRIPTOR_HAVE_CODE_TABLE_STRING
Bit mask for a code table string in a struct bufr_atom_data.
int bufr_find_tableB_index(buf_t *index, struct bufr_tableB *tb, const char *key)
found a descriptor index in a struct bufr_tableB
#define BUFR_TABLEB_CHANGED_SCALE
int bufrdeco_tableB_compressed(struct bufrdeco_compressed_ref *r, struct bufrdeco *b, struct bufr_descriptor *d, int mode)
get data from table B when parsing compressed data references
#define BUFR_TABLEB_CHANGED_BITS
#define BUFR_TABLEB_CHANGED_REFERENCE
int bufr_restore_original_tableB_item(struct bufr_tableB *tb, struct bufrdeco *b, uint8_t mode, char *key)
Restores the original table B parameters for a BUFR descriptor.
int bufrdeco_tableB_val(struct bufr_atom_data *a, struct bufrdeco *b, struct bufr_descriptor *d)
Get data from a table B descriptor.
const int32_t pow10pos_int[10]
int bufr_read_tableB(struct bufrdeco *b)
Contains all the information for a single data related with a descriptor in a expanded squence.
char name[BUFR_TABLEB_NAME_LENGTH]
char ctable[BUFR_EXPLAINED_LENGTH]
struct bufr_descriptor desc
char unit[BUFR_TABLEB_UNIT_LENGTH]
char cval[BUFR_CVAL_LENGTH]
char unit[BUFR_TABLEB_UNIT_LENGTH]
char name[BUFR_TABLEB_NAME_LENGTH]
Store a table B readed from a file formated and named as ECMWF bufrdc package.
struct bufr_tableB_decoded_item item[BUFR_MAXLINES_TABLEB]
char old_path[BUFRDECO_PATH_LENGTH]
char path[BUFRDECO_PATH_LENGTH]
Struct to hold the needed reference bit offsets, descriptor tree and replications in a compressed BUF...
char unit[BUFR_TABLEB_UNIT_LENGTH]
char name[BUFR_TABLEB_NAME_LENGTH]
struct bufr_descriptor * desc
uint8_t changing_reference
uint8_t local_bit_reserved
This struct contains all needed data to parse and decode a BUFR file.
struct bufrdeco_decoding_data_state state
struct bufr_tables * tables