bufr2synop 0.24.0
Functions | Variables
bufrdeco_utils.c File Reference

This file has the code of useful routines for library bufrdeco. More...

#include "bufrdeco.h"
Include dependency graph for bufrdeco_utils.c:

Go to the source code of this file.

Functions

buf_t get_bits_as_char_array2 (char *target, uint8_t *has_data, uint8_t *source, buf_t *bit0_offset, buf_t bit_length)
 
buf_t get_bits_as_char_array (char *target, uint8_t *has_data, uint8_t *source, buf_t *bit0_offset, buf_t bit_length)
 
uint32_t get_bits_as_uint32_t2 (uint32_t *target, uint8_t *has_data, uint8_t *source, buf_t *bit0_offset, buf_t bit_length)
 Read bits from an array of uint8_t and set them as an uint32_t. More...
 
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)
 
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. Most significant bit in source is sign. More...
 
uint32_t two_bytes_to_uint32 (const uint8_t *source)
 returns the uint32_t value from an array of two bytes, most significant first More...
 
uint32_t three_bytes_to_uint32 (const uint8_t *source)
 returns the uint32_t value from an array of three bytes, most significant first More...
 
int uint32_t_to_descriptor (struct bufr_descriptor *d, uint32_t id)
 parse an integer with a descriptor fom bufr ECWMF libary More...
 
int two_bytes_to_descriptor (struct bufr_descriptor *d, const uint8_t *source)
 set a struct bufr_descriptor from two consecutive bytes in bufr file More...
 
char * bufr_charray_to_string (char *s, char *buf, size_t size)
 get a null termitated c-string from an array of unsigned chars More...
 
char * bufr_adjust_string (char *s)
 Supress trailing blanks of a string. More...
 
int is_a_delayed_descriptor (struct bufr_descriptor *d)
 check if a descriptor is a delayed descriptor More...
 
int is_a_short_delayed_descriptor (struct bufr_descriptor *d)
 check if a descriptor is a short delayed descriptor More...
 
int is_a_local_descriptor (struct bufr_descriptor *d)
 check if a descriptor is a local descriptor More...
 
char * get_formatted_value_from_escale (char *fmt, size_t dim, int32_t escale, double val)
 gets a string with formatted value depending of scale More...
 
char * get_formatted_value_from_escale2 (char *fmt, size_t dim, int32_t escale, double val)
 gets a string with formatted value depending of scale More...
 
int bufrdeco_add_to_bitmap (struct bufrdeco_bitmap *bm, buf_t index_to, buf_t index_by)
 Push a bitmap element in a bufrdeco_bitmap. More...
 
int get_bitmaped_info (struct bufrdeco_bitmap_related_vars *brv, uint32_t target, struct bufrdeco *b)
 Get bitmap info searching into bitmaps. More...
 
int bufr_write_subset_offset_bits (FILE *f, struct bufrdeco_subset_bit_offsets *off)
 Write offset bit array for subsets in a non-compressed bufr. More...
 
int bufr_read_subset_offset_bits (FILE *f, struct bufrdeco_subset_bit_offsets *off)
 Write offset bit array for subsets in a non-compressed bufr. More...
 

Variables

uint8_t bitf [8] = {0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01}
 
uint8_t biti [8] = {0xFF,0x7f,0x3f,0x1F,0x0F,0x07,0x03,0x01}
 
uint8_t bitk [8] = {0x80,0xc0,0xe0,0xf0,0xf8,0xfc,0xfe,0xff}
 

Detailed Description

This file has the code of useful routines for library bufrdeco.

Definition in file bufrdeco_utils.c.

Function Documentation

◆ bufr_adjust_string()

char * bufr_adjust_string ( char *  s)

Supress trailing blanks of a string.

Parameters
sstring to process
Returns
the resulting s string

Definition at line 333 of file bufrdeco_utils.c.

334{
335 size_t l;
336
337 //bufrdeco_assert (s != NULL);
338
339 l = strlen ( s );
340 while ( l && s[--l] == ' ' )
341 s[l] = '\0';
342 return s;
343}

Referenced by bufrdeco_print_json_object_atom_data(), bufrdeco_print_json_tree_recursive(), and main().

Here is the caller graph for this function:

