bufr2synop 0.24.0
Functions
bufrdeco_json.c File Reference

This file has the code which functions to print BUFR data in json format. More...

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

Go to the source code of this file.

Functions

buf_t bufrdeco_print_json_scape_string_cvals (FILE *out, char *source)
 prints a descriptor string value scaping the '"' for a json format More...
 
buf_t bufrdeco_print_json_subset_data_prologue (FILE *out, struct bufrdeco *b)
 
buf_t bufrdeco_print_json_subset_data_epilogue (FILE *out)
 
buf_t bufrdeco_print_json_sequence_descriptor_header (FILE *out, struct bufr_sequence *seq)
 Print the header of a sequence descriptor (f == 3) More...
 
buf_t bufrdeco_print_json_sequence_descriptor_final (FILE *out)
 
buf_t bufrdeco_print_json_object_atom_data (FILE *out, struct bufr_atom_data *a, char *add)
 Print an json object with a descriptor data. More...
 
buf_t bufrdeco_print_json_object_operator_descriptor (FILE *out, struct bufr_descriptor *d, char *add)
 print an operator desciptor as a json object More...
 
buf_t bufrdeco_print_json_object_replicator_descriptor (FILE *out, struct bufr_descriptor *d, char *add)
 print an operator desciptor as a json object More...
 
buf_t bufrdeco_print_json_separator (FILE *out)
 Print the comma ',' separator in an output. More...
 
buf_t bufrdeco_print_json_sec0 (FILE *out, struct bufrdeco *b)
 
buf_t bufrdeco_print_json_sec1 (FILE *out, struct bufrdeco *b)
 Print info form sec 1 in json format. More...
 
buf_t bufrdeco_print_json_sec2 (FILE *out, struct bufrdeco *b)
 Print info form optional sec 2 in json format. More...
 
buf_t bufrdeco_print_json_sec3 (FILE *out, struct bufrdeco *b)
 Print info form sec 3 in json format. More...
 
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. More...
 
buf_t bufrdeco_print_json_tree (struct bufrdeco *b)
 

Detailed Description

This file has the code which functions to print BUFR data in json format.

Definition in file bufrdeco_json.c.

Function Documentation

◆ bufrdeco_print_json_object_atom_data()

buf_t bufrdeco_print_json_object_atom_data ( FILE *  out,
struct bufr_atom_data a,
char *  add 
)

Print an json object with a descriptor data.

Parameters
outoutput stream opened by caller
apointer to target struct bufr_atom_data
addadtional optional info
Returns
The amount of bytes sent to out

There are four cases of objects, depending of data type { "descriptor":"f xx yyy", "name":"name_of_descriptor" , "unit":"name_of_unit", "value":"string_value"} { "descriptor":"f xx yyy", "name":"name_of_descriptor" , "unit":"Code table", "value":"numeric_value", "meaning":"explanation_string} { "descriptor":"f xx yyy", "name":"name_of_descriptor" , "unit":"Flag value", "value":"numeric_value", "meaning":"explanation_string} { "descriptor":"f xx yyy", "name":"name_of_descriptor" , "unit":"name_of_unit", "value":"numeric_value"}

Definition at line 134 of file bufrdeco_json.c.

