bufr2synop 0.24.0
bufrdeco.h
Go to the documentation of this file.
1/***************************************************************************
2 * Copyright (C) 2013-2022 by Guillermo Ballester Valor *
3 * gbv@ogimet.com *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
20/*!
21 \file bufrdeco.h
22 \brief Include header file for bufrdeco library
23*/
24#ifndef BUFRDECO_H
25#define BUFRDECO_H
26
27#ifndef _GNU_SOURCE
28#define _GNU_SOURCE
29#endif
30
31// Uncomment following line to get timimgs in debug phase
32//#define DEBUG_TIME
33
34#include <stdio.h>
35#include <stdlib.h>
36#include <stdint.h>
37#include <string.h>
38#include <getopt.h>
39#include <time.h>
40#ifdef DEBUG_TIME
41#include <sys/times.h>
42#include <unistd.h>
43#endif
44#include <math.h>
45#include <sys/stat.h>
46
47// Uncomment following line to debug
48//#define __DEBUG
49
50/*!
51 * \def BUFRDECO
52 * \brief Name of this library
53 */
54#define BUFRDECO "bufrdeco"
55
56/*!
57 \def BUFR_LEN
58 \brief Max length of a BUFR file
59*/
60#define BUFR_LEN (512000)
61
62/*!
63 \def BUFR_OBS_DATA_MASK
64 \brief Bit mask for Observed data
65*/
66#define BUFR_OBS_DATA_MASK 128
67
68/*!
69 \def BUFR_COMPRESSED_DATA_MASK
70 \brief Bit mask for compressed data
71*/
72#define BUFR_COMPRESSED_DATA_MASK 64
73
74/*!
75 \def MISSING_REAL
76 \brief The missing default value for real values
77*/
78#define MISSING_REAL (1.7e38)
79
80/*!
81 \def MISSING_INTEGER
82 \brief The missing default value for integer values
83*/
84#define MISSING_INTEGER (2147483647)
85
86/*!
87 \def BUFR_MAXLINES_TABLEB
88 \brief The maximum expected lines in a Table B file
89*/
90#define BUFR_MAXLINES_TABLEB (2048)
91
92/*!
93 \def BUFR_MAXLINES_TABLEC
94 \brief The maximum expected lines in a Table C file
95*/
96#define BUFR_MAXLINES_TABLEC (8192)
97
98
99/*!
100 \def BUFR_MAXLINES_TABLED
101 \brief The maximum expected lines in a Table D file
102*/
103#define BUFR_MAXLINES_TABLED (8192)
104
105
106/*!
107 \def MAXLINES_TABLEC
108 \brief The maximum expected lines in a Table C file, legacy def used from ECMWF
109*/
110#define MAXLINES_TABLEC BUFR_MAXLINES_TABLEC
111
112/*!
113 \def BUFR_NMAXSEQ
114 \brief Maximum expected descriptors in a expanded sequence for a single subset
115*/
116#define BUFR_NMAXSEQ (2 * 16384)
117
118/*!
119 \def BUFR_EXPLAINED_LENGTH
120 \brief Maximum length for a explained descriptor string
121*/
122#define BUFR_EXPLAINED_LENGTH (512)
123
124/*!
125 \def CSV_MAXL
126 \brief Maximum length in a string to be parsed as csv
127*/
128#define CSV_MAXL (2048)
129
130/*!
131 \def NMAXSEQ_DESCRIPTORS
132 \brief Maximum nuber of unexpanded descriptors in a struct \ref bufr_sequence
133*/
134#define NMAXSEQ_DESCRIPTORS (256)
135
136/*!
137 \def DESCRIPTOR_VALUE_MISSING
138 \brief Bit mask for a missing value in a struct \ref bufr_atom_data
139*/
140#define DESCRIPTOR_VALUE_MISSING (1)
141
142/*!
143 \def DESCRIPTOR_HAVE_REAL_VALUE
144 \brief Bit mask for a real value in a struct \ref bufr_atom_data
145*/
146#define DESCRIPTOR_HAVE_REAL_VALUE (2)
147
148/*!
149 \def DESCRIPTOR_HAVE_STRING_VALUE
150 \brief Bit mask for a string in a struct \ref bufr_atom_data
151*/
152#define DESCRIPTOR_HAVE_STRING_VALUE (4)
153
154/*!
155 \def DESCRIPTOR_IS_CODE_TABLE
156 \brief Bit mask for a code table in a struct \ref bufr_atom_data
157*/
158#define DESCRIPTOR_IS_CODE_TABLE (8)
159
160/*!
161 \def DESCRIPTOR_HAVE_CODE_TABLE_STRING
162 \brief Bit mask for a code table string in a struct \ref bufr_atom_data
163*/
164#define DESCRIPTOR_HAVE_CODE_TABLE_STRING (16)
165
166/*!
167 \def DESCRIPTOR_HAVE_FLAG_TABLE_STRING
168 \brief Bit mask for a flag table string in a struct \ref bufr_atom_data
169*/
170#define DESCRIPTOR_HAVE_FLAG_TABLE_STRING (32)
171
172/*!
173 \def DESCRIPTOR_IS_FLAG_TABLE
174 \brief Bit mask for a flag table in a struct \ref bufr_atom_data
175*/
176#define DESCRIPTOR_IS_FLAG_TABLE (64)
177
178/*!
179 \def DESCRIPTOR_IS_A_REPLICATOR
180 \brief Bit mask for a replicator descriptor in a struct \ref bufr_atom_data
181*/
182#define DESCRIPTOR_IS_A_REPLICATOR (128)
183
184/*!
185 \def DESCRIPTOR_IS_AN_OPERATOR
186 \brief Bit mask for an operator data descriptor in a struct \ref bufr_atom_data
187*/
188#define DESCRIPTOR_IS_AN_OPERATOR (256)
189
190/*!
191 \def DESCRIPTOR_IS_LOCAL
192 \brief Bit mask for a flag table string in a struct \ref bufr_atom_data
193*/
194#define DESCRIPTOR_IS_LOCAL (512)
195
196/*!
197 \def BUFR_LEN_SEC1
198 \brief Max length in bytes for a sec1
199*/
200#define BUFR_LEN_SEC1 (8192)
201
202/*!
203 \def BUFR_LEN_SEC2
204 \brief Max length in bytes for a sec2
205*/
206#define BUFR_LEN_SEC2 (8192)
207
208
209/*!
210 \def BUFR_LEN_UNEXPANDED_DESCRIPTOR
211 \brief Max amount of unexpanded descriptors in a SEC3
212*/
213#define BUFR_LEN_UNEXPANDED_DESCRIPTOR (512)
214
215
216/*!
217 \def BUFR_MAX_EXPANDED_SEQUENCES
218 \brief Max amount of unexpanded sequences in a struct \ref bufrdeco_expanded_tree
219*/
220#define BUFR_MAX_EXPANDED_SEQUENCES (128)
221
222/*!
223 \def BUFR_MAX_QUALITY_DATA
224 \brief Max amount of quality data which is maped by a struct \ref bufrdeco_bitmap element
225*/
226#define BUFR_MAX_QUALITY_DATA (8)
227
228/*!
229 \def BUFR_MAX_BITMAP_PRESENT_DATA
230 \brief Max number of data present in a bitmap definition
231*/
232#define BUFR_MAX_BITMAP_PRESENT_DATA (4096)
233
234/*!
235 \def BUFR_MAX_BITMAPS
236 \brief Max number of structs \ref bufrdeco_bitmap that can be allocated in a struct \ref bufrdeco_bitmap_array
237*/
238#define BUFR_MAX_BITMAPS (8)
239
240/*!
241 * \def BUFR_MAX_SUBSETS
242 * \brief Max number of subsets in the array off bitoffset subset marks the bufrdeco library can manage
243 */
244#define BUFR_MAX_SUBSETS (2048)
245
246/*!
247 \def BUFR_LEN_SEC3
248 \brief Max length in bytes for a sec3
249*/
250#define BUFR_LEN_SEC3 (8 + 2 * BUFR_LEN_UNEXPANDED_DESCRIPTOR)
251
252/*!
253 \def BUFRDECO_OUTPUT_HTML
254 \brief Bit mask to the member mask for struct \ref bufrdeco to format output as html for SECs 0 to 3
255*/
256#define BUFRDECO_OUTPUT_HTML (1)
257
258/*!
259 \def BUFRDECO_OUTPUT_XML
260 \brief Bit mask to the member mask for struct \ref bufrdeco to format output as xml for SECs 0 to 3
261*/
262#define BUFRDECO_OUTPUT_XML (2)
263
264/*!
265 * \def BUFRDECO_USE_TABLES_CACHE
266 * \brief Bit mask to the member mask of struct \ref bufrdeco to mark the use of \ref bufr_tables cache
267 */
268#define BUFRDECO_USE_TABLES_CACHE (4)
269
270
271/*!
272 * \def BUFRDECO_OUTPUT_JSON_SEC0
273 * \brief Bit mask to the member mask of struct \ref bufrdeco to print info for SEC 0 in json format
274 */
275#define BUFRDECO_OUTPUT_JSON_SEC0 (8)
276
277/*!
278 * \def BUFRDECO_OUTPUT_JSON_SEC1
279 * \brief Bit mask to the member mask of struct \ref bufrdeco to print info for SEC 1 in json format
280 */
281#define BUFRDECO_OUTPUT_JSON_SEC1 (16)
282
283/*!
284 * \def BUFRDECO_OUTPUT_JSON_SEC2
285 * \brief Bit mask to the member mask of struct \ref bufrdeco to print bufr info for SEC 2 in json format
286 */
287#define BUFRDECO_OUTPUT_JSON_SEC2 (32)
288
289/*!
290 * \def BUFRDECO_OUTPUT_JSON_SEC3
291 * \brief Bit mask to the member mask of struct \ref bufrdeco to print bufr info for SEC 3 in json format
292 */
293#define BUFRDECO_OUTPUT_JSON_SEC3 (64)
294
295/*!
296 * \def BUFRDECO_OUTPUT_JSON_SUBSET_DATA
297 * \brief Bit mask to the member mask of struct \ref bufrdeco to print bufr subset data in json format
298 */
299#define BUFRDECO_OUTPUT_JSON_SUBSET_DATA (128)
300
301/*!
302 * \def BUFRDECO_OUTPUT_JSON_EXPANDED_TREE
303 * \brief Bit mask to the member mask of struct \ref bufrdeco to print bufr expanded tree of descriptors
304 */
305#define BUFRDECO_OUTPUT_JSON_EXPANDED_TREE (256)
306
307/*!
308 \def BUFRDECO_OUTPUT_JSON
309 \brief Bit mask to the member mask for struct \ref bufrdeco to format output as json for SECs 0 to 3
310*/
311#define BUFRDECO_OUTPUT_JSON (BUFRDECO_OUTPUT_JSON_SEC0 | BUFRDECO_OUTPUT_JSON_SEC1 | BUFRDECO_OUTPUT_JSON_SEC2 | BUFRDECO_OUTPUT_JSON_SEC3 )
312
313/*!
314 \def BUFR_TABLEB_NAME_LENGTH
315 \brief Max length (in chars) reserved for a name of variable in table B
316*/
317#define BUFR_TABLEB_NAME_LENGTH (128)
318
319/*!
320 \def BUFR_TABLEB_NAME_LENGTH
321 \brief Max length (in chars) reserved for the unit string in table B
322*/
323#define BUFR_TABLEB_UNIT_LENGTH (64)
324
325/*!
326 * \def BUFR_CVAL_LENGTH
327 * \brief Max length (in chars) of a cval in a \ref bufr_atom_data
328 */
329#define BUFR_CVAL_LENGTH (128)
330
331/*!
332 * \def BUFRDECO_PATH_LENGTH
333 * \brief Length for files/directory path strings
334 */
335#define BUFRDECO_PATH_LENGTH (256)
336
337/*!
338 * \def BUFRDECO_TABLES_CACHE_SIZE
339 * \brief Max number of structs \ref bufr_tables in a \ref bufr_tables_cache
340 */
341#define BUFRDECO_TABLES_CACHE_SIZE (16)
342
343/*! \typedef buf_t
344 \brief Type to set offsets and dimension of arrays or counters used in bufrdeco
345*/
346typedef uint32_t buf_t;
347
348/*! \typedef ibuf_t
349 \brief Type to set offsets and dimension of arrays or counters used in bufrdeco
350*/
351typedef int32_t ibuf_t;
352
353
354/*!
355 * \def strcpy_safe
356 * \brief Macro to make safely a strcpy when we know in calling function the size of string _target_ with sizeof()
357 */
358#define strcpy_safe(_target_,_src_) {\
359 strncpy(_target_,_src_,(sizeof(_target_) - 1)); \
360 _target_[sizeof(_target_) - 1] = '\0';}
361
362/*!
363 * \def strncpy_safe
364 * \brief Macro to make safely a strcpy when we know in calling function the size of string _target_ directly
365 */
366#define strncpy_safe(_target_,_src_,_dim_) {\
367 strncpy(_target_, _src_, _dim_ - 1); \
368 _target_[_dim_ - 1] = '\0';}
369
370/*!
371 * \def bufrdeco_assert
372 * \brief Check a expression and exit if it fails
373 */
374#define bufrdeco_assert(__my_expr__) \
375 if ( !(__my_expr__)) {\
376 fprintf(stderr, "%s: %s():%d -> ***The expression (%s) is false***\n", \
377 basename(__FILE__), __func__, __LINE__, #__my_expr__) ; \
378 exit (EXIT_FAILURE);\
379 }
380
381/*!
382 * \def bufrdeco_assert_with_return_val
383 * \brief Check a expression and returns a given value if it fails
384 */
385#define bufrdeco_assert_with_return_val(__my_expr__, __returnval__) \
386 if ( !(__my_expr__)) {\
387 fprintf(stderr, "%s: %s():%d -> ***The expression (%s) is false***\n", \
388 basename(__FILE__), __func__, __LINE__, #__my_expr__) ; \
389 return (__returnval__);\
390 }
391
392#ifdef DEBUG_TIME
393/*!
394 * \def print_timing
395 * \brief Macro to print the time interval between two clocks(). Useful in debug time.
396 */
397# define print_timing(__clk_start, __clk_end,__explanation) \
398 printf ("# %.6lf s <- Elapsed time for %s\n", (double)(__clk_end - __clk_start)/(double)(CLOCKS_PER_SEC), #__explanation)
399
400extern clock_t bufrdeco_clock_start, bufrdeco_clock_end;
401
402#endif
403
404/*!
405 \struct bufr_descriptor
406 \brief BUFR descriptor
407*/
409{
410 uint8_t f; /*!< F part of descriptor, 2 bits */
411 uint8_t x; /*!< X part of descriptor, 6 bits */
412 uint8_t y; /*!< Y part of descriptor, 8 bits */
413 uint8_t foo; /*!< Not used , to align the struct and size it to 16 bytes */
414 char c[12]; /*!< string with whole descriptor (6 decimal digits plus the 0x00 as the end of string */
415};
416
417/*!
418 \struct bufr_replicator
419 \brief store the information when parsing related to replicators
420*/
422{
423 struct bufr_sequence *s; /*!< struct to which this replicator struct belongs */
424 buf_t ixrep; /*!< index in a sequence of replicator descriptor */
425 buf_t ixdel; /*!< index in a sequence of a delayed replicator, if not then is the same that ixrep */
426 buf_t ndesc; /*!< amount of descritptors in sequence affected by replicator */
427 buf_t nloops; /*!< amount of loops to do */
428};
429
430/*!
431 \struct bufr_atom_data
432 \brief Contains all the information for a single data related with a descriptor in a expanded squence
433*/
435{
436 struct bufr_descriptor desc; /*!< struct \ref bufr_descriptor */
437 uint32_t mask; /*!< Mask with for the type */
438 char name[BUFR_TABLEB_NAME_LENGTH]; /*!< String with the name of descriptor */
439 char unit[BUFR_TABLEB_UNIT_LENGTH]; /*!< String with the name of units */
440 double val; /*!< Final value for the bufr descriptor data */
441 int32_t escale; /*!< Scale applied to get the data */
442 uint32_t associated; /*!< value for associated field, if any */
443 char cval[BUFR_CVAL_LENGTH]; /*!< String value for the bufr descriptor */
444 char ctable[BUFR_EXPLAINED_LENGTH]; /*!< Explained meaning for a code table */
445 struct bufr_sequence *seq; /*!< Pointer to the struct \ref bufr_sequence to which this descriptor belongs to */
446 buf_t ns; /*!< Element in bufr_sequence to which this descriptor belongs to */
447 buf_t is_bitmaped_by; /*!< Index of element in a struct \ref bufrdeco_subset_sequence_data which bitmap this one */
448 buf_t bitmap_to; /*!< Index of element in a struct \ref bufrdeco_subset_sequence_data which this one is mapping to */
449 buf_t related_to; /*!< Index of element in a struct \ref bufrdeco_subset_sequence_data which this one is related to */
450};
451
452/*!
453 \struct bufrdeco_subset_sequence_data
454 \brief Contains all the information for a subset in a expanded squence
455 This is a version to use with bufrdeco parse library
456*/
458{
459 buf_t dim; /*!< Amount of bufr_atom_data currently allocated */
460 buf_t nd; /*!< number of current amount of data used in sequence */
461 buf_t ss; /*!< Index of subset in the bufr report */
462 struct bufr_atom_data *sequence; /*!< the array of data associated structs \ref bufr_atom_data of an expanded sequence */
463};
464
465/*!
466 \struct bufrdeco_bitmap
467 \brief Stores all needed data for a bufr bitmap
468*/
470{
471 buf_t nb; /*!< Amount of elements used (data present) in the bitmap */
472 buf_t bitmap_to[BUFR_MAX_BITMAP_PRESENT_DATA]; /*!< Array of indexes in a sequence which bitmaps to */
473 buf_t bitmaped_by[BUFR_MAX_BITMAP_PRESENT_DATA]; /*!< Array of indexes in a bitmaps */
474 buf_t nq; /*!< Amount of quality parameters used per bitmaped data */
475 buf_t quality[BUFR_MAX_QUALITY_DATA]; /*!< array of indexes of first quality value related to bitmap_to[0] */
476 buf_t subs; /*!< index of subsituted value related to bitmap_to[0] */
477 buf_t retain; /*!< Index of retained value related tp bitmap_to[0] */
478 buf_t ns1; /*!< amount of first order statistical parameters used per bitmaped data */
479 buf_t stat1[BUFR_MAX_QUALITY_DATA]; /*!< Array of indexes of First-order statistical value related to bitmap_to[0] */
480 buf_t stat1_desc[BUFR_MAX_QUALITY_DATA]; /*!< Array of indexes which describes the First-order statistical parameter */
481 buf_t nds; /*!< amount of difference statistical parameters used per bitmaped data */
482 buf_t dstat[BUFR_MAX_QUALITY_DATA]; /*!< Attay of indexes of Difference statistical value related tp bitmap_to[0] */
483 buf_t dstat_desc[BUFR_MAX_QUALITY_DATA]; /*!< Array of indexes which describes the diffenece statistical parameter */
484};
485
486/*!
487 \struct bufrdeco_bitmap_array
488 \brief Stores all structs \ref bufrdeco_bitmap for a bufr bitmap
489*/
491{
492 buf_t nba; /*!< Amount of bitmaps used */
493 struct bufrdeco_bitmap *bmap[BUFR_MAX_BITMAPS]; /*!< array of pointers to struct \ref bufrdeco_bitmap */
494};
495
496/*!
497 \struct bufrdeco_bitmap_related_vars
498 \brief Contains data related to a target variable with the aid of a bitmap
499*/
501{
502 buf_t target; /*! Index in a subset sequence which related bitmaped vars are set in this struct */
503 buf_t nba; /*!< Index of struct \ref bufrdeco_bitmap in a \ref bufrdeco_bitmap_array which is used to get info for target */
504 buf_t nb; /*!< Index in a \ref bufrdeco_bitmap which is related with target */
505 buf_t bitmaped_by; /*!< Index in a subset sequence which bitmaps the target */
506 buf_t nq; /*!< Amount of quality parameters used to bitmap the target */
507 buf_t qualified_by[BUFR_MAX_QUALITY_DATA]; /*!< array of indexes quality values related to target */
508 buf_t substituted; /*!< index of subsituted value related to target */
509 buf_t retained; /*!< Index of retained value related to target */
510 buf_t ns1; /*!< amount of first order statistical parameters used to bitmap the data */
511 buf_t stat1[BUFR_MAX_QUALITY_DATA]; /*!< Array of indexes of First-order statistical value related to target */
512 buf_t stat1_desc[BUFR_MAX_QUALITY_DATA]; /*!< Array of indexes which describes the First-order statistical parameter */
513 buf_t nds; /*!< Amount of difference statistical parameters related to target */
514 buf_t dstat[BUFR_MAX_QUALITY_DATA]; /*!< Attay of indexes of Difference statistical value related to target */
515 buf_t dstat_desc[BUFR_MAX_QUALITY_DATA]; /*!< Array of indexes which describes the diffenece statistical parameter related to target*/
516};
517
518
519/*!
520 \struct bufrdeco_decoding_data_state
521 \brief stores the state when expanding a sequence.
522*/
524{
525 buf_t subset; /*!< Subset sequence index being parsed */
526 buf_t bit_offset; /*!< First data bit offset of current since the begining of data in byte 4 in SEC 4 */
527 int8_t added_bit_length; /*!< Current aditional bit_length that can be changed by descriptor 2 01 YYY */
528 int8_t added_scale; /*!< Current aditional scale factor that can be changed by descriptor 2 02 YYY */
529 int32_t added_reference; /*!< Current aditional reference that can be changed bu descriptor 2 03 YYY */
530 int32_t factor_reference; /*!< Factor to multiply current reference if > 1 */
531 uint8_t assoc_bits; /*!< number of associated bits */
532 uint8_t changing_reference; /*!< Changing reference as descriptor 2 03 YYY */
533 uint8_t fixed_ccitt; /*!< Length in octests for a CCITT var. Changed with descriptor 2 08 YYY . default 0 (or 1)*/
534 uint8_t local_bit_reserved; /*!< bits reserved for the inmediately local descriptor */
535 uint8_t quality_active; /*!< If != 0 then all 33 class descriptros are refered to a defined bitmap */
536 uint8_t subs_active; /*!< If != 0 then Substituted operator values is active */
537 uint8_t retained_active; /*!< If != 0 then Replaced/retained operator values is active */
538 uint8_t stat1_active; /*!< If != 0 then firsr order statistical values follow */
539 uint8_t dstat_active; /*!< If != 0 then difference statistical value follow */
540 int32_t bitmaping; /*!< If != 0 then is the backard count reference defined by replicator descriptor after 2 36 000 operator */
541 buf_t data_repetition_factor; /*!< for descriptors 0 31 011 and 0 31 012. Active if != 0 */
542 struct bufrdeco_bitmap *bitmap; /*!< Pointer to an active bitmap. If not bitmap defined then is NULL */
543};
544
545/*!
546 * \struct bufr_sequence_index_range
547 * \brief range of indexes in a struct \ref bufr_sequence where a condition must me chequed or marked, as example no data present or event
548 */
550{
551 int active; /*!< if != 0 then the range of descriptors is active */
552 buf_t first; /*!< First index for a descriptor in a struct \ref bufr_sequence to be chequed */
553 buf_t last; /*!< Last index for a descriptor in a struct \ref bufr_sequence to be chequed */
554};
555
556/*!
557 \struct bufr_sequence
558 \brief Stores an unexpanded sequence of descriptors
559
560 A sequence layer is needed when parsing expanded descriptor sec3 and sec4
561
562 First bufr_sequence is the sequence of descriptors in sec3 after
563 byte 8. This is a bufr_sequence in level 0.
564
565 When a sequence descriptor is found in a layer, the sequence entries found in table D
566 form this descriptor is a son bufr_sequence. This son has then a father
567 and also can have one or more sons. The index level is incremented by one every step it
568 go into decendents.
569
570*/
572{
573 char key[8]; /*!< the key */
574 buf_t level; /*!< The recursion level. descriptors in sec3 are level 0 */
575 buf_t ndesc; /*!< Number of unexpanded descriptor of a layer */
576 struct bufr_sequence *father; /*!< Pointer to the father struct. It should be NULL if level = 0 */
577 buf_t father_idesc ; /*!< Index of a descriptor in father to which this sequence is expanded */
578 struct bufr_sequence_index_range no_data_present; /*!< struct \ref bufr_sequence_index_range with no data descriptor range */
579 struct bufr_sequence_index_range event; /*!< struct \ref bufr_sequence_index_range with an event range */
580 struct bufr_sequence_index_range cond_event; /*!< struct \ref bufr_sequence_index_range with a conditioning event range */
581 struct bufr_sequence_index_range cat_forecast; /*!< struct \ref bufr_sequence_index_range with a categorical forecasts range */
582 uint8_t replicated[NMAXSEQ_DESCRIPTORS]; /*! Array of recursion level of replication 0 = no replicated. N = level of rep */
583 struct bufr_descriptor lseq[NMAXSEQ_DESCRIPTORS]; /*!< Array of unexpanded descriptors */
584 struct bufr_sequence *sons[NMAXSEQ_DESCRIPTORS]; /*!< Array of pointers to sons. It must be NULL
585 except for sequence descriptors. */
586 buf_t iseq; /*!< number of sequence when parsing a tree. for recursion level 0 in sec3 is asigned 0.
587 Is the index in member seq in struct bufereco_expanded_tree */
588 char name[BUFR_EXPLAINED_LENGTH]; /*!< Name of sequence if any */
589};
590
591/*!
592 \struct bufrdeco_expanded_tree
593 \brief Array of structs \ref bufr_sequence from which bufr expanded tree is made.
594*/
596{
597 buf_t nseq; /*!< current number of structs used */
598 struct bufr_sequence seq[BUFR_MAX_EXPANDED_SEQUENCES]; /*!< array of structs */
599};
600
601/*!
602 * \def BUFRDECO_COMPRESSED_REF_SEQUENCE_INIT_BITMASK
603 * \brief Bitmask for struct \ref bufrdeco_compressed_ref which marks the init of a descriptor sequence
604 */
605#define BUFRDECO_COMPRESSED_REF_SEQUENCE_INIT_BITMASK (1)
606
607/*!
608 * \def BUFRDECO_COMPRESSED_REF_DATA_DESCRIPTOR_BITMASK
609 * \brief Bitmask for struct \ref bufrdeco_compressed_ref which marks a data descriptor
610 */
611#define BUFRDECO_COMPRESSED_REF_DATA_DESCRIPTOR_BITMASK (2)
612
613/*!
614 * \def BUFRDECO_COMPRESSED_REF_OPERATOR_DESCRIPTOR
615 * \brief Bitmask for struct \ref bufrdeco_compressed_ref which marks an operator descriptor
616 */
617#define BUFRDECO_COMPRESSED_REF_OPERATOR_DESCRIPTOR (4)
618
619/*!
620 * \def BUFRDECO_COMPRESSED_REF_REPLICATOR_DESCRIPTOR
621 * \brief Bitmask for struct \ref bufrdeco_compressed_ref which marks a replicator descriptor
622 */
623#define BUFRDECO_COMPRESSED_REF_REPLICATOR_DESCRIPTOR (8)
624
625/*!
626 * \def BUFRDECO_COMPRESSED_REF_SEQUENCE_FINAL_BITMASK
627 * \brief Bitmask for struct \ref bufrdeco_compressed_ref which marks the final of a descriptor sequence
628 */
629#define BUFRDECO_COMPRESSED_REF_SEQUENCE_FINAL_BITMASK (16)
630
631/*!
632 \struct bufrdeco_compressed_ref
633 \brief Struct to hold the needed reference bit offsets, descriptor tree and replications in a compressed BUFR
634
635 In a compressed bufr it is supossed that all subsets are coded under the same expanded tree, included the delayed descriptors.
636 So the length of data in every subset is the same. To access to a field data we would need these strutcs \ref bufrdeco_compressed_ref
637*/
639{
640 uint32_t mask; /*!< Bit mask */
641 uint8_t is_associated ; /*!< 0 if is not associated data */
642 uint8_t has_data ; /*!< 1 if has any subset with valid data. 0 if missing in all subsets */
643 uint8_t bits; /*!< bits for data or associated in table b */
644 uint8_t inc_bits; /*!< number of inc bits for every subset */
645 int32_t ref; /*!< reference for a expanded data in table b */
646 buf_t bit0; /*!< first bit offset, i.e, most significant bit for ref0 */
647 buf_t ref0; /*!< local reference for a expanded data in subsets */
648 char cref0[256]; /*!< Local reference in case of string */
649 int32_t escale; /*!< escale for a expanded data in subset */
650 char name[BUFR_TABLEB_NAME_LENGTH]; /*!< String with the name of descriptor */
651 char unit[BUFR_TABLEB_UNIT_LENGTH]; /*!< String with the name of units */
652 struct bufr_descriptor *desc; /*!< associated descriptor */
653 struct bufr_sequence *seq; /*!< associated sequence */
654 buf_t is_bitmaped_by; /*!< Index element in a struct \ref bufrdeco_compressed_data_references which bitmap this one */
655 buf_t bitmap_to; /*!< Index element in a struct \ref bufrdeco_compressed_data_references which this one is mapping to */
656 buf_t related_to; /*!< Index of element ina struct \ref bufrdeco_compressed_data_references which this one is related to */
657 buf_t replicated_desc; /*!< Index of a replicated descriptor in a replication interval at current level, first 1 */
658 buf_t replicated_loop; /*!< Index of loop of a replicated descriptor in replication interval at current level, first 1 */
659 buf_t replicated_ndesc; /*!< Amount of descriptors in a replication interval at current level */
660 buf_t replicated_nloop; /*!< Amount of loops in a replication interval at current level */
661};
662
663/*!
664 \struct bufrdeco_compressed_data_references
665 \brief Manage an array of structs \ref bufrdeco_compressed_ref
666*/
668{
669 buf_t dim; /*!< dimension of array of compressed refs */
670 buf_t nd; /*!< current amount of data used */
671 struct bufrdeco_compressed_ref *refs; /*!< pointer to allocated array */
672};
673
674/*!
675 * \struct bufrdeco_subset_bit_offsets
676 * \brief Array of offset in bits for every subset in a non-compressed bufr. Offset is counted in bits from the init of SEC4 data, usually bit 32.
677 *
678 * To set the offset for non compressed bufr it is neccesary to parse the expanded tree and extact the data of the prior subsets.
679 * If we already know the bit offset of the data then we can access directly to the subset data without parsing the prior subsets.
680 *
681 * The utility of these offset array is that it can be write to and read from a binary file and access quickly to the
682 * desired subset data.
683 */
685{
686 buf_t nr ; /*!< Current number of used subset bit offsets. */
687 buf_t ofs[BUFR_MAX_SUBSETS]; /*! Array of subset bitoffset. offsets[n] is the bit offset from first data in sequence 'n'.
688 Offset is counted from the begining of SEC4 data in bits, usually bit 32 */
689};
690
691/*!
692 \struct bufr_sec0
693 \brief Store de parsed section 0
694*/
696{
697 uint32_t bufr_length; /*!< Original Bufr file size in bytes */
698 uint8_t edition; /*!< bufr edition nuber */
699 uint8_t raw[8]; /*!< bytes as in the bufr message */
700};
701
702/*!
703 \struct gts_header
704 \brief stores WMO GTS header info
705*/
707{
708 char bname[16]; /*!< Name of bulletin, as 'SNAU48' */
709 char center[8]; /*!< Release center name, as 'EGRR' */
710 char dtrel[16]; /*!< Date and time of release (format DDHHmm) */
711 char order[8]; /*!< sequence, as 'BBB' , 'RRA' 'CCA' ... */
712 char filename[BUFRDECO_PATH_LENGTH]; /*!< filename of Bufr file */
713 char timestamp[16]; /*!< String with timestamp (UTC) of file in GTS. Format YYYYMMDDHHmmss */
714};
715
716
717/*!
718 \struct bufr_sec1
719 \brief Store de parsed section 1 of a bufr file
720
721 <pre>
722 This is for version 4 BUFR
723 Section 1 – Identification section
724 Octet No. Contents
725 1–3 Length of section
726 4 BUFR master table (zero if standard WMO FM 94 BUFR tables are used – see Note 2)
727 5–6 Identification of originating/generating centre (see Common Code table C-11)
728 7–8 Identification of originating/generating sub-centre (allocated by originating/generating centre
729 – see Common Code table C-12)
730 9 Update sequence number (zero for original messages and for messages containing only
731 delayed reports; incremented for the other updates)
732 10 Bit 1 = 0 No optional section
733 = 1 Optional section follows
734 Bits 2-8 Set to zero (reserved)
735 11 Data category (Table A)
736 12 International data sub-category (see Common Code table C-13 and Note 3)
737 13 Local data sub-category (defined locally by automatic data-processing (ADP) centres
738 14 Version number of master table
739 15 Version number of local tables used to augment master table in use
740 16–17 Year (4 digits)
741 18 Month
742 19 Day Most typical time for the BUFR message contents – see Note 4
743 20 Hour
744 21 Minute
745 22 Second
746 23–Optional – for local use by ADP centres
747
748 And this is for version 3
749 1–3 Length of section
750 4 BUFR master table (zero if standard WMO FM 94 BUFR tables are used – see Note 2)
751 5 Originating/generating sub-centre: Code table 0 01 034 (defined, if necessary, by associated
752 originating/generating centre – see Note 3 of Common Code table C–1 in Part C/c.)
753 6 Originating/generating centre: Code table 0 01 033 (Common Code table C–1 in Part C/c.)
754 7 Update sequence number (zero for original BUFR messages; incremented for updates)
755 8 Bit 1 = 0 No optional section
756 = 1 Optional section follows
757 Bits 2–8 Set to zero (reserved)
758 9 Data category (Table A)
759 10 Data sub-category (defined by local automatic data processing (ADP) centres)
760 11 Version number of master table used – see Notes 2 and 4
761 12 Version number of local tables used to augment the master table in use – see Note 2
762 13 Year of century
763 14 Month
764 15 Day Most typical for the BUFR message contents
765 16 Hour
766 17 Minute
767 18- If not required by ADP centres for local use, octet 18 only shall be included and set to zero with
768 reference to Regulation 94.1.3
769 </pre>
770*/
772{
773 uint32_t length; /*!< Length of section 1 */
774 uint8_t master; /*!< Bufr master table */
775 uint32_t centre; /*!< Centre */
776 uint32_t subcentre; /*!< sub-Centre */
777 uint8_t update; /*!< update sequence number */
778 uint8_t options; /*!< options */
779 uint8_t category; /*!< Data category (table A) */
780 uint8_t subcategory; /*!< subcategory */
781 uint8_t subcategory_local;/*!< local data subcategory */
782 uint8_t master_version; /*!< Version of master table */
783 uint8_t master_local; /*!< Version number of local tables used to augment master table in use */
784 uint32_t year; /*!< Year */
785 uint8_t month; /*!< Month */
786 uint8_t day; /*!< Day */
787 uint8_t hour; /*!< hour */
788 uint8_t minute; /*!< minute */
789 uint8_t second; /*!< second */
790 uint8_t raw[BUFR_LEN_SEC1]; /*!< Raw data for sec1 as is in original BUFR file */
791};
792
793/*!
794 \struct bufr_sec2
795 \brief Store a parsed sec2 from a bufr file including rawdata
796*/
798{
799 uint32_t length;
800 uint8_t raw[BUFR_LEN_SEC2]; /*!< Raw data for sec2 as is in original BUFR file */
801};
802
803/*!
804 \struct bufr_sec3
805 \brief Store a parsed sec3 from a bufr file including rawdata
806*/
808{
809 uint32_t length; /*!< length of sec3 in bytes */
810 uint32_t subsets; /*!< Number of data subsets */
811 uint8_t observed; /*!< 1 if observed */
812 uint8_t compressed; /*!< 1 if compressed */
813 uint32_t ndesc; /*!< Current number of unexpanded descriptors */
814 struct bufr_descriptor unexpanded[BUFR_LEN_UNEXPANDED_DESCRIPTOR]; /*!< Array of unexpanded descriptors */
815 uint8_t raw[BUFR_LEN_SEC3]; /*!< Raw data for sec3 as is in original BUFR file */
816};
817
818/*!
819 \struct bufr_sec4
820 \brief Store a parsed sec4 from a bufr file including rawdata
821
822 Note that member \a raw do not need to be allocated
823*/
825{
826 uint32_t length; /*!< length of sec4 in bytes */
827 size_t bit_offset; /*!< Offset to current first bit in raw data sec4 to parse */
828 uint8_t raw[BUFR_LEN]; /*!< Pointer to a raw data for sec4 as in original BUFR file */
829};
830
831/*!
832 \struct bufr_tableB_decoded_item
833 \brief Store parameters for a descriptor in table b, i. e. with f = 0
834*/
836{
837 uint8_t changed; /*!< flag. If 0 = not changed from table B. If 1 Changed */
838 uint8_t x; /*!< x value of descriptor */
839 uint8_t y; /*!< y value of descriptor */
840 uint8_t kk; /*!< not used. A trick to align */
841 char key[8]; /*!< c value of descriptor */
842 char name[BUFR_TABLEB_NAME_LENGTH]; /*!< name */
843 char unit[BUFR_TABLEB_UNIT_LENGTH]; /*!< unit */
844 int32_t scale; /*!< escale */
845 int32_t scale_ori; /*!< escale as readed from table b */
846 int32_t reference; /*!< reference */
847 int32_t reference_ori; /*!< reference as readed from table b */
848 buf_t nbits; /*!< bits */
849 buf_t nbits_ori; /*!< bits as readed from table b */
850 buf_t tableC_ref; /*!< item to point table c, if any */
851 buf_t tableD_ref; /*!< item to point table d, if any */
852};
853
854/*!
855 \struct bufr_tableB
856 \brief Store a table B readed from a file formated and named as ECMWF bufrdc package
857*/
859{
860 int wmo_table; /*!< 1 when table is from WMO csv file, 0 otherwise */
861 char path[BUFRDECO_PATH_LENGTH]; /*!< Complete path of current file readed */
862 char old_path[BUFRDECO_PATH_LENGTH]; /*!< Cmplete path of prior file readed, used to avoid read two consecutive times the same file */
863 buf_t nlines; /*!< Current lines readed from file, i. e. used in array item[] */
864 buf_t x_start[64]; /*!< Index in array \a item[] for first x. x_start[j] is index for first descriptor which x == j */
865 buf_t num[64]; /*!< Amount of items for x. num[i] is the amount of items in array where x = i */
866 uint8_t y_ref[64][256]; /*!< index for y since first x. x_ref[i][j] is index since x_start[i] where y == j */
867 struct bufr_tableB_decoded_item item[BUFR_MAXLINES_TABLEB]; /*!< Array with structs containing parsed lines readed from file */
868};
869
870
871/*!
872 \struct bufr_tableC_decoded_item
873 \brief Store parameters for a descriptor in table C, i. e. for Table code and flags
874 Remember this is NOT the C WMO tables
875*/
877{
878 char key[8]; /*!< c value of descriptor */
879 uint8_t x; /*!< x value of descriptor */
880 uint8_t y; /*!< y value of descriptor */
881 uint32_t ival; /*!< code value */
882 char description[BUFR_EXPLAINED_LENGTH]; /*!< Description string of code */
883};
884
885
886/*!
887 \struct bufr_tableC
888 \brief Store a table C readed from a file formated and named as ECMWF bufrdc package
889*/
891{
892 int wmo_table; /*!< 1 when table is from WMO csv file, 0 otherwise */
893 char path[BUFRDECO_PATH_LENGTH]; /*!< Complete path of current file readed */
894 char old_path[BUFRDECO_PATH_LENGTH]; /*!< Cmplete path of prior file readed, used to avoid read two consecutive times the same file */
895 buf_t nlines; /*!< Current lines readed from file, i. e. used in array \a l[] */
896 buf_t x_start[64]; /*!< Index in array \a l[] for first x. x_start[j] is index for first descriptor which x == j */
897 buf_t num[64]; /*!< Amonut of lines for x. num[i] is the amount of items in array where x = i */
898 buf_t y_ref[64][256]; /*!< index for first y since first x. x_ref[i][j] is index since x_start[i] where y == j */
899 struct bufr_tableC_decoded_item item[BUFR_MAXLINES_TABLEC]; /*!< Array of decoded lines */
900};
901
902
903/*!
904 \struct bufr_tableD_decoded_item
905 \brief Store parameters for a line in table D (sequence of descritors)
906*/
908{
909 char key[8]; /*!< c key value of sequence descriptor */
910 char key2[8]; /*!< c key 2 of sequence element */
911 char description[BUFR_EXPLAINED_LENGTH]; /*!< Explained name of sequence */
912 char description2[BUFR_EXPLAINED_LENGTH]; /*!< Explained name of elemet of sequence */
913};
914
915/*!
916 \struct bufr_tableD
917 \brief Store a table D readed from a file formated and named as ECMWF bufrdc package
918*/
920{
921 int wmo_table; /*!< 1 when table is from WMO csv file, 0 otherwise */
922 char path[BUFRDECO_PATH_LENGTH]; /*!< Complete path of current file readed */
923 char old_path[BUFRDECO_PATH_LENGTH]; /*!< Cmplete path of prior file readed, used to avoid read two consecutive times the same file */
924 buf_t nlines; /*!< Current lines readed from file, i. e. used in array \a l[] */
925 buf_t x_start[64]; /*!< Index in array \a l[] for first x. x_start[j] is index for first descriptor which x == j */
926 buf_t num[64]; /*!< Amonut of lines for x. num[i] is the amount of items in array where x = i */
927 char l[BUFR_MAXLINES_TABLED][24]; /*!< Array with info about descriptor sequences emulating ECMW tables D */
928 struct bufr_tableD_decoded_item item[BUFR_MAXLINES_TABLED]; /*!< Array of decoded lines */
929};
930
931/*!
932 \struct bufr_tables
933 \brief Contains all tables needed to parse a bufr file
934
935 All readed files need to be named an formed as ECMWF bufrdc package
936*/
938{
939 struct bufr_tableB b; /*!< Table B */
940 struct bufr_tableC c; /*!< Table C */
941 struct bufr_tableD d; /*!< Table D */
942};
943
944/*!
945 * \struct bufr_tables_cache
946 * \brief Struct to store the cache of structs \ref bufr_tables
947 *
948 * When used, the member \a tables in main struct \ref bufrdeco is pointing to one of the elements in member array \a tab
949 */
951{
952 buf_t nt; /*!< Tables actually allocated in cache */
953 buf_t next; /*< index of next element in array to add */
954 int8_t ver[BUFRDECO_TABLES_CACHE_SIZE]; /*!< Table version for array elements */
955 struct bufr_tables *tab[BUFRDECO_TABLES_CACHE_SIZE]; /*! Array of structs \ref bufr_tables allocated */
956};
957
958/*!
959 \struct bufrdeco
960 \brief This struct contains all needed data to parse and decode a BUFR file
961
962 NOTE that must be initializad before use
963*/
965{
966 uint32_t mask; /*!< Array of bit mask which set some runtime features of bufrdeco library */
967 struct gts_header header; /*!< GTS data */
968 struct bufr_sec0 sec0; /*!< Parsed sec0 */
969 struct bufr_sec1 sec1; /*!< Parsed sec1 */
970 struct bufr_sec2 sec2; /*!< Parsed sec2 */
971 struct bufr_sec3 sec3; /*!< Parsed sec3 */
972 struct bufr_sec4 sec4; /*!< Parsed sec4 */
973 struct bufr_tables *tables; /*!< Pointer to a the struct containing all tables needed for a single bufr */
974 struct bufr_tables_cache cache; /*!< Struct \ref bufr_tables_cache */
975 struct bufrdeco_expanded_tree *tree; /*!< Pointer to a struct containing the parsed descriptor tree (with explansion) */
976 struct bufrdeco_decoding_data_state state; /*!< Struct with data needed when parsing bufr */
977 struct bufrdeco_subset_bit_offsets offsets; /*!< Struct \ref bufrdeco_subset_bit_offsets with bit offset of start point of every subset in non compressed bufr */
978 struct bufrdeco_compressed_data_references refs; /*!< struct with data references in case of compressed bufr */
979 struct bufrdeco_subset_sequence_data seq; /*!< sequence with data subset after parse */
980 struct bufrdeco_bitmap_array bitmap; /*!< Stores data for bit-maps */
981 struct bufrdeco_bitmap_related_vars brv; /*!< Stores data related with the aid of a bit-maps */
982 char bufrtables_dir[BUFRDECO_PATH_LENGTH]; /*!< string with the path of bufr table directories */
983 char error[1024]; /*!< String with detected errors, if any */
984 FILE *out ; /*!< Stream used for normal output. By default 'stdout' */
985 FILE *err ; /*!< Stream used for error output. By default 'stderr' */
986};
987
988extern const char DEFAULT_BUFRTABLES_ECMWF_DIR1[];
989extern const char DEFAULT_BUFRTABLES_ECMWF_DIR2[];
990extern const char DEFAULT_BUFRTABLES_WMO_CSV_DIR1[];
991extern const char DEFAULT_BUFRTABLES_WMO_CSV_DIR2[];
992extern const double pow10pos[8];
993extern const double pow10neg[8];
994extern const int32_t pow10pos_int[10];
995
996/************ Main API functions **************/
997char *bufrdeco_get_version ( char *version, size_t dversion, char *build, size_t dbuild, char *builder, size_t dbuilder,
998 int *version_major, int *version_minor, int *version_patch );
999int bufrdeco_parse_tree ( struct bufrdeco *b );
1000int bufrdeco_init ( struct bufrdeco *b );
1001int bufrdeco_close ( struct bufrdeco *b );
1002int bufrdeco_reset ( struct bufrdeco *b );
1003int bufrdeco_set_tables_dir ( struct bufrdeco *b, char *tables_dir );
1004int bufrdeco_set_out_stream (FILE *out, struct bufrdeco *b);
1005int bufrdeco_set_err_stream (FILE *err, struct bufrdeco *b);
1006int bufrdeco_get_bufr ( struct bufrdeco *b, char *filename );
1008int bufrdeco_read_subset_offset_bits ( struct bufrdeco *b, char *filename );
1009int bufrdeco_write_subset_offset_bits ( struct bufrdeco *b, char *filename );
1010
1011
1012// Memory funcions
1015int bufrdeco_init_tables ( struct bufr_tables **t );
1016int bufrdeco_free_tables ( struct bufr_tables **t );
1017int bufrdeco_substitute_tables ( struct bufr_tables **replaced, struct bufr_tables *source, struct bufrdeco *b );
1024int bufrdeco_store_tables ( struct bufr_tables **t, struct bufr_tables_cache *c, uint8_t ver );
1025int bufrdeco_cache_tables_search ( struct bufr_tables_cache *c, uint8_t ver );
1027
1028// Read bufr functions
1029int bufrdeco_read_bufr ( struct bufrdeco *b, char *filename );
1030int bufrdeco_extract_bufr ( struct bufrdeco *b, char *filename );
1031int bufrdeco_read_buffer ( struct bufrdeco *b, uint8_t *bufrx, buf_t size );
1032
1033// Read bufr WMO csv table files
1034int get_wmo_tablenames ( struct bufrdeco *b );
1035int bufr_read_tableB ( struct bufrdeco *b );
1036int bufr_read_tableC ( struct bufrdeco *b );
1037int bufr_read_tableD ( struct bufrdeco *b );
1038int bufr_read_tables ( struct bufrdeco *b );
1039char * csv_quoted_string ( char *out, char *in );
1040int parse_csv_line ( int *nt, char *tk[], char *lin );
1041
1042
1043// Print and output functions
1048int print_sec0_info ( struct bufrdeco *b );
1049int print_sec1_info ( struct bufrdeco *b );
1050int print_sec3_info ( struct bufrdeco *b );
1051int print_sec4_info ( struct bufrdeco *b );
1052int sprint_sec0_info ( char *target, size_t lmax, struct bufrdeco *b );
1053int sprint_sec1_info ( char *target, size_t lmax, struct bufrdeco *b );
1054int sprint_sec3_info ( char *target, size_t lmax, struct bufrdeco *b );
1055int sprint_sec4_info ( char *target, size_t lmax, struct bufrdeco *b );
1056int sprint_sec0_info_html ( char *target, size_t lmax, struct bufrdeco *b );
1057int sprint_sec1_info_html ( char *target, size_t lmax, struct bufrdeco *b );
1058int sprint_sec3_info_html ( char *target, size_t lmax, struct bufrdeco *b );
1059int sprint_sec4_info_html ( char *target, size_t lmax, struct bufrdeco *b );
1060int bufrdeco_print_tree ( struct bufrdeco *b );
1061int bufrdeco_fprint_tree ( FILE *f, struct bufrdeco *b );
1063int bufrdeco_print_atom_data_file ( FILE *f, struct bufr_atom_data *a );
1070char * bufrdeco_print_atom_data ( char *target, size_t lmax, struct bufr_atom_data *a );
1071char * bufrdeco_print_atom_data_html ( char *target, size_t lmax, struct bufr_atom_data *a, uint32_t ss );
1072char * get_formatted_value_from_escale ( char *fmt, size_t dim, int32_t escale, double val );
1073char * get_formatted_value_from_escale2 ( char *fmt, size_t dim, int32_t escale, double val );
1074
1075// To parse. General
1076int bufrdeco_parse_tree_recursive ( struct bufrdeco *b, struct bufr_sequence *father, buf_t father_idesc, const char *key );
1077int bufrdeco_decode_data_subset ( struct bufrdeco *b );
1081
1082// To parse compressed bufr
1086 struct bufrdeco *b );
1088 struct bufrdeco *b );
1090int bufrdeco_tableB_compressed ( struct bufrdeco_compressed_ref *r, struct bufrdeco *b, struct bufr_descriptor *d, int mode );
1092 buf_t subset, struct bufrdeco *b );
1094
1095// To get parsed data
1097
1098// To parse and print data and tree in json format
1099buf_t bufrdeco_print_json_sec0 ( FILE *out, struct bufrdeco *b );
1100buf_t bufrdeco_print_json_sec1 ( FILE *out, struct bufrdeco *b );
1101buf_t bufrdeco_print_json_sec2 ( FILE *out, struct bufrdeco *b );
1102buf_t bufrdeco_print_json_sec3 ( FILE *out, struct bufrdeco *b );
1104buf_t bufrdeco_print_json_tree_recursive ( FILE *out, struct bufrdeco *b, struct bufr_sequence *seq );
1107buf_t bufrdeco_print_json_object_atom_data (FILE *out, struct bufr_atom_data *a, char *aux );
1113buf_t bufrdeco_print_json_scape_string_cvals( FILE *out, char *source);
1116
1117
1118// Functions to get bits of data
1119uint32_t two_bytes_to_uint32 ( const uint8_t *source );
1120uint32_t three_bytes_to_uint32 ( const uint8_t *source );
1121uint32_t get_bits_as_uint32_t ( uint32_t *target, uint8_t *has_data, uint8_t *source, buf_t *bit0_offset,
1122 buf_t bit_length );
1123uint32_t get_bits_as_char_array ( char *target, uint8_t *has_data, uint8_t *source, buf_t *bit0_offset,
1124 buf_t bit_length );
1125
1126// Utilities for tables
1127char * bufrdeco_explained_table_val ( char *expl, size_t dim, struct bufr_tableC *tc, uint32_t *index,
1128 struct bufr_descriptor *d, uint32_t ival );
1129char * bufrdeco_explained_flag_val ( char *expl, size_t dim, struct bufr_tableC *tc, struct bufr_descriptor *d,
1130 uint64_t ival, uint8_t nbits );
1131char * bufrdeco_explained_table_csv_val ( char *expl, size_t dim, struct bufr_tableC *tc, uint32_t *index,
1132 struct bufr_descriptor *d, uint32_t ival );
1133char * bufrdeco_explained_flag_csv_val ( char *expl, size_t dim, struct bufr_tableC *tc, struct bufr_descriptor *d,
1134 uint64_t ival, uint8_t nbits );
1136 const char *key );
1137int bufrdeco_tableB_val ( struct bufr_atom_data *a, struct bufrdeco *b, struct bufr_descriptor *d );
1138int bufr_find_tableB_index ( buf_t *index, struct bufr_tableB *tb, const char *key );
1139int get_table_b_reference_from_uint32_t ( int32_t *target, uint8_t bits, uint32_t source );
1140int bufrdeco_tableD_get_descriptors_array ( struct bufr_sequence *s, struct bufrdeco *b, const char *key );
1141int bufr_find_tableC_csv_index ( buf_t *index, struct bufr_tableC *tc, const char *key, uint32_t code );
1142char *bufrdeco_get_f2_descriptor_explanation ( char *e, size_t dim, struct bufr_descriptor *d );
1143
1144// utilities for bitmaps
1145int bufrdeco_allocate_bitmap ( struct bufrdeco *b );
1146int bufrdeco_clean_bitmaps ( struct bufrdeco *b );
1148int bufrdeco_add_to_bitmap ( struct bufrdeco_bitmap *bm, buf_t index_to, buf_t index_by );
1149
1150// utilities for descriptors
1151int two_bytes_to_descriptor ( struct bufr_descriptor *d, const uint8_t *source );
1152int uint32_t_to_descriptor ( struct bufr_descriptor *d, uint32_t id );
1154int is_a_local_descriptor ( struct bufr_descriptor *d );
1156
1157// Utilities for strings
1158char * bufr_adjust_string ( char *s );
1159char * bufr_charray_to_string ( char *s, char *buf, size_t size );
1160
1161// I/O of bit offset for subsets
1164
1165#endif // from ifndef BUFRDECO_H
buf_t bufrdeco_print_json_subset_data_prologue(FILE *out, struct bufrdeco *b)
Definition: bufrdeco_json.c:58
buf_t bufrdeco_print_json_sec2(FILE *out, struct bufrdeco *b)
Print info form optional sec 2 in json format.
int bufrdeco_init_tables(struct bufr_tables **t)
Init a struct bufr_tables allocating space.
int bufrdeco_fprint_subset_sequence_data(FILE *f, struct bufrdeco_subset_sequence_data *s)
uint32_t buf_t
Type to set offsets and dimension of arrays or counters used in bufrdeco.
Definition: bufrdeco.h:346
uint32_t two_bytes_to_uint32(const uint8_t *source)
returns the uint32_t value from an array of two bytes, most significant first
struct bufrdeco_subset_sequence_data * bufrdeco_get_subset_sequence_data(struct bufrdeco *b)
Parse and get a struct bufrdeco_subset_sequence_data.
Definition: bufrdeco_data.c:39
int bufrdeco_clean_bitmaps(struct bufrdeco *b)
Clean all allocated bitmaps, but still is in memory.
int bufrdeco_init_subset_sequence_data(struct bufrdeco_subset_sequence_data *ba)
Init a struct bufrdeco_subset_sequence_data.
int bufrdeco_decode_replicated_subsequence_compressed(struct bufrdeco_compressed_data_references *r, struct bufr_replicator *rep, struct bufrdeco *b)
decodes a repicated subsequence
int bufrdeco_free_subset_sequence_data(struct bufrdeco_subset_sequence_data *ba)
Free the memory for sequence array in a struct bufrdeco_subset_sequence_data.
buf_t bufrdeco_print_json_separator(FILE *out)
Print the comma ',' separator in an output.
uint32_t three_bytes_to_uint32(const uint8_t *source)
returns the uint32_t value from an array of three bytes, most significant first
#define BUFR_EXPLAINED_LENGTH
Maximum length for a explained descriptor string.
Definition: bufrdeco.h:122
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....
int bufrdeco_init_expanded_tree(struct bufrdeco_expanded_tree **t)
Init a struct bufrdeco_expanded_tree allocating space.
int fprint_bufrdeco_compressed_ref(FILE *f, struct bufrdeco_compressed_ref *r)
prints a struct bufrdeco_compressed_ref
int uint32_t_to_descriptor(struct bufr_descriptor *d, uint32_t id)
parse an integer with a descriptor fom bufr ECWMF libary
int bufr_read_tableC(struct bufrdeco *b)
Reads a file with table C content (Code table and bit flags) according with csv WMO format.
int is_a_local_descriptor(struct bufr_descriptor *d)
check if a descriptor is a local descriptor
const char DEFAULT_BUFRTABLES_WMO_CSV_DIR2[]
Definition: bufrdeco_wmo.c:30
int bufrdeco_print_subset_sequence_data(struct bufrdeco_subset_sequence_data *s)
Prints a struct bufrdeco_subset_sequence_data.
const double pow10pos[8]
char * bufrdeco_explained_table_val(char *expl, size_t dim, struct bufr_tableC *tc, uint32_t *index, struct bufr_descriptor *d, uint32_t ival)
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_CVAL_LENGTH
Max length (in chars) of a cval in a bufr_atom_data.
Definition: bufrdeco.h:329
int bufrdeco_free_tables(struct bufr_tables **t)
Frees the allocated space for a struct bufr_tables.
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.
int bufrdeco_parse_f2_descriptor(struct bufrdeco_subset_sequence_data *s, struct bufr_descriptor *d, struct bufrdeco *b)
parse a descritor with f = 2
Definition: bufrdeco_f2.c:39
int bufrdeco_reset(struct bufrdeco *b)
Reset an struct bufrdeco. This is needed when changing to another bufr.
Definition: bufrdeco.c:180
int32_t ibuf_t
Type to set offsets and dimension of arrays or counters used in bufrdeco.
Definition: bufrdeco.h:351
int sprint_sec0_info_html(char *target, size_t lmax, struct bufrdeco *b)
Prints info from sec0 in html format.
#define BUFRDECO_TABLES_CACHE_SIZE
Max number of structs bufr_tables in a bufr_tables_cache.
Definition: bufrdeco.h:341
buf_t bufrdeco_print_json_object_operator_descriptor(FILE *out, struct bufr_descriptor *d, char *aux)
print an operator desciptor as a json object
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.
int bufrdeco_allocate_bitmap(struct bufrdeco *b)
allocate bitmap
int sprint_sec4_info(char *target, size_t lmax, struct bufrdeco *b)
Prints info from sec4.
const char DEFAULT_BUFRTABLES_ECMWF_DIR2[]
#define BUFR_MAXLINES_TABLEB
The maximum expected lines in a Table B file.
Definition: bufrdeco.h:90
int sprint_sec3_info(char *target, size_t lmax, struct bufrdeco *b)
Prints info from sec3.
#define BUFR_MAX_QUALITY_DATA
Max amount of quality data which is maped by a struct bufrdeco_bitmap element.
Definition: bufrdeco.h:226
uint32_t get_bits_as_char_array(char *target, uint8_t *has_data, uint8_t *source, buf_t *bit0_offset, buf_t bit_length)
int bufrdeco_get_bufr(struct bufrdeco *b, char *filename)
Read file and try to find a bufr report inserted in. Once found do the same that bufrdeco_read_bufr()
Definition: bufrdeco.c:315
int bufrdeco_read_buffer(struct bufrdeco *b, uint8_t *bufrx, buf_t size)
int fprint_bufrdeco_compressed_data_references(FILE *f, struct bufrdeco_compressed_data_references *r)
int print_bufrdeco_compressed_ref(struct bufrdeco_compressed_ref *r)
prints a struct bufrdeco_compressed_ref
char * bufr_charray_to_string(char *s, char *buf, size_t size)
get a null termitated c-string from an array of unsigned chars
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
int bufr_read_tableD(struct bufrdeco *b)
Reads a file with table D content according with WMO csv format.
int sprint_sec1_info_html(char *target, size_t lmax, struct bufrdeco *b)
Prints info from sec1.
buf_t bufrdeco_print_json_sequence_descriptor_final(FILE *out)
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 BUFR_MAXLINES_TABLEC
The maximum expected lines in a Table C file.
Definition: bufrdeco.h:96
buf_t bufrdeco_print_json_object_replicator_descriptor(FILE *out, struct bufr_descriptor *d, char *aux)
print an operator desciptor as a json object
int bufrdeco_set_out_stream(FILE *out, struct bufrdeco *b)
Set the library normal output stream.
Definition: bufrdeco.c:227
#define BUFR_MAX_EXPANDED_SEQUENCES
Max amount of unexpanded sequences in a struct bufrdeco_expanded_tree.
Definition: bufrdeco.h:220
int bufrdeco_free_cache_tables(struct bufr_tables_cache *c)
deallocate and clean a bufr_tables_cache
Definition: bufrdeco_wmo.c:322
int bufrdeco_get_atom_data_from_compressed_data_ref(struct bufr_atom_data *a, struct bufrdeco_compressed_ref *r, buf_t subset, struct bufrdeco *b)
Get atom data from a descriptor for a given subset.
buf_t bufrdeco_print_json_tree(struct bufrdeco *b)
#define BUFR_LEN_SEC3
Max length in bytes for a sec3.
Definition: bufrdeco.h:250
int bufrdeco_free_bitmap_array(struct bufrdeco_bitmap_array *a)
Free an allocated bitmap array.
char * bufrdeco_explained_table_csv_val(char *expl, size_t dim, struct bufr_tableC *tc, uint32_t *index, struct bufr_descriptor *d, uint32_t ival)
int sprint_sec1_info(char *target, size_t lmax, struct bufrdeco *b)
Prints info from sec1.
buf_t bufrdeco_print_json_sec0(FILE *out, struct bufrdeco *b)
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.
int bufrdeco_init_compressed_data_references(struct bufrdeco_compressed_data_references *rf)
Init a struct bufrdeco_compressed_data_references.
int bufr_read_tables(struct bufrdeco *b)
Read the tables according with bufr file data from a bufr table directory.
Definition: bufrdeco_wmo.c:162
int print_sec0_info(struct bufrdeco *b)
Prints info from sec0.
int bufrdeco_print_atom_data_stdout(struct bufr_atom_data *a)
print the data in a struct bufr_atom_data to stdout
int bufrdeco_set_tables_dir(struct bufrdeco *b, char *tables_dir)
Sets the directory path for BUFR tables. Needed if it is not any default directories.
Definition: bufrdeco.c:291
int print_bufrdeco_compressed_data_references(struct bufrdeco_compressed_data_references *r)
prints a struct bufrdeco_compressed_references
int bufrdeco_parse_tree_recursive(struct bufrdeco *b, struct bufr_sequence *father, buf_t father_idesc, const char *key)
Parse the descriptor tree in a recursive way.
Definition: bufrdeco_tree.c:60
buf_t bufrdeco_print_json_sequence_descriptor_header(FILE *out, struct bufr_sequence *seq)
Print the header of a sequence descriptor (f == 3)
Definition: bufrdeco_json.c:94
int get_wmo_tablenames(struct bufrdeco *b)
Get the complete pathnames for WMO csv table files needed by a bufr message.
Definition: bufrdeco_wmo.c:47
int sprint_sec0_info(char *target, size_t lmax, struct bufrdeco *b)
Prints info from sec0.
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
int bufrdeco_fprint_subset_sequence_data_html(FILE *f, struct bufrdeco_subset_sequence_data *s)
#define BUFRDECO_PATH_LENGTH
Length for files/directory path strings.
Definition: bufrdeco.h:335
int bufrdeco_close(struct bufrdeco *b)
Free all allocated memory. Needed when no more task to do with bufrdeco library.
Definition: bufrdeco.c:259
int sprint_sec4_info_html(char *target, size_t lmax, struct bufrdeco *b)
Prints info from sec4.
int bufrdeco_substitute_tables(struct bufr_tables **replaced, struct bufr_tables *source, struct bufrdeco *b)
substitute an struct bufr_tables into a struct bufrdeco
#define BUFR_MAX_BITMAPS
Max number of structs bufrdeco_bitmap that can be allocated in a struct bufrdeco_bitmap_array.
Definition: bufrdeco.h:238
char * bufrdeco_explained_flag_csv_val(char *expl, size_t dim, struct bufr_tableC *tc, struct bufr_descriptor *d, uint64_t ival, uint8_t nbits)
int bufrdeco_set_err_stream(FILE *err, struct bufrdeco *b)
Set the error stream.
Definition: bufrdeco.c:242
int parse_csv_line(int *nt, char *tk[], char *lin)
Parse a csv line.
Definition: bufrdeco_csv.c:258
int bufrdeco_parse_f2_compressed(struct bufrdeco_compressed_data_references *r, struct bufr_descriptor *d, struct bufrdeco *b)
parse a descritor with f = 2 in case of compressed bufr
Definition: bufrdeco_f2.c:406
char * bufrdeco_print_atom_data_html(char *target, size_t lmax, struct bufr_atom_data *a, uint32_t ss)
print the data in a struct bufr_atom_data to a string as cells of table rows
int bufrdeco_store_tables(struct bufr_tables **t, struct bufr_tables_cache *c, uint8_t ver)
Init an element of array c->tab[] if still not allocated. If allocated clean it and set *t pointing t...
Definition: bufrdeco_wmo.c:269
char * csv_quoted_string(char *out, char *in)
Transform a string to a quoted string to be inserted in a csv file.
Definition: bufrdeco_csv.c:48
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
char * bufrdeco_get_version(char *version, size_t dversion, char *build, size_t dbuild, char *builder, size_t dbuilder, int *version_major, int *version_minor, int *version_patch)
Definition: bufrdeco.c:50
#define BUFR_LEN_SEC1
Max length in bytes for a sec1.
Definition: bufrdeco.h:200
#define BUFR_LEN_UNEXPANDED_DESCRIPTOR
Max amount of unexpanded descriptors in a SEC3.
Definition: bufrdeco.h:213
#define BUFR_MAX_BITMAP_PRESENT_DATA
Max number of data present in a bitmap definition.
Definition: bufrdeco.h:232
buf_t bufrdeco_print_json_sec3(FILE *out, struct bufrdeco *b)
Print info form sec 3 in json format.
const char DEFAULT_BUFRTABLES_WMO_CSV_DIR1[]
Definition: bufrdeco_wmo.c:29
#define BUFR_MAX_SUBSETS
Max number of subsets in the array off bitoffset subset marks the bufrdeco library can manage.
Definition: bufrdeco.h:244
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 bufrdeco_increase_data_array(struct bufrdeco_subset_sequence_data *s)
doubles the allocated space for a struct bufrdeco_subset_sequence_data whenever is posible
buf_t bufrdeco_print_json_subset_data_epilogue(FILE *out)
Definition: bufrdeco_json.c:77
int bufrdeco_free_expanded_tree(struct bufrdeco_expanded_tree **t)
Frees the allocated space for a struct bufrdeco_expanded_tree.
#define BUFR_TABLEB_UNIT_LENGTH
Definition: bufrdeco.h:323
int bufrdeco_fprint_tree(FILE *f, struct bufrdeco *b)
Print a tree of descriptors.
int print_sec3_info(struct bufrdeco *b)
Prints info from sec3.
#define BUFR_MAXLINES_TABLED
The maximum expected lines in a Table D file.
Definition: bufrdeco.h:103
int bufr_find_tableC_csv_index(buf_t *index, struct bufr_tableC *tc, const char *key, uint32_t code)
int bufrdeco_parse_compressed(struct bufrdeco_compressed_data_references *r, struct bufrdeco *b)
Preliminary parse of a compressed data bufr.
const char DEFAULT_BUFRTABLES_ECMWF_DIR1[]
int is_a_delayed_descriptor(struct bufr_descriptor *d)
check if a descriptor is a delayed descriptor
int bufrdeco_parse_compressed_recursive(struct bufrdeco_compressed_data_references *r, struct bufr_sequence *l, struct bufrdeco *b)
Parse recursively the compressed data in a bufr report to get references where to get data for every ...
char * bufrdeco_print_atom_data(char *target, size_t lmax, struct bufr_atom_data *a)
print the data in a struct bufr_atom_data to a string
int bufrdeco_clean_subset_sequence_data(struct bufrdeco_subset_sequence_data *ba)
Cleans a struct bufrdeco_subset_sequence_data.
int bufrdeco_increase_compressed_data_references_count(struct bufrdeco_compressed_data_references *r, struct bufrdeco *b)
Increment the count of a struct bufrdeco_compressed_data_references.
int sprint_sec3_info_html(char *target, size_t lmax, struct bufrdeco *b)
Prints info from sec3 formatted as html.
int bufrdeco_cache_tables_search(struct bufr_tables_cache *c, uint8_t ver)
Search a struct bufr_tables in bufr_tables_cache.
Definition: bufrdeco_wmo.c:304
int bufrdeco_print_subset_sequence_data_tagged_html(struct bufrdeco_subset_sequence_data *s, char *id)
int bufrdeco_tableB_val(struct bufr_atom_data *a, struct bufrdeco *b, struct bufr_descriptor *d)
Get data from a table B descriptor.
#define BUFR_LEN
Max length of a BUFR file.
Definition: bufrdeco.h:60
const int32_t pow10pos_int[10]
int bufr_decode_subset_data_compressed(struct bufrdeco_subset_sequence_data *s, struct bufrdeco_compressed_data_references *r, struct bufrdeco *b)
Get data for a given subset in a compressed data bufr.
int bufrdeco_extract_bufr(struct bufrdeco *b, char *filename)
Read file and try to find a bufr report inserted in. Once found do the same that bufrdeco_read_file()
#define BUFR_TABLEB_NAME_LENGTH
Max length (in chars) reserved for a name of variable in table B.
buf_t bufrdeco_print_json_object_atom_data(FILE *out, struct bufr_atom_data *a, char *aux)
Print an json object with a descriptor data.
#define NMAXSEQ_DESCRIPTORS
Maximum nuber of unexpanded descriptors in a struct bufr_sequence.
Definition: bufrdeco.h:134
int bufrdeco_decode_subset_data_recursive(struct bufrdeco_subset_sequence_data *d, struct bufr_sequence *l, struct bufrdeco *b)
decode the data from a subset in a recursive way
const double pow10neg[8]
int bufrdeco_print_tree(struct bufrdeco *b)
Print a tree of descriptors.
buf_t bufrdeco_print_json_scape_string_cvals(FILE *out, char *source)
prints a descriptor string value scaping the '"' for a json format
Definition: bufrdeco_json.c:33
int bufrdeco_free_compressed_data_references(struct bufrdeco_compressed_data_references *rf)
Free the memory allocated for array of references in a struct bufrdeco_compressed_data_references.
int bufrdeco_decode_replicated_subsequence(struct bufrdeco_subset_sequence_data *d, struct bufr_replicator *r, struct bufrdeco *b)
Decodes a replicated sequence.
int bufrdeco_write_subset_offset_bits(struct bufrdeco *b, char *filename)
Write offset bit array for subsets in a non-compressed bufr.
Definition: bufrdeco.c:330
buf_t bufrdeco_print_json_sec1(FILE *out, struct bufrdeco *b)
Print info form sec 1 in json format.
int bufrdeco_parse_tree(struct bufrdeco *b)
Parse the tree of descriptors without expand the replicators.
Definition: bufrdeco.c:120
int bufrdeco_read_subset_offset_bits(struct bufrdeco *b, char *filename)
Write offset bit array for subsets in a non-compressed bufr.
Definition: bufrdeco.c:358
int bufr_read_tableB(struct bufrdeco *b)
char * bufr_adjust_string(char *s)
Supress trailing blanks of a string.
int print_sec4_info(struct bufrdeco *b)
Prints info from sec3.
int bufrdeco_decode_data_subset(struct bufrdeco *b)
User interface to decode a BUFR subset.
Definition: bufrdeco_data.c:62
int bufrdeco_read_bufr(struct bufrdeco *b, char *filename)
Read bufr file and does preliminary and first decode pass.
Definition: bufrdeco_read.c:41
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
int bufrdeco_print_atom_data_file(FILE *f, struct bufr_atom_data *a)
print the data in a struct bufr_atom_data to a file already open by caller
struct bufrdeco_subset_sequence_data * bufrdeco_get_target_subset_sequence_data(buf_t nset, struct bufrdeco *b)
Prepare the struct bufrdeco to get data from the solicited subset.
Definition: bufrdeco.c:396
int is_a_short_delayed_descriptor(struct bufr_descriptor *d)
check if a descriptor is a short delayed descriptor
int bufrdeco_print_subset_sequence_data_html(struct bufrdeco_subset_sequence_data *s)
char * bufrdeco_get_f2_descriptor_explanation(char *e, size_t dim, struct bufr_descriptor *d)
Definition: bufrdeco_f2.c:773
int bufrdeco_tableD_get_descriptors_array(struct bufr_sequence *s, struct bufrdeco *b, const char *key)
get the descriptors array for a descriptor sequence defined in table D with F = 3
#define BUFR_LEN_SEC2
Max length in bytes for a sec2.
Definition: bufrdeco.h:206
int bufrdeco_init(struct bufrdeco *b)
Inits and allocate memory for a struct bufrdeco.
Definition: bufrdeco.c:138
int print_sec1_info(struct bufrdeco *b)
Prints info from sec1.
buf_t bufrdeco_print_json_tree_recursive(FILE *out, struct bufrdeco *b, struct bufr_sequence *seq)
Print a tree of descriptors to a file in a recursive way in json format.
int bufrdeco_fprint_subset_sequence_data_tagged_html(FILE *f, struct bufrdeco_subset_sequence_data *s, char *id)
Contains all the information for a single data related with a descriptor in a expanded squence.
Definition: bufrdeco.h:435
int32_t escale
Definition: bufrdeco.h:441
uint32_t mask
Definition: bufrdeco.h:437
char name[BUFR_TABLEB_NAME_LENGTH]
Definition: bufrdeco.h:438
char ctable[BUFR_EXPLAINED_LENGTH]
Definition: bufrdeco.h:444
struct bufr_descriptor desc
Definition: bufrdeco.h:436
buf_t related_to
Definition: bufrdeco.h:449
double val
Definition: bufrdeco.h:440
buf_t is_bitmaped_by
Definition: bufrdeco.h:447
uint32_t associated
Definition: bufrdeco.h:442
char unit[BUFR_TABLEB_UNIT_LENGTH]
Definition: bufrdeco.h:439
char cval[BUFR_CVAL_LENGTH]
Definition: bufrdeco.h:443
struct bufr_sequence * seq
Definition: bufrdeco.h:445
buf_t bitmap_to
Definition: bufrdeco.h:448
BUFR descriptor.
Definition: bufrdeco.h:409
char c[12]
Definition: bufrdeco.h:414
uint8_t foo
Definition: bufrdeco.h:413
store the information when parsing related to replicators
Definition: bufrdeco.h:422
struct bufr_sequence * s
Definition: bufrdeco.h:423
Store de parsed section 0.
Definition: bufrdeco.h:696
uint8_t raw[8]
Definition: bufrdeco.h:699
uint8_t edition
Definition: bufrdeco.h:698
uint32_t bufr_length
Definition: bufrdeco.h:697
Store de parsed section 1 of a bufr file.
Definition: bufrdeco.h:772
uint8_t month
Definition: bufrdeco.h:785
uint32_t year
Definition: bufrdeco.h:784
uint8_t master_local
Definition: bufrdeco.h:783
uint32_t subcentre
Definition: bufrdeco.h:776
uint32_t centre
Definition: bufrdeco.h:775
uint8_t category
Definition: bufrdeco.h:779
uint8_t options
Definition: bufrdeco.h:778
uint8_t minute
Definition: bufrdeco.h:788
uint8_t subcategory
Definition: bufrdeco.h:780
uint8_t master_version
Definition: bufrdeco.h:782
uint8_t second
Definition: bufrdeco.h:789
uint8_t day
Definition: bufrdeco.h:786
uint32_t length
Definition: bufrdeco.h:773
uint8_t subcategory_local
Definition: bufrdeco.h:781
uint8_t raw[BUFR_LEN_SEC1]
Definition: bufrdeco.h:790
uint8_t hour
Definition: bufrdeco.h:787
uint8_t update
Definition: bufrdeco.h:777
uint8_t master
Definition: bufrdeco.h:774
Store a parsed sec2 from a bufr file including rawdata.
Definition: bufrdeco.h:798
uint32_t length
Definition: bufrdeco.h:799
uint8_t raw[BUFR_LEN_SEC2]
Definition: bufrdeco.h:800
Store a parsed sec3 from a bufr file including rawdata.
Definition: bufrdeco.h:808
uint8_t observed
Definition: bufrdeco.h:811
uint8_t compressed
Definition: bufrdeco.h:812
struct bufr_descriptor unexpanded[BUFR_LEN_UNEXPANDED_DESCRIPTOR]
Definition: bufrdeco.h:814
uint32_t ndesc
Definition: bufrdeco.h:813
uint32_t length
Definition: bufrdeco.h:809
uint32_t subsets
Definition: bufrdeco.h:810
uint8_t raw[BUFR_LEN_SEC3]
Definition: bufrdeco.h:815
Store a parsed sec4 from a bufr file including rawdata.
Definition: bufrdeco.h:825
uint32_t length
Definition: bufrdeco.h:826
uint8_t raw[BUFR_LEN]
Definition: bufrdeco.h:828
size_t bit_offset
Definition: bufrdeco.h:827
range of indexes in a struct bufr_sequence where a condition must me chequed or marked,...
Definition: bufrdeco.h:550
Stores an unexpanded sequence of descriptors.
Definition: bufrdeco.h:572
struct bufr_sequence_index_range cond_event
Definition: bufrdeco.h:580
struct bufr_descriptor lseq[NMAXSEQ_DESCRIPTORS]
Definition: bufrdeco.h:583
struct bufr_sequence_index_range no_data_present
Definition: bufrdeco.h:578
struct bufr_sequence * father
Definition: bufrdeco.h:576
buf_t ndesc
Definition: bufrdeco.h:575
buf_t father_idesc
Definition: bufrdeco.h:577
struct bufr_sequence_index_range event
Definition: bufrdeco.h:579
char key[8]
Definition: bufrdeco.h:573
uint8_t replicated[NMAXSEQ_DESCRIPTORS]
Definition: bufrdeco.h:582
buf_t iseq
Definition: bufrdeco.h:586
buf_t level
Definition: bufrdeco.h:574
struct bufr_sequence * sons[NMAXSEQ_DESCRIPTORS]
Definition: bufrdeco.h:584
struct bufr_sequence_index_range cat_forecast
Definition: bufrdeco.h:581
char name[BUFR_EXPLAINED_LENGTH]
Definition: bufrdeco.h:588
Store parameters for a descriptor in table b, i. e. with f = 0.
Definition: bufrdeco.h:836
char unit[BUFR_TABLEB_UNIT_LENGTH]
Definition: bufrdeco.h:843
char name[BUFR_TABLEB_NAME_LENGTH]
Definition: bufrdeco.h:842
Store a table B readed from a file formated and named as ECMWF bufrdc package.
Definition: bufrdeco.h:859
uint8_t y_ref[64][256]
Definition: bufrdeco.h:866
struct bufr_tableB_decoded_item item[BUFR_MAXLINES_TABLEB]
Definition: bufrdeco.h:867
buf_t nlines
Definition: bufrdeco.h:863
buf_t num[64]
Definition: bufrdeco.h:865
buf_t x_start[64]
Definition: bufrdeco.h:864
char old_path[BUFRDECO_PATH_LENGTH]
Definition: bufrdeco.h:862
int wmo_table
Definition: bufrdeco.h:860
char path[BUFRDECO_PATH_LENGTH]
Definition: bufrdeco.h:861
Store parameters for a descriptor in table C, i. e. for Table code and flags Remember this is NOT the...
Definition: bufrdeco.h:877
char description[BUFR_EXPLAINED_LENGTH]
Definition: bufrdeco.h:882
Store a table C readed from a file formated and named as ECMWF bufrdc package.
Definition: bufrdeco.h:891
int wmo_table
Definition: bufrdeco.h:892
buf_t num[64]
Definition: bufrdeco.h:897
struct bufr_tableC_decoded_item item[BUFR_MAXLINES_TABLEC]
Definition: bufrdeco.h:899
char path[BUFRDECO_PATH_LENGTH]
Definition: bufrdeco.h:893
buf_t x_start[64]
Definition: bufrdeco.h:896
buf_t nlines
Definition: bufrdeco.h:895
char old_path[BUFRDECO_PATH_LENGTH]
Definition: bufrdeco.h:894
buf_t y_ref[64][256]
Definition: bufrdeco.h:898
Store parameters for a line in table D (sequence of descritors)
Definition: bufrdeco.h:908
char description2[BUFR_EXPLAINED_LENGTH]
Definition: bufrdeco.h:912
char description[BUFR_EXPLAINED_LENGTH]
Definition: bufrdeco.h:911
Store a table D readed from a file formated and named as ECMWF bufrdc package.
Definition: bufrdeco.h:920
char l[BUFR_MAXLINES_TABLED][24]
Definition: bufrdeco.h:927
int wmo_table
Definition: bufrdeco.h:921
buf_t nlines
Definition: bufrdeco.h:924
char path[BUFRDECO_PATH_LENGTH]
Definition: bufrdeco.h:922
buf_t x_start[64]
Definition: bufrdeco.h:925
char old_path[BUFRDECO_PATH_LENGTH]
Definition: bufrdeco.h:923
struct bufr_tableD_decoded_item item[BUFR_MAXLINES_TABLED]
Definition: bufrdeco.h:928
buf_t num[64]
Definition: bufrdeco.h:926
Struct to store the cache of structs bufr_tables.
Definition: bufrdeco.h:951
int8_t ver[BUFRDECO_TABLES_CACHE_SIZE]
Definition: bufrdeco.h:954
struct bufr_tables * tab[BUFRDECO_TABLES_CACHE_SIZE]
Definition: bufrdeco.h:955
Contains all tables needed to parse a bufr file.
Definition: bufrdeco.h:938
struct bufr_tableD d
Definition: bufrdeco.h:941
struct bufr_tableB b
Definition: bufrdeco.h:939
struct bufr_tableC c
Definition: bufrdeco.h:940
Stores all structs bufrdeco_bitmap for a bufr bitmap.
Definition: bufrdeco.h:491
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 bitmaped_by[BUFR_MAX_BITMAP_PRESENT_DATA]
Definition: bufrdeco.h:473
buf_t dstat_desc[BUFR_MAX_QUALITY_DATA]
Definition: bufrdeco.h:483
buf_t stat1_desc[BUFR_MAX_QUALITY_DATA]
Definition: bufrdeco.h:480
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
buf_t bitmap_to[BUFR_MAX_BITMAP_PRESENT_DATA]
Definition: bufrdeco.h:472
Manage an array of structs bufrdeco_compressed_ref.
Definition: bufrdeco.h:668
struct bufrdeco_compressed_ref * refs
Definition: bufrdeco.h:671
Struct to hold the needed reference bit offsets, descriptor tree and replications in a compressed BUF...
Definition: bufrdeco.h:639
char unit[BUFR_TABLEB_UNIT_LENGTH]
Definition: bufrdeco.h:651
char name[BUFR_TABLEB_NAME_LENGTH]
Definition: bufrdeco.h:650
struct bufr_descriptor * desc
Definition: bufrdeco.h:652
struct bufr_sequence * seq
Definition: bufrdeco.h:653
stores the state when expanding a sequence.
Definition: bufrdeco.h:524
struct bufrdeco_bitmap * bitmap
Definition: bufrdeco.h:542
Array of structs bufr_sequence from which bufr expanded tree is made.
Definition: bufrdeco.h:596
struct bufr_sequence seq[BUFR_MAX_EXPANDED_SEQUENCES]
Definition: bufrdeco.h:598
Array of offset in bits for every subset in a non-compressed bufr. Offset is counted in bits from the...
Definition: bufrdeco.h:685
buf_t ofs[BUFR_MAX_SUBSETS]
Definition: bufrdeco.h:687
Contains all the information for a subset in a expanded squence This is a version to use with bufrdec...
Definition: bufrdeco.h:458
struct bufr_atom_data * sequence
Definition: bufrdeco.h:462
This struct contains all needed data to parse and decode a BUFR file.
Definition: bufrdeco.h:965
struct bufr_sec0 sec0
Definition: bufrdeco.h:968
struct bufrdeco_bitmap_array bitmap
Definition: bufrdeco.h:980
struct bufrdeco_subset_sequence_data seq
Definition: bufrdeco.h:979
uint32_t mask
Definition: bufrdeco.h:966
struct bufr_sec4 sec4
Definition: bufrdeco.h:972
FILE * err
Definition: bufrdeco.h:985
struct bufr_tables_cache cache
Definition: bufrdeco.h:974
struct bufrdeco_compressed_data_references refs
Definition: bufrdeco.h:978
struct bufrdeco_subset_bit_offsets offsets
Definition: bufrdeco.h:977
struct bufr_sec2 sec2
Definition: bufrdeco.h:970
struct bufrdeco_decoding_data_state state
Definition: bufrdeco.h:976
struct bufr_tables * tables
Definition: bufrdeco.h:973
char bufrtables_dir[BUFRDECO_PATH_LENGTH]
Definition: bufrdeco.h:982
struct bufr_sec3 sec3
Definition: bufrdeco.h:971
struct gts_header header
Definition: bufrdeco.h:967
FILE * out
Definition: bufrdeco.h:984
struct bufrdeco_expanded_tree * tree
Definition: bufrdeco.h:975
char error[1024]
Definition: bufrdeco.h:983
struct bufrdeco_bitmap_related_vars brv
Definition: bufrdeco.h:981
struct bufr_sec1 sec1
Definition: bufrdeco.h:969
stores WMO GTS header info
Definition: bufrdeco.h:707
char center[8]
Definition: bufrdeco.h:709
char dtrel[16]
Definition: bufrdeco.h:710
char order[8]
Definition: bufrdeco.h:711
char bname[16]
Definition: bufrdeco.h:708
char filename[BUFRDECO_PATH_LENGTH]
Definition: bufrdeco.h:712
char timestamp[16]
Definition: bufrdeco.h:713