◆ bufr_charray_to_string()

char * bufr_charray_to_string ( char *  s,
char *  buf,
size_t  size 
)

get a null termitated c-string from an array of unsigned chars

Parameters
sresulting string
bufpointer to first element in array
sizenumber of chars in array
Returns
the resulting s string

Definition at line 316 of file bufrdeco_utils.c.

317{
318 //bufrdeco_assert (s != NULL && buf != NULL);
319
320 // copy
321 memcpy ( s , buf, size );
322 // add final string mark
323 s[size] = '\0';
324 return s;
325}

Referenced by main().

Here is the caller graph for this function:

◆ bufr_read_subset_offset_bits()

int bufr_read_subset_offset_bits ( FILE *  f,
struct bufrdeco_subset_bit_offsets off 
)

Write offset bit array for subsets in a non-compressed bufr.

Parameters
ffile pointer opened by caller
offpointer to the struct bufrdeco_subset_bit_offsets with the data to write into file
Returns
if success return 0, otherwise 1

Definition at line 577 of file bufrdeco_utils.c.

578{
579 size_t readed;
580
581 //bufrdeco_assert (off != NULL && f != NULL );
582
583 readed = fread( &(off->nr), sizeof (buf_t ), 1, f);
584 bufrdeco_assert_with_return_val (readed == 1, 1);
585
586 readed = fread( &(off->ofs[0]), sizeof (buf_t ), off->nr, f);
587 bufrdeco_assert_with_return_val (readed == off->nr, 1);
588
589 return 0;
590}
uint32_t buf_t
Type to set offsets and dimension of arrays or counters used in bufrdeco.
Definition: bufrdeco.h:346
#define bufrdeco_assert_with_return_val(__my_expr__, __returnval__)
Check a expression and returns a given value if it fails.
Definition: bufrdeco.h:385
buf_t ofs[BUFR_MAX_SUBSETS]
Definition: bufrdeco.h:687

References bufrdeco_assert_with_return_val, bufrdeco_subset_bit_offsets::nr, and bufrdeco_subset_bit_offsets::ofs.

Referenced by bufrdeco_read_subset_offset_bits().

Here is the caller graph for this function:

◆ bufr_write_subset_offset_bits()

int bufr_write_subset_offset_bits ( FILE *  f,
struct bufrdeco_subset_bit_offsets off 
)

Write offset bit array for subsets in a non-compressed bufr.

Parameters
ffile pointer opened by caller
offpointer to the struct bufrdeco_subset_bit_offsets with the data to write into file
Returns
if success return 0, otherwise 1

Definition at line 555 of file bufrdeco_utils.c.

556{
557 size_t wrote;
558
559 //bufrdeco_assert (off != NULL && f != NULL );
560
561 wrote = fwrite( &(off->nr), sizeof (buf_t ), 1, f);
562 bufrdeco_assert_with_return_val (wrote == 1, 1);
563
564 wrote = fwrite( &(off->ofs[0]), sizeof (buf_t ), off->nr, f);
565 bufrdeco_assert_with_return_val (wrote == off->nr, 1);
566
567 return 0;
568}

References bufrdeco_assert_with_return_val, bufrdeco_subset_bit_offsets::nr, and bufrdeco_subset_bit_offsets::ofs.

Referenced by bufrdeco_write_subset_offset_bits().

Here is the caller graph for this function:

◆ bufrdeco_add_to_bitmap()

int bufrdeco_add_to_bitmap ( struct bufrdeco_bitmap bm,
buf_t  index_to,
buf_t  index_by 
)

Push a bitmap element in a bufrdeco_bitmap.

Parameters
bmtarget struct bufrdeco_bitmap where to push
index_toindex of the bufrdeco_bitmap which this is bitmapping to
index_byindex of the bufrdeco_bitmap which this is bitmapped by
Returns
If no space to push returns 1, otherwise 0

Definition at line 461 of file bufrdeco_utils.c.