135{
136 char aux[256];
137 buf_t used = 0;
138
139 used += fprintf ( out, "{\"Descriptor\":\"%u %02u %03u\",\"Name\":\"%s\",", a->desc.f, a->desc.x, a->desc.y, bufr_adjust_string ( a->name ) );
140
141 // add aditional info keys
142 if ( add != NULL && add[0] )
143 used += fprintf ( out, "%s,", add );
144
146 {
147 // string data case
149 used += fprintf ( out, "\"Unit\":\"CCITT5\",\"Value\":\"MISSING\"}" ) ;
150 else
151 {
152 used += fprintf ( out, "\"Unit\":\"CCITT5\",\"Value\":\"" ) ;
154 used += fprintf ( out, "\"}" );
155 }
156 }
157 else if ( a->mask & DESCRIPTOR_IS_CODE_TABLE )
158 {
159 // code table case
161 used += fprintf ( out, "\"Unit\":\"Code table\",\"Value\":\"MISSING\"}" ) ;
162 else
163 {
164 used += fprintf ( out, "\"Unit\":\"Code table\",\"Value\":%u,", ( uint32_t ) ( a->val + 0.5 ) ) ;
165 used += fprintf ( out, "\"Meaning\":\"%s\"}", bufr_adjust_string ( a->ctable ) );
166 }
167 }
168 else if ( a->mask & DESCRIPTOR_IS_FLAG_TABLE )
169 {
170 // flag table case
172 used += fprintf ( out, "\"Unit\":\"Flag table\",\"Value\":\"MISSING\"}" ) ;
173 else
174 {
175 used += fprintf ( out, "\"Unit\":\"Flag table\",\"Value\":\"0x%08X\",", ( uint32_t ) ( a->val ) ) ;
176 used += fprintf ( out, "\"Meaning\":\"%s\"}", bufr_adjust_string ( a->ctable ) );
177 }
178 }
179 else
180 {
181 // numeric data case
183 used += fprintf ( out, "\"Unit\":\"%s\",\"Value\":\"MISSING\"}", a->unit ) ;
184 else
185 {
186 used += fprintf ( out, "\"Unit\":\"%s\",\"Value\":%s}", a->unit,
187 get_formatted_value_from_escale2 ( aux, sizeof ( aux ), a->escale, a->val ) );
188
189 }
190 }
191 return used;
192}
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
uint32_t buf_t
Type to set offsets and dimension of arrays or counters used in bufrdeco.
Definition: bufrdeco.h:346
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
#define DESCRIPTOR_HAVE_STRING_VALUE
Bit mask for a string in a struct bufr_atom_data.
Definition: bufrdeco.h:152
#define DESCRIPTOR_IS_FLAG_TABLE
Bit mask for a flag table in a struct bufr_atom_data.
Definition: bufrdeco.h:176
#define DESCRIPTOR_IS_CODE_TABLE
Bit mask for a code table in a struct bufr_atom_data.
Definition: bufrdeco.h:158
#define DESCRIPTOR_VALUE_MISSING
Bit mask for a missing value in a struct bufr_atom_data.
Definition: bufrdeco.h:140
char * bufr_adjust_string(char *s)
Supress trailing blanks of a string.
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
double val
Definition: bufrdeco.h:440
char unit[BUFR_TABLEB_UNIT_LENGTH]
Definition: bufrdeco.h:439
char cval[BUFR_CVAL_LENGTH]
Definition: bufrdeco.h:443

References bufr_adjust_string(), bufrdeco_print_json_scape_string_cvals(), bufr_atom_data::ctable, bufr_atom_data::cval, bufr_atom_data::desc, DESCRIPTOR_HAVE_STRING_VALUE, DESCRIPTOR_IS_CODE_TABLE, DESCRIPTOR_IS_FLAG_TABLE, DESCRIPTOR_VALUE_MISSING, bufr_atom_data::escale, bufr_descriptor::f, get_formatted_value_from_escale2(), bufr_atom_data::mask, bufr_atom_data::name, bufr_atom_data::unit, bufr_atom_data::val, bufr_descriptor::x, and bufr_descriptor::y.

Referenced by bufr_decode_subset_data_compressed(), bufrdeco_decode_replicated_subsequence(), bufrdeco_decode_subset_data_recursive(), and bufrdeco_parse_f2_descriptor().

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

◆ bufrdeco_print_json_object_operator_descriptor()

buf_t bufrdeco_print_json_object_operator_descriptor ( FILE *  out,
struct bufr_descriptor d,
char *  add 
)

print an operator desciptor as a json object

Parameters
outoutput stream opened by caller
dpointer to operator descriptor
addadtional optional info
Returns
The amount of bytes sent to out

Definition at line 203 of file bufrdeco_json.c.

204{
205 buf_t used = 0;
206 char explanation[256];
207
208 if ( d->f == 2 )
209 {
210 // only prints if f == 2
211 used += fprintf ( out, "{\"Descriptor\":\"%u %02u %03u\",", d->f, d->x, d->y );
212 // add aditional info keys
213 if ( add != NULL && add[0] )
214 used += fprintf ( out, "%s,", add );
215
216 used += fprintf ( out, "\"Operator\": \"%s\"}", bufrdeco_get_f2_descriptor_explanation ( explanation, sizeof ( explanation ), d ) );
217 }
218 return used;
219}
char * bufrdeco_get_f2_descriptor_explanation(char *e, size_t dim, struct bufr_descriptor *d)
Definition: bufrdeco_f2.c:773

References bufrdeco_get_f2_descriptor_explanation(), bufr_descriptor::f, bufr_descriptor::x, and bufr_descriptor::y.

