bufr2synop 0.24.0
bufrdeco_f2.c
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_f2.c
22 \brief file with the code to process some of the operations in B for F = 2
23 */
24#ifndef CONFIG_H
25# include "config.h"
26# define CONFIG_H
27#endif
28
29#include "bufrdeco.h"
30
31/*!
32 \fn int bufrdeco_parse_f2_descriptor ( struct bufrdeco_subset_sequence_data *s, struct bufr_descriptor *d, struct bufrdeco *b )
33 \brief parse a descritor with f = 2
34 \param s pointer to a struct \ref bufrdeco_subset_sequence_data where to set data if any
35 \param d pointer to the source descriptor
36 \param b pointer to the base struct \ref bufrdeco
37 \return If succeded return 0, otherwise 1
38 */
40{
41 buf_t nbits;
42 struct bufr_atom_data *a;
43 uint8_t has_data;
44
45 // Check args
46 bufrdeco_assert ( b != NULL );
47
48 if ( d == NULL || s == NULL )
49 {
50 snprintf ( b->error, sizeof ( b->error ), "%s(): Unspected NULL argument(s)\n", __func__ );
51 }
52
53 if ( d->f != 2 )
54 {
55 return 0; // nothing to do here
56 }
57
58 switch ( d->x )
59 {
60 case 1:
61 // Add (YYY–128) bits to the data width given for each
62 // data element in Table B, other than CCITT IA5
63 // (character) data, code or flag tables.
64 if ( d->y )
65 {
66 b->state.added_bit_length = d->y - 128;
67 }
68 else
69 {
71 }
72 break;
73
74 case 2:
75 // Add YYY–128 to the scale for each data element in
76 // Table B, other than CCITT IA5 (character) data, code
77 // or flag tables.
78 if ( d->y )
79 {
80 b->state.added_scale = d->y - 128;
81 }
82 else
83 {
84 b->state.added_scale = 0;
85 }
86 break;
87
88 case 3:
89 // Subsequent element descriptors define new reference
90 // values for corresponding Table B entries. Each new
91 // reference value is represented by YYY bits in the Data
92 // section. Definition of new reference values is concluded
93 // by coding this operator with YYY = 255. Negative
94 // reference values shall be represented by a positive
95 // integer with the left-most bit (bit 1) set to 1.
97 break;
98
99 case 4:
100 // Precede each data element with YYY bits of
101 // information. This operation associates a data field
102 // (e.g. quality control information) of YYY bits with each
103 // data element.
104 b->state.assoc_bits = d->y;
105 break;
106
107 case 5:
108 // YYY characters (CCITT International Alphabet No. 5) are
109 // inserted as a data field of YYY x 8 bits in length.
110 nbits = 8 * d->y;
111 a = & ( s->sequence[s->nd] );
112 memcpy ( &a->desc, d, sizeof ( struct bufr_descriptor ) );
113 if ( get_bits_as_char_array ( a->cval, &has_data, &b->sec4.raw[4], & ( b->state.bit_offset ), nbits ) == 0 )
114 {
115 snprintf ( b->error, sizeof ( b->error ), "%s(): Cannot get %u uchars from '%s'\n", __func__, d->y, d->c );
116 return 1;
117 }
118 if ( has_data == 0 )
119 {
121 }
122 else
123 {
125 }
126 //strcpy_safe ( a->name, "SIGNIFY CHARACTER" );
127 //strcpy_safe ( a->unit, "CCITTIA5" ); // unit
128 strcpy ( a->name, "SIGNIFY CHARACTER" );
129 strcpy ( a->unit, "CCITTIA5" ); // unit
131 {
134 }
135
136 if ( s->nd < ( s->dim - 1 ) )
137 {
138 ( s->nd ) ++;
139 }
140 else if ( bufrdeco_increase_data_array ( s ) == 0 )
141 {
142 ( s->nd ) ++;
143 }
144 else
145 {
146 snprintf ( b->error, sizeof ( b->error ), "%s(): No more bufr_atom_data available. Check BUFR_NMAXSEQ\n", __func__ );
147 return 1;
148 }
149 break;
150
151 case 6:
152 // YYY bits of data are described by the immediately
153 // following local descriptor.
154 b->state.local_bit_reserved = d->y;
155 break;
156
157 case 7:
158 // For Table B elements, which are not CCITT IA5
159 // (character data), code tables, or flag tables:
160 // 1. Add YYY to the existing scale factor
161 // YYY
162 // 2. Multiply the existing reference value by 10
163 // 3. Calculate ((10 x YYY) + 2) ÷ 3, disregard any
164 // fractional remainder and add the result to the
165 // existing bit width.
166 if ( d->y )
167 {
168 b->state.added_scale = d->y;
169 if ( d->y < 10 )
171 else
172 {
173 snprintf ( b->error, sizeof ( b->error ), "%s(): Too much %u increase bits for operator '%s'", __func__, d->y,
174 d->c );
175 return 1;
176 }
177 b->state.added_bit_length = ( int8_t ) ( ( 10.0 * d->y + 2.0 ) / 3.0 );
178 }
179 else
180 {
181 b->state.added_scale = 0;
182 b->state.factor_reference = 1;
183 b->state.added_bit_length = 0;
184 }
185 break;
186
187 case 8:
188 // YYY characters from CCITT International Alphabet
189 // No. 5 (representing YYY x 8 bits in length) replace the
190 // specified data width given for each CCITT IA5
191 // element in Table B.
192 b->state.fixed_ccitt = d->y;
193 break;
194
195 case 21:
196 // Data not present
197 //
198 // Data values present in Section 4 (Data section)
199 // corresponding to the following YYY descriptors shall
200 // be limited to data from Classes 01–09, and Class 31.
201
202 // It is nor processed here, it is already processed when parsing tree of expanded descriptors
203 // adjusting the proper struct \ref bufr_sequence_index_range no_data_present
204 break;
205
206 case 22:
207 // Quality information follows
208 // The values of Class 33 elements which follow relate to
209 // the data defined by the data present bit-map.
210 //
211 // Here we jsut activate the quality_active flag
212 b->state.quality_active = 1;
213 b->state.subs_active = 0;
214 b->state.retained_active = 0;
215 b->state.stat1_active = 0;
216 b->state.dstat_active = 0;
217 break;
218
219 case 23:
220 if ( d->y == 0 )
221 {
222 // Substituted operator values
223 //
224 // The substituted values which follow relate to the data
225 // defined by the data present bit-map.
226 b->state.quality_active = 0;
227 b->state.subs_active = 1;
228 b->state.retained_active = 0;
229 b->state.stat1_active = 0;
230 b->state.dstat_active = 0;
231 }
232 break;
233
234 case 24:
235 if ( d->y == 0 )
236 {
237 // First-order statistical values follow
238 //
239 // The statistical values which follow relate to the data
240 // defined by the data present bit-map.
241 b->state.quality_active = 0;
242 b->state.subs_active = 0;
243 b->state.retained_active = 0;
244 b->state.stat1_active = 1;
245 b->state.dstat_active = 0;
246 }
247 break;
248
249 case 25:
250 if ( d->y == 0 )
251 {
252 // Difference statistical values follow
253 //
254 // The statistical values which follow relate to the data
255 // defined by the data present bit-map.
256 b->state.quality_active = 0;
257 b->state.subs_active = 0;
258 b->state.retained_active = 0;
259 b->state.stat1_active = 0;
260 b->state.dstat_active = 1;
261 }
262 break;
263
264 case 32:
265 if ( d->y == 0 )
266 {
267 // Replaced/retained values follow
268 //
269 // The replaced/retained values which follow relate to the
270 // data defined by the data present bit-map.
271 b->state.quality_active = 0;
272 b->state.subs_active = 0;
273 b->state.retained_active = 1;
274 b->state.stat1_active = 0;
275 b->state.dstat_active = 0;
276 }
277 break;
278
279 case 35:
280 // Cancel backward data reference
281 //
282 // This operator terminates all previously defined backward
283 // reference and cancels any previously defined
284 // data present bit-map; it causes the next data present
285 // bit-map to refer to the data descriptors which
286 // immediately precede the operator to which it relates.
287
288 // Set the bitmap pointer to NULL.
289 b->state.bitmap = NULL;
290 break;
291
292 case 36:
293 // Define data present bit-map
294 //
295 // This operator defines the data present bit-map which
296 // follows for possible re-use; only one data present
297 // bit-map may be defined between this operator and the
298 // cancel use defined data present bit-map operator.
299
300 // Here we just add a bufrdeco_bitmap struct set the current bitmap
301 if ( bufrdeco_allocate_bitmap ( b ) )
302 {
303 // Cannot allocate another bitmap
304 return 1;
305 }
306 // Set the new current bitmap
307 b->state.bitmap = b->bitmap.bmap[b->bitmap.nba - 1];
308
309 // Now set the bitmaping backward count to 1 to flag that next replicator descriptor must be set it properly
310 b->state.bitmaping = 1;
311
312 break;
313
314 case 37:
315 // if y = 0000 use defined data present bit-map
316 // This operator causes the defined data present bit-map to be used again.
317 //
318 // if y = 255 Cancel use defined data present bit-map
319 // This operator cancels the re-use of the defined data present bit-map.
320 if ( d->y == 0 )
321 {
322 if ( b->bitmap.nba && b->state.bitmap == NULL )
323 b->state.bitmap = b->bitmap.bmap[b->bitmap.nba - 1];
324 }
325 else if ( d->y == 255 )
326 {
327 b->state.bitmap = NULL;
328 }
329 break;
330
331 case 41:
332 // This operator denotes the beginning of the definition of an event.
333 //
334 // An event, as defined for use with operators 2 41 000 and 2 42 000,
335 // is a set of one or more circumstances described using appropriate
336 // Table B descriptors along with their corresponding data values. The
337 // grouping of such descriptors together as a single “event” allows
338 // them to be collectively assigned as the target of a separate descriptor
339 // such as 0 33 045 or 0 33 046. When defining a circumstance within an
340 // event, descriptor 0 33 042 may be employed preceding the appropriate
341 // Table B descriptor in order to indicate that the corresponding value
342 // is actually a bound for a range of values.
343 //
344 // If y = 255 then it denotes the conclusion of the
345 // event definition that was begun via the previous 2 41 000
346 // operator.
347 //
348 // It is nor processed here, it is already processed when parsing tree of expanded descriptors
349 // adjusting the proper struct \ref bufr_sequence_index_range event
350 break;
351
352 case 42:
353 // This operator denotes the beginning of the definition of a conditioning event.
354 //
355 // An event, as defined for use with operators 2 41 000 and 2 42 000,
356 // is a set of one or more circumstances described using appropriate
357 // Table B descriptors along with their corresponding data values. The
358 // grouping of such descriptors together as a single “event” allows
359 // them to be collectively assigned as the target of a separate descriptor
360 // such as 0 33 045 or 0 33 046. When defining a circumstance within an
361 // event, descriptor 0 33 042 may be employed preceding the appropriate
362 // Table B descriptor in order to indicate that the corresponding value
363 // is actually a bound for a range of values.
364 //
365 // If y = 255 then it denotes the conclusion of the conditioning
366 // event definition that was begun via the previous 2 42 000
367 // operator.
368 //
369 // It is nor processed here, it is already processed when parsing tree of expanded descriptors
370 // adjusting the proper struct \ref bufr_sequence_index_range cond_event
371 break;
372
373 case 43:
374 // The values which follow are categorical forecast values
375 //
376 // A categorical forecast value represents a “best guess” from among a set of related,
377 // and often mutually exclusive, data values or categories. Operator 2 43 000 may be
378 // used to designate one or more values as categorical forecast values, and descriptor
379 // 0 33 042 may be employed preceding any such value in order to indicate that that value
380 // is actually a bound for a range of value
381 //
382 // If y == 255 then it denotes the conclusion of the definition of categorical forecast
383 // values that was begun via theprevious 2 43 000 operator.
384 //
385 // It is nor processed here, it is already processed when parsing tree of expanded descriptors
386 // adjusting the proper struct \ref bufr_sequence_index_range cat_forecast
387 break;
388
389 default:
390 snprintf ( b->error, sizeof ( b->error ), "%s(): Still no proccessed descriptor '%s' in "
391 "current library version %s\n", __func__, d->c, VERSION );
392 return 1;
393 }
394 return 0;
395}
396
397
398/*!
399 \fn int bufrdeco_parse_f2_compressed ( struct bufrdeco_compressed_data_references *r, struct bufr_descriptor *d, struct bufrdeco *b )
400 \brief parse a descritor with f = 2 in case of compressed bufr
401 \param r pointer to a struct \ref bufrdeco_compressed_data_references where to set data references if any
402 \param d pointer to the source descriptor
403 \param b pointer to the base struct \ref bufrdeco
404 \return If succeded return 0, otherwise 1
405 */
407{
408 buf_t nbits;
409 uint32_t ival;
410 struct bufrdeco_compressed_ref *rf;
411 uint8_t has_data;
412
413 // Check args
414 bufrdeco_assert ( b != NULL );
415
416 if ( d == NULL || r == NULL )
417 {
418 snprintf ( b->error, sizeof ( b->error ), "%s(): Unspected NULL argument(s)\n", __func__ );
419 }
420
421 if ( d->f != 2 )
422 {
423 return 0; // nothing to do here
424 }
425
426 switch ( d->x )
427 {
428 case 1:
429 // Add (YYY–128) bits to the data width given for each
430 // data element in Table B, other than CCITT IA5
431 // (character) data, code or flag tables.
432 if ( d->y )
433 {
434 b->state.added_bit_length = d->y - 128;
435 }
436 else
437 {
438 b->state.added_bit_length = 0;
439 }
440 break;
441
442 case 2:
443 // Add YYY–128 to the scale for each data element in
444 // Table B, other than CCITT IA5 (character) data, code
445 // or flag tables.
446 if ( d->y )
447 {
448 b->state.added_scale = d->y - 128;
449 }
450 else
451 {
452 b->state.added_scale = 0;
453 }
454 break;
455
456 case 3:
457 // Subsequent element descriptors define new reference
458 // values for corresponding Table B entries. Each new
459 // reference value is represented by YYY bits in the Data
460 // section. Definition of new reference values is concluded
461 // by coding this operator with YYY = 255. Negative
462 // reference values shall be represented by a positive
463 // integer with the left-most bit (bit 1) set to 1.
464 b->state.changing_reference = d->y;
465 break;
466
467 case 4:
468 // Precede each data element with YYY bits of
469 // information. This operation associates a data field
470 // (e.g. quality control information) of YYY bits with each
471 // data element.
472 b->state.assoc_bits = d->y;
473 break;
474
475 case 5:
476 // YYY characters (CCITT International Alphabet No. 5) are
477 // inserted as a data field of YYY x 8 bits in length.
478 nbits = 8 * d->y;
479 rf = & ( r->refs[r->nd] );
481 rf->desc = d;
482 if ( get_bits_as_char_array ( rf->cref0, &rf->has_data, &b->sec4.raw[4], & ( b->state.bit_offset ), nbits ) == 0 )
483 {
484 snprintf ( b->error, sizeof ( b->error ), "%s(): Cannot get %u uchars from '%s'\n", __func__, d->y, d->c );
485 return 1;
486 }
487 //strcpy_safe ( rf->name, "SIGNIFY CHARACTER" );
488 //strcpy_safe ( rf->unit, "CCITTIA5" ); // unit
489 strcpy ( rf->name, "SIGNIFY CHARACTER" );
490 strcpy ( rf->unit, "CCITTIA5" ); // unit
491
492 // Is suppossed all data will have same length in all subsets
493 // extracting inc_bits from next 6 bits
494 if ( get_bits_as_uint32_t ( &ival, &has_data, &b->sec4.raw[4], & ( b->state.bit_offset ), 6 ) == 0 )
495 {
496 snprintf ( b->error, sizeof ( b->error ), "%s(): Cannot get 6 bits for inc_bits from '%s'\n", __func__, d->c );
497 return 1;
498 }
499 if ( ival != d->y )
500 {
501 snprintf ( b->error, sizeof ( b->error ), "%s(): Bad length in inc_bits for a 2 05 YYY descriptor from '%s'\n", __func__, d->c );
502 return 1;
503 }
504 rf->inc_bits = ival;
505 b->state.bit_offset += rf->inc_bits * 8 * b->sec3.subsets;
506 if ( r->nd < ( BUFR_NMAXSEQ - 1 ) )
507 {
508 r->nd += 1;
509 }
510 else
511 {
512 snprintf ( b->error, sizeof ( b->error ), "%s(): Reached limit. Consider increas BUFR_NMAXSEQ\n", __func__ );
513 return 1;
514 }
515 break;
516
517 case 6:
518 // YYY bits of data are described by the immediately
519 // following local descriptor.
520 b->state.local_bit_reserved = d->y;
521 break;
522
523 case 7:
524 // For Table B elements, which are not CCITT IA5
525 // (character data), code tables, or flag tables:
526 // 1. Add YYY to the existing scale factor
527 // YYY
528 // 2. Multiply the existing reference value by 10
529 // 3. Calculate ((10 x YYY) + 2) ÷ 3, disregard any
530 // fractional remainder and add the result to the
531 // existing bit width.
532 if ( d->y )
533 {
534 b->state.added_scale = d->y;
535 if ( d->y < 10 )
537 else
538 {
539 snprintf ( b->error, sizeof ( b->error ), "%s(): Too much %u increase bits for operator '%s'", __func__, d->y,
540 d->c );
541 return 1;
542 }
543 b->state.added_bit_length = ( int8_t ) ( ( 10.0 * d->y + 2.0 ) / 3.0 );
544 }
545 else
546 {
547 b->state.added_scale = 0;
548 b->state.factor_reference = 1;
549 b->state.added_bit_length = 0;
550 }
551 break;
552
553 case 8:
554 // YYY characters from CCITT International Alphabet
555 // No. 5 (representing YYY x 8 bits in length) replace the
556 // specified data width given for each CCITT IA5
557 // element in Table B.
558 b->state.fixed_ccitt = d->y;
559 break;
560
561 case 21:
562 // Data not present
563 //
564 // Data values present in Section 4 (Data section)
565 // corresponding to the following YYY descriptors shall
566 // be limited to data from Classes 01–09, and Class 31.
567 //
568 // It is nor processed here, it is already processed when parsing tree of expanded descriptors
569 // adjusting the proper struct \ref bufr_sequence_index_range no_data_present
570 break;
571
572 case 22:
573 // Quality information follows
574 // The values of Class 33 elements which follow relate to
575 // the data defined by the data present bit-map.
576 //
577 // Here we jsut activate the quality_active flag
578 b->state.quality_active = 1;
579 b->state.subs_active = 0;
580 b->state.retained_active = 0;
581 b->state.stat1_active = 0;
582 b->state.dstat_active = 0;
583 break;
584
585 case 23:
586 if ( d->y == 0 )
587 {
588 // Substituted operator values
589 //
590 // The substituted values which follow relate to the data
591 // defined by the data present bit-map.
592 b->state.quality_active = 0;
593 b->state.subs_active = 1;
594 b->state.retained_active = 0;
595 b->state.stat1_active = 0;
596 b->state.dstat_active = 0;
597 }
598 break;
599
600 case 24:
601 if ( d->y == 0 )
602 {
603 // First-order statistical values follow
604 //
605 // The statistical values which follow relate to the data
606 // defined by the data present bit-map.
607 b->state.quality_active = 0;
608 b->state.subs_active = 0;
609 b->state.retained_active = 0;
610 b->state.stat1_active = 1;
611 b->state.dstat_active = 0;
612 }
613 break;
614
615 case 25:
616 if ( d->y == 0 )
617 {
618 // Difference statistical values follow
619 //
620 // The statistical values which follow relate to the data
621 // defined by the data present bit-map.
622 b->state.quality_active = 0;
623 b->state.subs_active = 0;
624 b->state.retained_active = 0;
625 b->state.stat1_active = 0;
626 b->state.dstat_active = 1;
627 }
628 break;
629
630 case 32:
631 if ( d->y == 0 )
632 {
633 // Replaced/retained values follow
634 //
635 // The replaced/retained values which follow relate to the
636 // data defined by the data present bit-map.
637 b->state.quality_active = 0;
638 b->state.subs_active = 0;
639 b->state.retained_active = 1;
640 b->state.stat1_active = 0;
641 b->state.dstat_active = 0;
642 }
643 break;
644
645
646 case 35:
647 // Cancel backward data reference
648 //
649 // This operator terminates all previously defined backward
650 // reference and cancels any previously defined
651 // data present bit-map; it causes the next data present
652 // bit-map to refer to the data descriptors which
653 // immediately precede the operator to which it relates.
654
655 // Set the bitmap pointer to NULL.
656 b->state.bitmap = NULL;
657 break;
658
659 case 36:
660 // Define data present bit-map
661 //
662 // This operator defines the data present bit-map which
663 // follows for possible re-use; only one data present
664 // bit-map may be defined between this operator and the
665 // cancel use defined data present bit-map operator.
666
667 // Here we just add a bufrdeco_bitmap struct set the current bitmap
668 if ( bufrdeco_allocate_bitmap ( b ) )
669 {
670 // Cannot allocate another bitmap
671 return 1;
672 }
673 // Set the new current bitmap
674 b->state.bitmap = b->bitmap.bmap[b->bitmap.nba - 1];
675
676 // Now set the bitmaping backward count to 1 to flag that next replicator descriptor must be set it properly
677 b->state.bitmaping = 1;
678
679 break;
680
681 case 37:
682 // if y = 0000 use defined data present bit-map
683 // This operator causes the defined data present bit-map to be used again.
684 //
685 // if y = 255 Cancel use defined data present bit-map
686 // This operator cancels the re-use of the defined data present bit-map.
687 if ( d->y == 0 )
688 {
689 if ( b->bitmap.nba && b->state.bitmap == NULL )
690 b->state.bitmap = b->bitmap.bmap[b->bitmap.nba - 1];
691 }
692 else if ( d->y == 255 )
693 {
694 b->state.bitmap = NULL;
695 }
696 break;
697
698 case 41:
699 // This operator denotes the beginning of the definition of an event.
700 //
701 // An event, as defined for use with operators 2 41 000 and 2 42 000,
702 // is a set of one or more circumstances described using appropriate
703 // Table B descriptors along with their corresponding data values. The
704 // grouping of such descriptors together as a single “event” allows
705 // them to be collectively assigned as the target of a separate descriptor
706 // such as 0 33 045 or 0 33 046. When defining a circumstance within an
707 // event, descriptor 0 33 042 may be employed preceding the appropriate
708 // Table B descriptor in order to indicate that the corresponding value
709 // is actually a bound for a range of values.
710 //
711 // If y = 255 then it denotes the conclusion of the
712 // event definition that was begun via the previous 2 41 000
713 // operator.
714 //
715 // It is nor processed here, it is already processed when parsing tree of expanded descriptors
716 // adjusting the proper struct \ref bufr_sequence_index_range event
717 break;
718
719 case 42:
720 // This operator denotes the beginning of the definition of a conditioning event.
721 //
722 // An event, as defined for use with operators 2 41 000 and 2 42 000,
723 // is a set of one or more circumstances described using appropriate
724 // Table B descriptors along with their corresponding data values. The
725 // grouping of such descriptors together as a single “event” allows
726 // them to be collectively assigned as the target of a separate descriptor
727 // such as 0 33 045 or 0 33 046. When defining a circumstance within an
728 // event, descriptor 0 33 042 may be employed preceding the appropriate
729 // Table B descriptor in order to indicate that the corresponding value
730 // is actually a bound for a range of values.
731 //
732 // If y = 255 then it denotes the conclusion of the conditioning
733 // event definition that was begun via the previous 2 42 000
734 // operator.
735 //
736 // It is nor processed here, it is already processed when parsing tree of expanded descriptors
737 // adjusting the proper struct \ref bufr_sequence_index_range cond_event
738 break;
739
740 case 43:
741 // The values which follow are categorical forecast values
742 //
743 // A categorical forecast value represents a “best guess” from among a set of related,
744 // and often mutually exclusive, data values or categories. Operator 2 43 000 may be
745 // used to designate one or more values as categorical forecast values, and descriptor
746 // 0 33 042 may be employed preceding any such value in order to indicate that that value
747 // is actually a bound for a range of value
748 //
749 // If y == 255 then it denotes the conclusion of the definition of categorical forecast
750 // values that was begun via theprevious 2 43 000 operator.
751 //
752 // It is nor processed here, it is already processed when parsing tree of expanded descriptors
753 // adjusting the proper struct \ref bufr_sequence_index_range cat_forecast
754 break;
755
756 default:
757 // Still not processed: 21
758 snprintf ( b->error, sizeof ( b->error ), "%s(): Still no proccessed descriptor '%s' in "
759 "current library version %s \n", __func__, d->c, VERSION );
760 return 1;
761 }
762 return 0;
763}
764
765/*!
766 * \fn char *bufrdeco_get_f2_descriptor_explanation ( char *e, struct bufr_descriptor *d)
767 * \brief Return a stribg with brief explanation of descriptor when f = 2.
768 * \param e string with explanation as result
769 * \param d pointer to the struct \ref bufr_descriptor to explain
770 *
771 * \return As result, returns the explanation string or null if problems.
772 */
773char *bufrdeco_get_f2_descriptor_explanation ( char *e, size_t dim, struct bufr_descriptor *d )
774{
775 // check the input
776 bufrdeco_assert ( e != NULL && d != NULL && d->f == 2 )
777
778 switch ( d->x )
779 {
780 case 1:
781 if (d->y)
782 snprintf ( e, dim, "Change data width %d bits.", d->y - 128 );
783 else
784 snprintf ( e, dim, "Change data width 0 bits.");
785 break;
786
787 case 2:
788 if (d->y)
789 snprintf ( e, dim, "Change scale %d units.", d->y - 128 );
790 else
791 snprintf ( e, dim, "Change scale 0 units.");
792 break;
793
794 case 3:
795 if ( d->y != 255 )
796 snprintf ( e, dim, "Change reference values. Each new reference value has %d bits width.", d->y );
797 else
798 snprintf ( e, dim, "Change reference values concluded." );
799 break;
800
801 case 4:
802 snprintf ( e, dim,"Add associated field. Precede each data element with %d bits of information.", d->y );
803 break;
804
805 case 5:
806 snprintf ( e, dim, "Signify character. %d characters CCITT IA5 are inserted as a data field of %d x 8 bits in length.", d->y, d->y );
807 break;
808
809 case 6:
810 snprintf ( e, dim, "Signify data width. %d bits of data are described by immediately following descsriptor", d->y );
811 break;
812
813 case 7:
814 snprintf ( e, dim, "Increase scale, reference value and data width." );
815 break;
816
817 case 8:
818 snprintf ( e, dim, "Change width of CCITT IA5 field to %d characters instead of the indicated in table B", d->y );
819 break;
820
821 case 21:
822 snprintf ( e, dim, "**** Next %d descriptor(s) on this sequence level do not have data present ****", d->y );
823 break;
824
825 case 22:
826 snprintf ( e, dim, "Quality information follows. The values of Class 33 elements which follow relate to the data defined by the data present bit-map." );
827 break;
828
829 case 23:
830 if ( d->y == 0 )
831 snprintf ( e, dim, "Substituted values operator. The substituted values which follow relate to the data defined by the data present bit-map." );
832 else if ( d->y == 255 )
833 snprintf ( e, dim, "Substituted values marker operator. This operator shall signify a data item containing a substituted value." );
834 break;
835
836 case 24:
837 if ( d->y == 0 )
838 snprintf ( e, dim, "First-order statistical values follow." );
839 else if ( d->y == 255 )
840 snprintf ( e, dim, "First-order statistical values marker operator" );
841 break;
842
843 case 25:
844 if ( d->y == 0 )
845 snprintf ( e, dim,"Replaced/retained values follow." );
846 else if ( d->y == 255 )
847 snprintf ( e, dim, "Replaced/retained value marker operator" );
848 break;
849
850 case 32:
851 if ( d->y == 0 )
852 snprintf ( e, dim, "Difference statistical values follow." );
853 else if ( d->y == 255 )
854 snprintf ( e, dim, "Difference statistical values marker operator" );
855 break;
856
857 case 35:
858 snprintf ( e, dim, "Cancel backward data reference" );
859 break;
860
861 case 36:
862 snprintf ( e, dim, "Define data present bit-map" );
863 break;
864
865 case 37:
866 snprintf ( e, dim, " Use defined data present bit-map" );
867 break;
868
869 case 41:
870 if ( d->y == 0 )
871 snprintf ( e, dim, "@@@@ Event definition begins in next descriptor of this sequence level @@@@" );
872 else
873 snprintf ( e, dim, "@@@@ Event definition ends here @@@@" );
874 break;
875
876 case 42:
877 if ( d->y == 0 )
878 snprintf ( e, dim, "!!!! Conditioning event definition begins in next descriptor of this sequence level !!!!" );
879 else
880 snprintf ( e, dim, "!!!! Conditioning event definition ends here !!!!" );
881 break;
882
883 case 43:
884 if ( d->y == 0 )
885 snprintf ( e, dim, "&&&& Categorical forecast follow in next descriptor of this sequence level &&&&" );
886 else
887 snprintf ( e, dim, "&&&& Categorical forecast ends here &&&&" );
888 break;
889
890 default:
891 e[0] = 0; // void string
892 break;
893 }
894
895 return e;
896}
Include header file for bufrdeco library.
#define BUFR_NMAXSEQ
Maximum expected descriptors in a expanded sequence for a single subset.
Definition: bufrdeco.h:116
uint32_t buf_t
Type to set offsets and dimension of arrays or counters used in bufrdeco.
Definition: bufrdeco.h:346
#define bufrdeco_assert(__my_expr__)
Check a expression and exit if it fails.
Definition: bufrdeco.h:374
buf_t bufrdeco_print_json_separator(FILE *out)
Print the comma ',' separator in an output.
int bufrdeco_allocate_bitmap(struct bufrdeco *b)
allocate bitmap
uint32_t get_bits_as_char_array(char *target, uint8_t *has_data, uint8_t *source, buf_t *bit0_offset, buf_t bit_length)
#define BUFRDECO_COMPRESSED_REF_DATA_DESCRIPTOR_BITMASK
Bitmask for struct bufrdeco_compressed_ref which marks a data descriptor.
Definition: bufrdeco.h:611
#define BUFRDECO_OUTPUT_JSON_SUBSET_DATA
Bit mask to the member mask of struct bufrdeco to print bufr subset data in json format.
Definition: bufrdeco.h:299
#define DESCRIPTOR_HAVE_STRING_VALUE
Bit mask for a string in a struct bufr_atom_data.
Definition: bufrdeco.h:152
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
#define DESCRIPTOR_VALUE_MISSING
Bit mask for a missing value in a struct bufr_atom_data.
Definition: bufrdeco.h:140
const int32_t pow10pos_int[10]
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.
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_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_get_f2_descriptor_explanation(char *e, size_t dim, struct bufr_descriptor *d)
Definition: bufrdeco_f2.c:773
#define VERSION
Definition: config.h:8
Contains all the information for a single data related with a descriptor in a expanded squence.
Definition: bufrdeco.h:435
uint32_t mask
Definition: bufrdeco.h:437
char name[BUFR_TABLEB_NAME_LENGTH]
Definition: bufrdeco.h:438
struct bufr_descriptor desc
Definition: bufrdeco.h:436
char unit[BUFR_TABLEB_UNIT_LENGTH]
Definition: bufrdeco.h:439
char cval[BUFR_CVAL_LENGTH]
Definition: bufrdeco.h:443
BUFR descriptor.
Definition: bufrdeco.h:409
char c[12]
Definition: bufrdeco.h:414
uint32_t subsets
Definition: bufrdeco.h:810
uint8_t raw[BUFR_LEN]
Definition: bufrdeco.h:828
struct bufrdeco_bitmap * bmap[BUFR_MAX_BITMAPS]
Definition: bufrdeco.h:493
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 bufrdeco_bitmap * bitmap
Definition: bufrdeco.h:542
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 bufrdeco_bitmap_array bitmap
Definition: bufrdeco.h:980
uint32_t mask
Definition: bufrdeco.h:966
struct bufr_sec4 sec4
Definition: bufrdeco.h:972
struct bufrdeco_decoding_data_state state
Definition: bufrdeco.h:976
struct bufr_sec3 sec3
Definition: bufrdeco.h:971
FILE * out
Definition: bufrdeco.h:984
char error[1024]
Definition: bufrdeco.h:983