462{
463 //bufrdeco_assert (bm != NULL);
464
466 {
467 bm->bitmap_to[bm->nb] = index_to;
468 bm->bitmaped_by[bm->nb] = index_by;
469 ( bm->nb )++;
470 return 0;
471 }
472 return 1;
473}
#define BUFR_MAX_BITMAP_PRESENT_DATA
Max number of data present in a bitmap definition.
Definition: bufrdeco.h:232
buf_t bitmaped_by[BUFR_MAX_BITMAP_PRESENT_DATA]
Definition: bufrdeco.h:473
buf_t bitmap_to[BUFR_MAX_BITMAP_PRESENT_DATA]
Definition: bufrdeco.h:472

References bufrdeco_bitmap::bitmap_to, bufrdeco_bitmap::bitmaped_by, BUFR_MAX_BITMAP_PRESENT_DATA, and bufrdeco_bitmap::nb.

Referenced by bufrdeco_decode_replicated_subsequence(), and bufrdeco_decode_replicated_subsequence_compressed().

Here is the caller graph for this function:

◆ get_bitmaped_info()

int get_bitmaped_info ( struct bufrdeco_bitmap_related_vars brv,
uint32_t  target,
struct bufrdeco b 
)

Get bitmap info searching into bitmaps.

Parameters
brvpointer to struct bufrdeco_bitmap_related_vars where to set the results
targetThe key to find in array of bitmaps
bpointer to the current struct bufrdeco
Returns
If found the target return 0, othewise return 1

Definition at line 484 of file bufrdeco_utils.c.

485{
486 size_t i, j, k;
487 uint32_t delta;
488 struct bufrdeco_bitmap *bm;
489
490 //bufrdeco_assert (b != NULL && brv != NULL);
491
492 brv->target = target;
493 for ( i = 0; i < b->bitmap.nba ; i++ )
494 {
495 bm = b->bitmap.bmap[i];
496 for ( j = 0; j < bm->nb ; j++ )
497 {
498 if ( bm->bitmap_to[j] == target )
499 {
500 brv->nba = i;
501 brv->nb = j;
502 brv->bitmaped_by = bm->bitmaped_by[j];
503 delta = bm->bitmaped_by[j] - bm->bitmaped_by[0];
504 // quality data
505 if (bm->nq)
506 {
507 for (k = 0; k < bm->nq; k++)
508 {
509 brv->qualified_by[k] = bm->quality[k] + delta;
510 }
511 }
512
513 // substituded
514 if (bm->subs)
515 brv->substituted = bm->subs + delta;
516
517 if (bm->retain )
518 brv->retained = bm->retain + delta;
519
520 if (bm->ns1)
521 {
522 for (k = 0; k < bm->ns1; k++)
523 {
524 brv->stat1[k] = bm->stat1[k] + delta;
525 brv->stat1_desc[k] = bm->stat1[k];
526 }
527 }
528
529 if (bm->nds)
530 {
531 for (k = 0; k < bm->nds; k++)
532 {
533 brv->dstat[k] = bm->dstat[k] + delta;
534 brv->stat1_desc[k] = bm->dstat[k];
535 }
536 }
537
538 return 0;
539 }
540 else if ( b->bitmap.bmap[i]->bitmap_to[j] > target )
541 break;
542 }
543 }
544 return 1;
545}
struct bufrdeco_bitmap * bmap[BUFR_MAX_BITMAPS]
Definition: bufrdeco.h:493
Stores all needed data for a bufr bitmap.
Definition: bufrdeco.h:470
buf_t dstat[BUFR_MAX_QUALITY_DATA]
Definition: bufrdeco.h:482
buf_t stat1[BUFR_MAX_QUALITY_DATA]
Definition: bufrdeco.h:479
buf_t quality[BUFR_MAX_QUALITY_DATA]
Definition: bufrdeco.h:475
struct bufrdeco_bitmap_array bitmap
Definition: bufrdeco.h:980

References bufrdeco::bitmap, bufrdeco_bitmap::bitmap_to, bufrdeco_bitmap::bitmaped_by, bufrdeco_bitmap_related_vars::bitmaped_by, bufrdeco_bitmap_array::bmap, bufrdeco_bitmap::dstat, bufrdeco_bitmap_related_vars::dstat, bufrdeco_bitmap::nb, bufrdeco_bitmap_related_vars::nb, bufrdeco_bitmap_array::nba, bufrdeco_bitmap_related_vars::nba, bufrdeco_bitmap::nds, bufrdeco_bitmap::nq, bufrdeco_bitmap::ns1, bufrdeco_bitmap_related_vars::qualified_by, bufrdeco_bitmap::quality, bufrdeco_bitmap::retain, bufrdeco_bitmap_related_vars::retained, bufrdeco_bitmap::stat1, bufrdeco_bitmap_related_vars::stat1, bufrdeco_bitmap_related_vars::stat1_desc, bufrdeco_bitmap::subs, bufrdeco_bitmap_related_vars::substituted, and bufrdeco_bitmap_related_vars::target.