Referenced by bufr_decode_subset_data_compressed(), bufrdeco_decode_replicated_subsequence(), and bufrdeco_decode_subset_data_recursive().

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

◆ bufrdeco_print_json_object_replicator_descriptor()

buf_t bufrdeco_print_json_object_replicator_descriptor ( FILE *  out,
struct bufr_descriptor d,
char *  add 
)

print an operator desciptor as a json object

Parameters
outstring where to print
dpointer to operator descriptor
addadditional info
Returns
The amount of bytes sent to out

Definition at line 230 of file bufrdeco_json.c.

231{
232 buf_t used = 0;
233
234 if ( d->f == 1 )
235 {
236 used += fprintf ( out, "{\"Descriptor\":\"%u %02u %03u\",", d->f, d->x, d->y );
237 // add aditional info keys
238 if ( add != NULL && add[0] )
239 used += fprintf ( out, "%s,", add );
240
241 if ( d->y == 0 )
242 {
243 if ( d->x == 1 )
244 used += fprintf ( out, "\"Replicator\":\"Replicator for %d descriptor after next delayed descriptor which set the number of replications.\"}", d->x );
245 else
246 used += fprintf ( out, "\"Replicator\":\"Replicator for %d descriptors after next delayed descriptor which set the number of replications.\"}", d->x );
247 }
248 else
249 {
250 if ( d->x == 1 )
251 used += fprintf ( out, "\"Replicator\":\"Replicator for next descriptor %d times.\"}", d->y );
252 else
253 used += fprintf ( out, "\"Replicator\":\"Replicator for next %d descriptors %d times\"}", d->x, d->y );
254 }
255
256 }
257 return used;
258}

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

Referenced by bufr_decode_subset_data_compressed(), bufrdeco_decode_replicated_subsequence(), and bufrdeco_decode_subset_data_recursive().

Here is the caller graph for this function:

◆ bufrdeco_print_json_scape_string_cvals()

buf_t bufrdeco_print_json_scape_string_cvals ( FILE *  out,
char *  source 
)

prints a descriptor string value scaping the '"' for a json format

Parameters
outoutput stream
sourcesource string
Returns
The amount of bytes sent to out

Definition at line 33 of file bufrdeco_json.c.

34{
35 buf_t i = 0, used = 0;
36 while ( source[i] )
37 {
38 switch ( source[i] )
39 {
40 case '"':
41 used += fprintf ( out, "%c%c", '\\', source[i++] );
42 break;
43 default:
44 used += fprintf ( out, "%c", source[i++] );
45 break;
46 }
47 }
48 return used;
49}

Referenced by bufrdeco_print_json_object_atom_data().

Here is the caller graph for this function:

◆ bufrdeco_print_json_sec0()

buf_t bufrdeco_print_json_sec0 ( FILE *  out,
struct bufrdeco b 
)

Definition at line 280 of file bufrdeco_json.c.

281{
282 size_t used = 0;
283
284 bufrdeco_assert ( b != NULL );
285 used += fprintf ( out, "{\"Sec 0\":{" );
286 used += fprintf ( out, "\"Bufr length\":%u,", b->sec0.bufr_length );
287 used += fprintf ( out, "\"Bufr edition\":%u}}", b->sec0.edition );
288 return used;
289}
#define bufrdeco_assert(__my_expr__)
Check a expression and exit if it fails.
Definition: bufrdeco.h:374
uint8_t edition
Definition: bufrdeco.h:698
uint32_t bufr_length
Definition: bufrdeco.h:697
struct bufr_sec0 sec0
Definition: bufrdeco.h:968

References bufr_sec0::bufr_length, bufrdeco_assert, bufr_sec0::edition, and bufrdeco::sec0.

Referenced by bufrdeco_read_buffer().

Here is the caller graph for this function:

◆ bufrdeco_print_json_sec1()

buf_t bufrdeco_print_json_sec1 ( FILE *  out,
struct bufrdeco b 
)

Print info form sec 1 in json format.

Parameters
outstring where to print
bactuve struct bufrdeco
Returns
The amount of bytes sent to out

Definition at line 300 of file bufrdeco_json.c.

301{
302 size_t used = 0;
303
304 bufrdeco_assert ( b != NULL );
305 used += fprintf ( out, "{\"Sec 1\":{" );
306 used += fprintf ( out, "\"Length\":%u", b->sec1.length );
307 used += fprintf ( out, ",\"Bufr master table\":%u", b->sec1.master );
308 used += fprintf ( out, ",\"Centre\":%u", b->sec1.centre );
309 used += fprintf ( out, ",\"Sub-Centre\":%u", b->sec1.subcentre );
310 used += fprintf ( out, ",\"Update sequence\":%u", b->sec1.update );
311 used += fprintf ( out, ",\"Options\":\"0x%x\"", b->sec1.options );
312 used += fprintf ( out, ",\"Category\":%u", b->sec1.category );
313 used += fprintf ( out, ",\"Subcategory\":%u", b->sec1.subcategory );
314 used += fprintf ( out, ",\"Sub-category local\":%u", b->sec1.subcategory_local );
315 used += fprintf ( out, ",\"Master table version\":%u", b->sec1.master_version );
316 used += fprintf ( out, ",\"Master table local\":%u", b->sec1.master_local );
317 used += fprintf ( out, ",\"Year\":%u", b->sec1.year );
318 used += fprintf ( out, ",\"Month\":%u", b->sec1.month );
319 used += fprintf ( out, ",\"Day\":%u", b->sec1.day );
320 used += fprintf ( out, ",\"Hour\":%u", b->sec1.hour );
321 used += fprintf ( out, ",\"Minute\":%u", b->sec1.minute );
322 used += fprintf ( out, ",\"Second\":%u", b->sec1.second );
323 if ( b->sec0.edition == 3 )
324 used += fprintf ( out, ",\"Aditional space\":%u", b->sec1.length - 17 );
325 else
326 used += fprintf ( out, ",\"Aditional space\":%u", b->sec1.length - 22 );
327 used += fprintf ( out, "}" );
328
329 if ( b->tables->b.path[0] )
330 {
331 used += fprintf ( out, ",{\"Used tables\":{" );
332 used += fprintf ( out, ",\"TableB file\":\"%s\"", b->tables->b.path );
333 used += fprintf ( out, ",\"tableC file\":\"%s\"", b->tables->c.path );
334 used += fprintf ( out, ",\"tableD file\":\"%s\"", b->tables->d.path );
335 used += fprintf ( out, "}" );
336 }
337 used += fprintf ( out, "}" );
338
339 return used;
340}
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 hour
Definition: bufrdeco.h:787
uint8_t update
Definition: bufrdeco.h:777
uint8_t master
Definition: bufrdeco.h:774
char path[BUFRDECO_PATH_LENGTH]
Definition: bufrdeco.h:861
char path[BUFRDECO_PATH_LENGTH]
Definition: bufrdeco.h:893
char path[BUFRDECO_PATH_LENGTH]
Definition: bufrdeco.h:922
struct bufr_tableD d
Definition: bufrdeco.h:941
struct bufr_tableB b
Definition: bufrdeco.h:939
struct bufr_tableC c
Definition: bufrdeco.h:940
struct bufr_tables * tables
Definition: bufrdeco.h:973
struct bufr_sec1 sec1
Definition: bufrdeco.h:969

References bufr_tables::b, bufrdeco_assert, bufr_tables::c, bufr_sec1::category, bufr_sec1::centre, bufr_tables::d, bufr_sec1::day, bufr_sec0::edition, bufr_sec1::hour, bufr_sec1::length, bufr_sec1::master, bufr_sec1::master_local, bufr_sec1::master_version, bufr_sec1::minute, bufr_sec1::month, bufr_sec1::options, bufr_tableB::path, bufr_tableC::path, bufr_tableD::path, bufrdeco::sec0, bufrdeco::sec1, bufr_sec1::second, bufr_sec1::subcategory, bufr_sec1::subcategory_local, bufr_sec1::subcentre, bufrdeco::tables, bufr_sec1::update, and bufr_sec1::year.

Referenced by bufrdeco_read_buffer().

Here is the caller graph for this function:

◆ bufrdeco_print_json_sec2()

buf_t bufrdeco_print_json_sec2 ( FILE *  out,
struct bufrdeco b 
)

Print info form optional sec 2 in json format.

Parameters
outstring where to print
bactuve struct bufrdeco
Returns
The amount of bytes sent to out

Definition at line 350 of file bufrdeco_json.c.