◆ get_bits_as_char_array()

buf_t get_bits_as_char_array ( char *  target,
uint8_t *  has_data,
uint8_t *  source,
buf_t bit0_offset,
buf_t  bit_length 
)

Definition at line 86 of file bufrdeco_utils.c.

87{
88 buf_t i, j, k;
89 buf_t nc;
90 uint8_t *c;
91
92 //bufrdeco_assert (has_data != NULL && source != NULL && target != NULL && bit0_offset != NULL);
93
94 if ( bit_length % 8 )
95 return 0; // bit_length needs to be divisible by 8
96
97 //printf("bit_length=%lu\n", bit_length);
98
99 nc = bit_length / 8;
100 i = ( *bit0_offset ) % 8;
101 k = 8 - i;
102 *has_data = 0; // marc if no missing data is present
103 for ( j = 0; j < nc ; j++ )
104 {
105 c = source + ( *bit0_offset ) / 8;
106 * ( target + j ) = ( *c & biti[i] );
107 if ( i )
108 {
109 * ( target + j ) <<= i;
110 * ( target + j ) |= ( ( * ( c + 1 ) & bitk[i - 1] ) >> k );
111 }
112 if ( * ( target + j ) != -1 )
113 *has_data = 1;
114 //printf("%c", * ( target + j ) );
115 *bit0_offset += 8; // update bit0_offset
116 }
117 * ( target + nc ) = '\0';
118 return bit_length;
119}
uint8_t biti[8]
uint8_t bitk[8]

References biti, and bitk.

Referenced by bufrdeco_get_atom_data_from_compressed_data_ref(), bufrdeco_parse_f2_compressed(), bufrdeco_parse_f2_descriptor(), bufrdeco_tableB_compressed(), and bufrdeco_tableB_val().

Here is the caller graph for this function:

◆ get_bits_as_char_array2()

buf_t get_bits_as_char_array2 ( char *  target,
uint8_t *  has_data,
uint8_t *  source,
buf_t bit0_offset,
buf_t  bit_length 
)

Definition at line 40 of file bufrdeco_utils.c.

41{
42 buf_t i, j;
43 buf_t r, d, nc;
44 uint8_t *c;
45
46 //bufrdeco_assert (has_data != NULL && source != NULL && target != NULL && bit0_offset != NULL);
47
48 if ( bit_length % 8 )
49 return 0; // bit_length needs to be divisible by 8
50
51 nc = bit_length / 8;
52 *has_data = 0; // marc if no missing data is present
53 for ( j = 0; j < nc ; j++ )
54 {
55 r = 8;
56 d = 0;
57 * ( target + j ) = 0;
58 do
59 {
60 c = source + ( *bit0_offset + d ) / 8;
61 i = ( *bit0_offset + d ) % 8;
62 if ( *c & bitf[i] )
63 * ( target + j ) += ( 1U << ( r - 1 ) );
64 else
65 *has_data = 1;
66 d += 1;
67 r -= 1;
68 }
69 while ( r > 0 );
70 *bit0_offset += 8; // update bit0_offset
71 }
72 * ( target + nc ) = '\0';
73 return bit_length;
74}
uint8_t bitf[8]

References bitf.

◆ get_bits_as_uint32_t()

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 
)

Definition at line 182 of file bufrdeco_utils.c.

183{
184 int i;
185 uint8_t *c;
186 uint64_t x;
187
188 //bufrdeco_assert (has_data != NULL && source != NULL && target != NULL && bit0_offset != NULL);
189
190 if ( bit_length > 32 || bit_length == 0 )
191 return 0;
192
193 if ( bit_length < 8 )
194 return get_bits_as_uint32_t2 ( target, has_data, source, bit0_offset, bit_length );
195
196 *target = 0;
197 *has_data = 0; // marc if no missing data is present
198 c = source + ( *bit0_offset ) / 8;
199 i = ( *bit0_offset ) % 8;
200 x = ( ( uint64_t ) ( *c & biti[i] ) << 32 ) + ( ( uint64_t ) ( * ( c + 1 ) ) << 24 ) + ( ( uint64_t ) ( * ( c + 2 ) ) << 16 ) +
201 ( ( uint64_t ) ( * ( c + 3 ) ) << 8 ) + ( uint64_t ) ( * ( c + 4 ) ); // 40 - i bits
202 x >>= ( 40 - i - bit_length );
203 *target = ( uint32_t ) x;
204 if ( ( 1UL << bit_length ) != ( x + 1UL ) )
205 *has_data = 1;
206
207 *bit0_offset += bit_length; // update bit0_offset
208 return bit_length;
209}
uint32_t get_bits_as_uint32_t2(uint32_t *target, uint8_t *has_data, uint8_t *source, buf_t *bit0_offset, buf_t bit_length)
Read bits from an array of uint8_t and set them as an uint32_t.

References biti, and get_bits_as_uint32_t2().

Referenced by bufrdeco_get_atom_data_from_compressed_data_ref(), bufrdeco_parse_f2_compressed(), bufrdeco_tableB_compressed(), and bufrdeco_tableB_val().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_bits_as_uint32_t2()

size_t get_bits_as_uint32_t2 ( uint32_t *  target,
uint8_t *  has_data,
uint8_t *  source,
buf_t bit0_offset,
buf_t  bit_length 
)

Read bits from an array of uint8_t and set them as an uint32_t.

Parameters
targetuint32_t pointer where to set the result
has_dataOutput flags to check whether is missing data. If 0 then data is missing, othewise has data
sourcearray of uint8_t elements. Most significant bit of first element is the bit offset reference
bit0_offsetBit offset
bit_lengthLenght (in bits) for the chunck to extract
Returns
If returns the amount of bits readed. 0 if problems. It also update bits_offset with the new bits.

This is a version which extract bit a bit. For more than about 8 bits should be used the algorithm in get_bits_as_uint32_t

Definition at line 135 of file bufrdeco_utils.c.

136{
137 buf_t i;
138 buf_t r, d;
139 uint8_t *c;
140
141 //bufrdeco_assert (has_data != NULL && source != NULL && target != NULL && bit0_offset != NULL);
142
143 if ( bit_length > 32 || bit_length == 0 )
144 return 0;
145
146 r = bit_length;
147 d = 0;
148 *target = 0;
149 *has_data = 0;
150
151 do
152 {
153 c = source + ( *bit0_offset + d ) / 8;
154 i = ( *bit0_offset + d ) % 8;
155 if ( *c & bitf[i] )
156 *target += ( 1U << ( r - 1 ) );
157 else
158 *has_data = 1;
159 d += 1;
160 r -= 1;
161 }
162 while ( r > 0 );
163 *bit0_offset += bit_length; // update bit0_offset
164
165 return bit_length;
166}

References bitf.

Referenced by get_bits_as_uint32_t().

Here is the caller graph for this function:

◆ get_formatted_value_from_escale()

char * get_formatted_value_from_escale ( char *  fmt,
size_t  dim,
int32_t  escale,
double  val 
)

gets a string with formatted value depending of scale

Parameters
fmtThe output target string
dimSize of available space (bytes) to write the result
escalevalue scale in descriptor
valdouble to printf
Returns
the resulting fmt string This version use 17 width for number plus a final space

Definition at line 410 of file bufrdeco_utils.c.

411{
412 char aux[32];
413 //bufrdeco_assert (fmt != NULL);
414
415 if ( escale >= 0 )
416 {
417 sprintf ( aux, "%%17.%dlf " , escale );
418 snprintf ( fmt, dim, aux, val );
419 }
420 else
421 snprintf ( fmt, dim, "%17.0lf " , val );
422 return fmt;
423}

Referenced by bufrdeco_print_atom_data(), and bufrdeco_print_atom_data_html().

Here is the caller graph for this function:

◆ get_formatted_value_from_escale2()

char * get_formatted_value_from_escale2 ( char *  fmt,
size_t  dim,
int32_t  escale,
double  val 
)