351{
352 size_t used = 0;
353
354 bufrdeco_assert ( b != NULL );
355 used += fprintf ( out, "{\"Sec 2\":{" );
356 if ( b->sec1.options & 0x80 )
357 used += fprintf ( out, "\"Length\":%u}}", b->sec2.length );
358 else
359 used += fprintf ( out, "\"Length\":0}}" );
360
361 return used;
362}
uint32_t length
Definition: bufrdeco.h:799
struct bufr_sec2 sec2
Definition: bufrdeco.h:970

References bufrdeco_assert, bufr_sec2::length, bufr_sec1::options, bufrdeco::sec1, and bufrdeco::sec2.

Referenced by bufrdeco_read_buffer().

Here is the caller graph for this function:

◆ bufrdeco_print_json_sec3()

buf_t bufrdeco_print_json_sec3 ( FILE *  out,
struct bufrdeco b 
)

Print info form sec 3 in json format.

Parameters
outstring where to print
bactuve struct bufrdeco
Returns
The amount of bytes sent to out

Definition at line 372 of file bufrdeco_json.c.

373{
374 buf_t used = 0, i;
375
376 bufrdeco_assert ( b != NULL );
377 used += fprintf ( out, "{\"Sec 3\":{" );
378 used += fprintf ( out, "\"Sec3 length\":%u", b->sec3.length );
379 used += fprintf ( out, ",\"Subsets\":%u", b->sec3.subsets );
380 used += fprintf ( out, ",\"Observed\":%u", b->sec3.observed );
381 used += fprintf ( out, ",\"Compressed\":%u", b->sec3.compressed );
382 used += fprintf ( out, ",\"Unexpanded descriptors\":%u", b->sec3.ndesc );
383 used += fprintf ( out, ",\"Unexpanded array\":" );
384
385 used += fprintf ( out,"[" );
386 for ( i = 0; i < b->sec3.ndesc; i++ )
387 {
388 if ( i )
389 used += fprintf ( out,"," );
390 used += fprintf ( out, "{\"%u\":\"%u %02u %03u\"}", i, b->sec3.unexpanded[i].f, b->sec3.unexpanded[i].x, b->sec3.unexpanded[i].y );
391 }
392 used += fprintf ( out,"]}}" );
393
394 return used;
395}
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
struct bufr_sec3 sec3
Definition: bufrdeco.h:971

References bufrdeco_assert, bufr_sec3::compressed, bufr_descriptor::f, bufr_sec3::length, bufr_sec3::ndesc, bufr_sec3::observed, bufrdeco::sec3, bufr_sec3::subsets, bufr_sec3::unexpanded, bufr_descriptor::x, and bufr_descriptor::y.

Referenced by bufrdeco_read_buffer().

Here is the caller graph for this function:

◆ bufrdeco_print_json_separator()

buf_t bufrdeco_print_json_separator ( FILE *  out)

Print the comma ',' separator in an output.

Parameters
outstring where to print
Returns
The amount of bytes sent to out

Definition at line 267 of file bufrdeco_json.c.

268{
269 return fprintf ( out, "," );
270}

Referenced by bufr_decode_subset_data_compressed(), bufrdeco_decode_replicated_subsequence(), bufrdeco_decode_subset_data_recursive(), and bufrdeco_parse_f2_descriptor().

Here is the caller graph for this function:

◆ bufrdeco_print_json_sequence_descriptor_final()

buf_t bufrdeco_print_json_sequence_descriptor_final ( FILE *  out)

Definition at line 110 of file bufrdeco_json.c.

111{
112 buf_t used = 0;
113 // print final
114 used += fprintf ( out, "]}" );
115 return used;
116}

Referenced by bufr_decode_subset_data_compressed(), and bufrdeco_decode_subset_data_recursive().

Here is the caller graph for this function:

◆ bufrdeco_print_json_sequence_descriptor_header()

buf_t bufrdeco_print_json_sequence_descriptor_header ( FILE *  out,
struct bufr_sequence seq 
)

Print the header of a sequence descriptor (f == 3)

Parameters
outoutput stream opened by caller
seqpointer to a bufr_sequence bufr_sequence
Returns
The amount of bytes sent to out

Definition at line 94 of file bufrdeco_json.c.

95{
96 buf_t used = 0;
97
98 used += fprintf ( out, "{\"Descriptor\":\"%c %c%c %c%c%c\",", seq->key[0], seq->key[1], seq->key[2], seq->key[3], seq->key[4], seq->key[5] );
99 used += fprintf ( out, "\"Sequence description\":\"%s\",\"Expanded sequence\":[", seq->name );
100 return used;
101}
char key[8]
Definition: bufrdeco.h:573
char name[BUFR_EXPLAINED_LENGTH]
Definition: bufrdeco.h:588