gets a string with formatted value depending of scale

Parameters
fmtThe output target string
dimSize of available space (bytes) to write the result
escalevalue scale in descriptor
valdouble to printf
Returns
the resulting fmt string

Differs from get_formatted_value_from_escale that no blanks are written

Definition at line 436 of file bufrdeco_utils.c.

437{
438 char aux[32];
439 //bufrdeco_assert (fmt != NULL);
440
441 if ( escale >= 0 )
442 {
443 sprintf ( aux, "%%.%dlf" , escale );
444 snprintf ( fmt, dim, aux, val );
445 }
446 else
447 snprintf ( fmt, dim, "%.0lf" , val );
448 return fmt;
449}

Referenced by bufrdeco_print_json_object_atom_data().

Here is the caller graph for this function:

◆ get_table_b_reference_from_uint32_t()

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. Most significant bit in source is sign.

Parameters
targetint32_t as result
bitsnumber of bits to consider
sourceuint32_T with the data to transform
Returns
If success return 0, 1 otherwise

Definition at line 221 of file bufrdeco_utils.c.

222{
223 uint32_t mask = 1;
224
225 //bufrdeco_assert (target != NULL);
226
227
228 if ( bits > 32 || bits == 0 )
229 return 1;
230
231 if ( bits > 1 )
232 mask = ( ( uint32_t ) 1 << ( bits - 1 ) );
233
234 if ( mask & source )
235 {
236 // case of negative number
237 *target = - ( int32_t ) ( source - mask );
238 }
239 else
240 *target = ( int32_t ) ( source );
241 return 0;
242}

Referenced by bufrdeco_tableB_compressed(), and bufrdeco_tableB_val().

Here is the caller graph for this function:

◆ is_a_delayed_descriptor()

int is_a_delayed_descriptor ( struct bufr_descriptor d)

check if a descriptor is a delayed descriptor

Parameters
dpointer to a struct bufr_descriptor to check
Returns
If is a delayed desccriptor return 1, 0 otherwise.

Definition at line 351 of file bufrdeco_utils.c.

352{
353 //bufrdeco_assert (d != NULL);
354
355 if ( ( d->f == 0 ) &&
356 ( d->x == 31 ) &&
357 ( d->y == 1 || d->y == 2 || d->y == 11 || d->y == 12 ) )
358 return 1;
359 else
360 return 0;
361}

References bufr_descriptor::f, bufr_descriptor::x, and bufr_descriptor::y.

Referenced by bufrdeco_fprint_tree_recursive(), bufrdeco_print_json_tree_recursive(), and bufrdeco_tableB_compressed().

Here is the caller graph for this function:

◆ is_a_local_descriptor()

int is_a_local_descriptor ( struct bufr_descriptor d)

check if a descriptor is a local descriptor

Parameters
dpointer to a struct bufr_descriptor to check
Returns
If is a local desccriptor return 1, 0 otherwise.

Definition at line 388 of file bufrdeco_utils.c.

389{
390 //bufrdeco_assert (d != NULL);
391
392 if ( ( d->f == 0 ) &&
393 ( d->x >= 48 ) &&
394 ( d->x <= 63 ) )
395 return 1;
396 else
397 return 0;
398}

References bufr_descriptor::f, and bufr_descriptor::x.

Referenced by bufrdeco_get_atom_data_from_compressed_data_ref(), bufrdeco_tableB_compressed(), and bufrdeco_tableB_val().

Here is the caller graph for this function:

◆ is_a_short_delayed_descriptor()

int is_a_short_delayed_descriptor ( struct bufr_descriptor d)

check if a descriptor is a short delayed descriptor

Parameters
dpointer to a struct bufr_descriptor to check
Returns
If is a delayed descriptor return 1, 0 otherwise.

Definition at line 369 of file bufrdeco_utils.c.

370{
371 //bufrdeco_assert (d != NULL);
372
373 if ( ( d->f == 0 ) &&
374 ( d->x == 31 ) &&
375 ( d->y == 0 ) )
376 return 1;
377 else
378 return 0;
379}

References bufr_descriptor::f, bufr_descriptor::x, and bufr_descriptor::y.

Referenced by bufrdeco_fprint_tree_recursive(), bufrdeco_print_json_tree_recursive(), and bufrdeco_tableB_compressed().

Here is the caller graph for this function:

◆ three_bytes_to_uint32()

uint32_t three_bytes_to_uint32 ( const uint8_t *  source)

returns the uint32_t value from an array of three bytes, most significant first

Parameters
sourcepointer to source uint8_t
Returns
the uint32_t resulting

Definition at line 265 of file bufrdeco_utils.c.

266{
267 //bufrdeco_assert (source != NULL);
268 return ( ( uint32_t ) source[2] + ( uint32_t ) source[1] * 256 + ( uint32_t ) source[0] * 65536 );
269}

Referenced by bufrdeco_read_buffer().

Here is the caller graph for this function:

◆ two_bytes_to_descriptor()

int two_bytes_to_descriptor ( struct bufr_descriptor d,
const uint8_t *  source 
)

set a struct bufr_descriptor from two consecutive bytes in bufr file

Parameters
sourcepointer to first byte (most significant)
dpointer to the resulting descriptor
Returns
0 if all is OK. 1 otherwise

Definition at line 297 of file bufrdeco_utils.c.

298{
299 //bufrdeco_assert (source != NULL && d != NULL);
300
301 d->y = source[1];
302 d->x = source[0] & 0x3f;
303 d->f = ( source[0] >> 6 ) & 0x03;
304 sprintf ( d->c, "%u%02u%03u", d->f, d->x, d->y );
305 return 0;
306}
char c[12]
Definition: bufrdeco.h:414

References bufr_descriptor::c, bufr_descriptor::f, bufr_descriptor::x, and bufr_descriptor::y.

Referenced by bufrdeco_read_buffer().

Here is the caller graph for this function:

◆ two_bytes_to_uint32()

uint32_t two_bytes_to_uint32 ( const uint8_t *  source)

returns the uint32_t value from an array of two bytes, most significant first

Parameters
sourcepointer to source uint8_t
Returns
the uint32_t resulting

Definition at line 250 of file bufrdeco_utils.c.

251{
252
253 //bufrdeco_assert (source != NULL);
254
255 return ( ( uint32_t ) source[1] + ( uint32_t ) source[0] * 256 );
256}

Referenced by bufrdeco_read_buffer().

Here is the caller graph for this function:

◆ uint32_t_to_descriptor()

int uint32_t_to_descriptor ( struct bufr_descriptor d,
uint32_t  id 
)

parse an integer with a descriptor fom bufr ECWMF libary

Parameters
dpointer to a struct bufr_descriptor where to set the result on output
idinteger with the descriptor from ewcwf
Returns
the resulting uint32_t

Definition at line 278 of file bufrdeco_utils.c.

279{
280 //bufrdeco_assert (d != NULL);
281
282 d->f = id / 100000;
283 d->x = ( id % 100000 ) / 1000;
284 d->y = id % 1000;
285 sprintf ( d->c, "%06u", id );
286 return 0;
287}

References bufr_descriptor::c, bufr_descriptor::f, bufr_descriptor::x, and bufr_descriptor::y.

Referenced by bufr_find_tableB_index(), bufr_find_tableC_csv_index(), bufr_read_tableB(), bufr_read_tableC(), bufr_read_tableD(), bufrdeco_tableD_get_descriptors_array(), and main().

Here is the caller graph for this function:

Variable Documentation

◆ bitf

uint8_t bitf[8] = {0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01}

Mask a single bit of a byte

Definition at line 26 of file bufrdeco_utils.c.

Referenced by get_bits_as_char_array2(), and get_bits_as_uint32_t2().

◆ biti

uint8_t biti[8] = {0xFF,0x7f,0x3f,0x1F,0x0F,0x07,0x03,0x01}

Mask remaining bits in a byte (less significant)

Definition at line 27 of file bufrdeco_utils.c.

Referenced by get_bits_as_char_array(), and get_bits_as_uint32_t().

◆ bitk

uint8_t bitk[8] = {0x80,0xc0,0xe0,0xf0,0xf8,0xfc,0xfe,0xff}

Mask first bits in a byte (most significant)

Definition at line 28 of file bufrdeco_utils.c.

Referenced by get_bits_as_char_array().