References bufr_sequence::key, and bufr_sequence::name.

Referenced by bufr_decode_subset_data_compressed(), and bufrdeco_decode_subset_data_recursive().

Here is the caller graph for this function:

◆ bufrdeco_print_json_subset_data_epilogue()

buf_t bufrdeco_print_json_subset_data_epilogue ( FILE *  out)

Definition at line 77 of file bufrdeco_json.c.

78{
79 buf_t used = 0;
80
81 // print prologue
82 used += fprintf ( out, "}\n" );
83 return used;
84}

Referenced by bufr_decode_subset_data_compressed(), and bufrdeco_decode_subset_data_recursive().

Here is the caller graph for this function:

◆ bufrdeco_print_json_subset_data_prologue()

buf_t bufrdeco_print_json_subset_data_prologue ( FILE *  out,
struct bufrdeco b 
)

Definition at line 58 of file bufrdeco_json.c.

59{
60 buf_t used = 0;
61
62 bufrdeco_assert ( b != NULL );
63
64 // print prologue
65 used += fprintf ( out, "{\"BUFR File\":\"%s\",\"Subset\":%u,\"Decoded data\":",b->header.filename, b->seq.ss );
66
67 return used;
68}
struct bufrdeco_subset_sequence_data seq
Definition: bufrdeco.h:979
struct gts_header header
Definition: bufrdeco.h:967
char filename[BUFRDECO_PATH_LENGTH]
Definition: bufrdeco.h:712

References bufrdeco_assert, gts_header::filename, bufrdeco::header, bufrdeco::seq, and bufrdeco_subset_sequence_data::ss.

Referenced by bufr_decode_subset_data_compressed(), and bufrdeco_decode_subset_data_recursive().

Here is the caller graph for this function:

◆ bufrdeco_print_json_tree()

buf_t bufrdeco_print_json_tree ( struct bufrdeco b)

Definition at line 508 of file bufrdeco_json.c.

509{
510 buf_t used = 0;
511 bufrdeco_assert ( b != NULL );
512
514 used += bufrdeco_print_json_tree_recursive ( b->out, b, NULL );
515 return used;
516};
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.
#define BUFRDECO_OUTPUT_JSON_EXPANDED_TREE
Bit mask to the member mask of struct bufrdeco to print bufr expanded tree of descriptors.
Definition: bufrdeco.h:305
uint32_t mask
Definition: bufrdeco.h:966
FILE * out
Definition: bufrdeco.h:984

References bufrdeco_assert, BUFRDECO_OUTPUT_JSON_EXPANDED_TREE, bufrdeco_print_json_tree_recursive(), bufrdeco::mask, and bufrdeco::out.

Referenced by main().

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

◆ bufrdeco_print_json_tree_recursive()

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.

Parameters
outstream opened by caller
bpointer to the basic container struct bufrdeco
seqpointer to the struct bufr_sequence to print
Returns
The amount of bytes sent to out

Definition at line 405 of file bufrdeco_json.c.

406{
407 buf_t i, k, used = 0;
408 struct bufr_sequence *l;
409 char explanation[256];
410
411 bufrdeco_assert ( out != NULL && b != NULL );
412
413 if ( seq == NULL )
414 {
415 l = & ( b->tree->seq[0] );
416 }
417 else
418 {
419 l = seq;
420 }
421
422 // begins the array
423 for ( i = 0; i < l->ndesc; i++ )
424 {
425 if ( i )
426 used += fprintf ( out, "," );
427 fprintf ( out, "{\"%u %02u %03u\"", l->lseq[i].f, l->lseq[i].x,l->lseq[i].y );
428
429 if ( l->lseq[i].f != 3 )
430 {
431 if ( l->lseq[i].f == 0 )
432 {
433 if ( bufr_find_tableB_index ( &k, & ( b->tables->b ), l->lseq[i].c ) )
434 used += fprintf ( out, "\"Not found in tables\"}" );
435 else
436 {
437 used += fprintf ( out, ":\"" );
438 if ( l->replicated[i] )
439 {
440 if ( l->replicated[i] )
441 {
442 if ( l->replicated[i] == 1 )
443 used += fprintf ( out, "Replicated | " );
444 else
445 used += fprintf ( out, "Replicated depth %u | ", l->replicated[i] );
446 }
447 }
448 if ( is_a_delayed_descriptor ( & l->lseq[i] ) ||
450 used += fprintf ( out, "* %s\"}", b->tables->b.item[k].name );
451 else
452 used += fprintf ( out, "%s\"}", b->tables->b.item[k].name );
453 }
454 }
455 else if ( l->lseq[i].f == 2 )
456 {
457 used += fprintf ( out, ":\"%s\"}", bufrdeco_get_f2_descriptor_explanation ( explanation, sizeof ( explanation ), & ( l->lseq[i] ) ) );
458 }
459 else if ( l->lseq[i].f == 1 )
460 {
461 if ( l->lseq[i].y == 0 )
462 {
463 if ( l->lseq[i].x == 1 )
464 used += fprintf ( out, ":\"* Replicator for %d descriptor after next delayed descriptor which set the number of replications.\"}", l->lseq[i].x );
465 else
466 used += fprintf ( out, ":\"* Replicator for %d descriptors after next delayed descriptor which set the number of replications.\"}", l->lseq[i].x );
467 }
468 else
469 {
470 if ( l->lseq[i].x == 1 )
471 used += fprintf ( out, ":\"* Replicator for next descriptor %d times\"}", l->lseq[i].y );
472 else
473 used += fprintf ( out, ":\"* Replicator for next %d descriptors %d times\"}", l->lseq[i].x, l->lseq[i].y );
474 }
475 }
476 else
477 used += fprintf ( out, "\n" );
478 continue;
479 }
480 else
481 {
482 // f == 3
483 used += fprintf ( out, ":\"" );
484 if ( l->replicated[i] )
485 {
486 if ( l->replicated[i] == 1 )
487 used += fprintf ( out, "Replicated | " );
488 else
489 used += fprintf ( out, "Replicated depth %u | ", l->replicated[i] );
490 }
491 used += fprintf ( out, "%s\"", bufr_adjust_string ( l->name ) );
492 used += fprintf ( out, ",\"Expanded\":[" );
493 // parse de son
494 used += bufrdeco_print_json_tree_recursive ( out, b, l->sons[i] );
495 used += fprintf ( out, "]}" );
496 // we then recursively parse the son
497 }
498 }
499 return used;
500}
int bufr_find_tableB_index(buf_t *index, struct bufr_tableB *tb, const char *key)
found a descriptor index in a struct bufr_tableB
int is_a_delayed_descriptor(struct bufr_descriptor *d)
check if a descriptor is a delayed descriptor
int is_a_short_delayed_descriptor(struct bufr_descriptor *d)
check if a descriptor is a short delayed descriptor
char c[12]
Definition: bufrdeco.h:414
Stores an unexpanded sequence of descriptors.
Definition: bufrdeco.h:572
struct bufr_descriptor lseq[NMAXSEQ_DESCRIPTORS]
Definition: bufrdeco.h:583
buf_t ndesc
Definition: bufrdeco.h:575
uint8_t replicated[NMAXSEQ_DESCRIPTORS]
Definition: bufrdeco.h:582
struct bufr_sequence * sons[NMAXSEQ_DESCRIPTORS]
Definition: bufrdeco.h:584
char name[BUFR_TABLEB_NAME_LENGTH]
Definition: bufrdeco.h:842
struct bufr_tableB_decoded_item item[BUFR_MAXLINES_TABLEB]
Definition: bufrdeco.h:867
struct bufr_sequence seq[BUFR_MAX_EXPANDED_SEQUENCES]
Definition: bufrdeco.h:598
struct bufrdeco_expanded_tree * tree
Definition: bufrdeco.h:975

References bufr_tables::b, bufr_adjust_string(), bufr_find_tableB_index(), bufrdeco_assert, bufrdeco_get_f2_descriptor_explanation(), bufrdeco_print_json_tree_recursive(), bufr_descriptor::c, bufr_descriptor::f, is_a_delayed_descriptor(), is_a_short_delayed_descriptor(), bufr_tableB::item, bufr_sequence::lseq, bufr_sequence::name, bufr_tableB_decoded_item::name, bufr_sequence::ndesc, bufr_sequence::replicated, bufrdeco_expanded_tree::seq, bufr_sequence::sons, bufrdeco::tables, bufrdeco::tree, bufr_descriptor::x, and bufr_descriptor::y.

Referenced by bufrdeco_print_json_tree(), and bufrdeco_print_json_tree_recursive().

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