bufr2synop 0.24.0
Functions
bufrdeco_data.c File Reference

This file has the code which extract data from a bufr. More...

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

Go to the source code of this file.

Functions

struct bufrdeco_subset_sequence_databufrdeco_get_subset_sequence_data (struct bufrdeco *b)
 Parse and get a struct bufrdeco_subset_sequence_data. More...
 
int bufrdeco_decode_data_subset (struct bufrdeco *b)
 User interface to decode a BUFR subset. More...
 
int bufrdeco_increase_data_array (struct bufrdeco_subset_sequence_data *d)
 doubles the allocated space for a struct bufrdeco_subset_sequence_data whenever is posible More...
 
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 More...
 
int bufrdeco_decode_replicated_subsequence (struct bufrdeco_subset_sequence_data *d, struct bufr_replicator *r, struct bufrdeco *b)
 Decodes a replicated sequence. More...
 

Detailed Description

This file has the code which extract data from a bufr.

Definition in file bufrdeco_data.c.

Function Documentation

◆ bufrdeco_decode_data_subset()

int bufrdeco_decode_data_subset ( struct bufrdeco b)

User interface to decode a BUFR subset.

Parameters
bpointer to the base struct bufrdeco
Returns
Return 0 in case of success, 1 otherwise

Note that if succeeded the counter to current subset index is increased. Remember that in case of non compressed data we must to decode all previous subsets to get the desired one. In case of compressed we can access directly to a the desired subset

Definition at line 62 of file bufrdeco_data.c.

63{
66
67 // check arguments
68 bufrdeco_assert ( b != NULL );
69
70 s = & ( b->seq );
71 r = & ( b->refs );
72
73 if ( s == NULL || r == NULL )
74 {
75 snprintf ( b->error, sizeof ( b->error ), "%s(): Unspected NULL argument(s)\n", __func__ );
76 return 1;
77 }
78
79 // Check about parsed tree
80 if ( b->tree == NULL || b->tree->nseq == 0 )
81 {
82 snprintf ( b->error, sizeof ( b->error ), "%s(): Try to parse compressed data without parsed tree\n", __func__ );
83 return 1;
84 }
85
86 // First we init the subset sequence data
88 {
89 return 1;
90 }
91
92 // also we clean the possible defined bitmaps in prior subsets
93 if ( bufrdeco_clean_bitmaps ( b ) )
94 {
95 return 1;
96 }
97
98 // Then we get the data from an already parsed descriptor tree
99 if ( b->sec3.compressed )
100 {
101 if ( r->nd == 0 )
102 {
103 // case of compressed data and still not parsed
104 if ( bufrdeco_parse_compressed ( r, b ) )
105 {
106 return 1;
107 }
108 }
109 if ( bufr_decode_subset_data_compressed ( s, r, b ) )
110 {
111 return 1;
112 }
113 }
114 else
115 {
116 if ( bufrdeco_decode_subset_data_recursive ( s, NULL, b ) )
117 {
118 return 1;
119 }
120 }
121
122 // Finally we update the subset counter
123 ( b->state.subset ) ++;
124 return 0;
125}
int bufrdeco_clean_bitmaps(struct bufrdeco *b)
Clean all allocated bitmaps, but still is in memory.
#define bufrdeco_assert(__my_expr__)
Check a expression and exit if it fails.
Definition: bufrdeco.h:374
int bufrdeco_parse_compressed(struct bufrdeco_compressed_data_references *r, struct bufrdeco *b)
Preliminary parse of a compressed data bufr.
int bufrdeco_clean_subset_sequence_data(struct bufrdeco_subset_sequence_data *ba)
Cleans a struct bufrdeco_subset_sequence_data.
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_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
uint8_t compressed
Definition: bufrdeco.h:812
Manage an array of structs bufrdeco_compressed_ref.
Definition: bufrdeco.h:668
Contains all the information for a subset in a expanded squence This is a version to use with bufrdec...
Definition: bufrdeco.h:458
struct bufrdeco_subset_sequence_data seq
Definition: bufrdeco.h:979
struct bufrdeco_compressed_data_references refs
Definition: bufrdeco.h:978
struct bufrdeco_decoding_data_state state
Definition: bufrdeco.h:976
struct bufr_sec3 sec3
Definition: bufrdeco.h:971
struct bufrdeco_expanded_tree * tree
Definition: bufrdeco.h:975
char error[1024]
Definition: bufrdeco.h:983

References bufr_decode_subset_data_compressed(), bufrdeco_assert, bufrdeco_clean_bitmaps(), bufrdeco_clean_subset_sequence_data(), bufrdeco_decode_subset_data_recursive(), bufrdeco_parse_compressed(), bufr_sec3::compressed, bufrdeco::error, bufrdeco_compressed_data_references::nd, bufrdeco_expanded_tree::nseq, bufrdeco::refs, bufrdeco::sec3, bufrdeco::seq, bufrdeco::state, bufrdeco_decoding_data_state::subset, and bufrdeco::tree.

Referenced by bufrdeco_get_subset_sequence_data(), and bufrdeco_get_target_subset_sequence_data().

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

◆ bufrdeco_decode_replicated_subsequence()

int bufrdeco_decode_replicated_subsequence ( struct bufrdeco_subset_sequence_data d,
struct bufr_replicator r,
struct bufrdeco b 
)

Decodes a replicated sequence.

Parameters
dtarget struct bufrdeco_subset_sequence_data
rpointer to a struct bufr_replicator which manage the replication task
bpointer to the base struct bufrdeco
Returns
If succeeded return 0, 1 otherwise

Definition at line 509 of file bufrdeco_data.c.

510{
511 buf_t i, k;
512 buf_t ixloop; // Index for loop
513 buf_t ixd; // Index for descriptor
514 struct bufr_sequence *l = r->s; // sequence
515 struct bufr_replicator replicator;
516 char aux[80];
517
518 bufrdeco_assert ( b != NULL );
519
520 if ( d == NULL || r == NULL )
521 {
522 {
523 snprintf ( b->error, sizeof ( b->error ), "%s(): Unspected NULL argument(s)\n", __func__ );
524 return 1;
525 }
526 }
527
528 for ( ixloop = 0; ixloop < r->nloops; ixloop++ )
529 {
530 for ( ixd = 0; ixd < r->ndesc ; ixd ++ )
531 {
533 snprintf(aux, sizeof (aux), "\"Replicated\":\"Descriptor %u/%u of loop %u/%u\"", ixd + 1, ixloop + 1, r->ndesc, r->nloops);
534
535 i = ixd + r->ixdel + 1;
536 switch ( l->lseq[i].f )
537 {
538 case 0:
539 // Checks if no_data_present is active for this descriptor in this sequence
540 if ( l->no_data_present.active &&
541 i >= l->no_data_present.first &&
542 i <= l->no_data_present.last )
543 {
544 // If here then no_data_present has been active in this sequence
545 if ( l->lseq[i].x > 9 &&
546 l->lseq[i].x != 31 )
547 {
548 snprintf ( b->error, sizeof ( b->error ), "%s(): Getting data from table b with class other than 1-9,31 and no data present activated\n", __func__ );
549 return 1;
550 }
551 }
552
553 // Repeat the extraction of data if b->state.data_repetition_factor != 0
554 // It get data al least a time
555 do
556 {
557 // decrement counter if not zero
560
561 // Get data from table B
562 if ( bufrdeco_tableB_val ( & ( d->sequence[d->nd] ), b, & ( l->lseq[i] ) ) )
563 {
564 return 1;
565 }
567 {
569 bufrdeco_print_json_object_atom_data ( b->out, & ( d->sequence[d->nd] ), aux );
570 }
571 }
572 while ( b->state.data_repetition_factor != 0 );
573
574 // case of delayed replicator description and data
575 if ( l->lseq[i].x == 31 && ( l->lseq[i].y == 11 || l->lseq[i].y == 12 ) )
577
578
579 // Case of defining bitmap 0 31 031
580 if ( l->lseq[i].x == 31 && l->lseq[i].y == 31 && b->state.bitmaping )
581 {
582 if ( d->sequence[d->nd].val == 0.0 ) // Check if it is meaning present data
583 {
584 d->sequence[d->nd - b->state.bitmaping].is_bitmaped_by = d->nd;
585 d->sequence[d->nd].bitmap_to = d->nd - b->state.bitmaping;
586 // Add reference to bitmap
587 bufrdeco_add_to_bitmap ( b->bitmap.bmap[b->bitmap.nba - 1], d->nd - b->state.bitmaping, d->nd );
588 }
589 }
590
591 // Process quality data
592 if ( b->state.quality_active &&
593 l->lseq[i].x == 33 )
594 {
595 if ( ixloop == 0 )
596 {
597 k = b->bitmap.bmap[b->bitmap.nba - 1]->nq;
598 b->bitmap.bmap[b->bitmap.nba - 1]->quality[k] = d->nd;
599 if ( k < BUFR_MAX_QUALITY_DATA )
600 ( b->bitmap.bmap[b->bitmap.nba - 1]->nq )++;
601 else
602 {
603 snprintf ( b->error, sizeof ( b->error ), "%s(): No more space for quality vars in bitmap. Check BUFR_MAX_QUALITY_DATA\n", __func__ );
604 return 1;
605 }
606 }
607 d->sequence[d->nd].related_to = b->bitmap.bmap[b->bitmap.nba - 1]->bitmap_to[ixloop];
608 }
609
610 //case of first order statistics
611 if ( b->state.stat1_active &&
612 l->lseq[i].x == 8 && l->lseq[i].y == 23 )
613 {
614 if ( ixloop == 0 )
615 {
616 k = b->bitmap.bmap[b->bitmap.nba - 1]->ns1; // index un stqts
617 b->bitmap.bmap[b->bitmap.nba - 1]->stat1_desc[k] = d->nd; // Set the value of statistical parameter
618 // update the number of quality variables for the bitmap
619 if ( k < BUFR_MAX_QUALITY_DATA )
620 ( b->bitmap.bmap[b->bitmap.nba - 1]->ns1 )++;
621 else
622 {
623 snprintf ( b->error, sizeof ( b->error ), "%s(): No more space for first order statistic vars in bitmap. Check BUFR_MAX_QUALITY_DATA\n", __func__ );
624 return 1;
625 }
626 }
627 d->sequence[d->nd].related_to = b->bitmap.bmap[b->bitmap.nba - 1]->bitmap_to[ixloop];
628 }
629
630 //case of difference statistics
631 if ( b->state.dstat_active &&
632 l->lseq[i].x == 8 && l->lseq[i].y == 24 )
633 {
634 if ( ixloop == 0 )
635 {
636 k = b->bitmap.bmap[b->bitmap.nba - 1]->nds; // index in stats
637 b->bitmap.bmap[b->bitmap.nba - 1]->dstat_desc[k] = d->nd; // Set the value of statistical parameter
638 // update the number of quality variables for the bitmap
639 if ( k < BUFR_MAX_QUALITY_DATA )
640 ( b->bitmap.bmap[b->bitmap.nba - 1]->nds )++;
641 else
642 {
643 snprintf ( b->error, sizeof ( b->error ), "%s(): No more space for difference statistic vars in bitmap. Check BUFR_MAX_QUALITY_DATA\n", __func__ );
644 return 1;
645 }
646 }
647 d->sequence[d->nd].related_to = b->bitmap.bmap[b->bitmap.nba - 1]->bitmap_to[ixloop];
648 }
649
650 if ( d->nd < ( d->dim - 1 ) )
651 {
652 ( d->nd ) ++;
653 }
654 else if ( bufrdeco_increase_data_array ( d ) == 0 )
655 {
656 ( d->nd ) ++;
657 }
658 else
659 {
660 snprintf ( b->error, sizeof ( b->error ), "%s(): No more bufr_atom_data available. Check BUFR_NMAXSEQ\n", __func__ );
661 return 1;
662 }
663 break;
664
665 case 1:
666 // Case of replicator descriptor
667 replicator.s = l;
668 replicator.ixrep = i;
670 {
673 }
674
675 if ( l->lseq[i].y != 0 )
676 {
677 // no delayed
678 replicator.ixdel = i;
679 replicator.ndesc = l->lseq[i].x;
680 replicator.nloops = l->lseq[i].y;
681 bufrdeco_decode_replicated_subsequence ( d, &replicator, b );
682 ixd += replicator.ndesc; // update ixd properly
683 }
684 else
685 {
686 // case of delayed;
687 replicator.ixdel = i + 1;
688 replicator.ndesc = l->lseq[i].x;
689 // here we read ndesc from delayed replicator descriptor
690 if ( bufrdeco_tableB_val ( & ( d->sequence[d->nd] ), b, & ( l->lseq[i + 1] ) ) )
691 {
692 return 1;
693 }
695 {
697 bufrdeco_print_json_object_atom_data ( b->out, & ( d->sequence[d->nd] ), aux );
698 }
699 replicator.nloops = ( size_t ) d->sequence[d->nd].val;
700 if ( d->nd < ( d->dim - 1 ) )
701 {
702 ( d->nd ) ++;
703 }
704 else if ( bufrdeco_increase_data_array ( d ) == 0 )
705 {
706 ( d->nd ) ++;
707 }
708 else
709 {
710 snprintf ( b->error, sizeof ( b->error ), "%s(): No more bufr_atom_data available. Check BUFR_NMAXSEQ\n", __func__ );
711 return 1;
712 }
713 bufrdeco_decode_replicated_subsequence ( d, &replicator, b );
714 ixd += replicator.ndesc + 1; // update ixd properly
715 }
716 //i = r->ixdel + r->ndesc; // update i properly
717 break;
718
719 case 2:
720 // Case of operator descriptor
721 if ( bufrdeco_parse_f2_descriptor ( d, & ( l->lseq[i] ), b ) )
722 {
723 return 1;
724 }
725
727 {
730 }
731 // Case of subsituted values
732 if ( b->state.subs_active && l->lseq[i].x == 23 && l->lseq[i].y == 255 )
733 {
734 k = b->bitmap.bmap[b->bitmap.nba - 1]->bitmap_to[ixloop]; // ref which is bitmaped_to
735 // Get the bitmaped descriptor k
736 if ( ixloop == 0 )
737 {
738 b->bitmap.bmap[b->bitmap.nba - 1]->subs = d->nd;
739 }
740 if ( bufrdeco_tableB_val ( & ( d->sequence[d->nd] ), b, & ( l->lseq[k] ) ) )
741 {
742 return 1;
743 }
744 d->sequence[d->nd].related_to = b->bitmap.bmap[b->bitmap.nba - 1]->bitmap_to[ixloop];
745
746 if ( d->nd < ( d->dim - 1 ) )
747 {
748 d->nd += 1;
749 }
750 else
751 {
752 snprintf ( b->error, sizeof ( b->error ), "%s(): Reached limit. Consider increas BUFR_NMAXSEQ\n", __func__ );
753 return 1;
754 }
755 }
756
757 // Case of replaced/retained values
758 if ( b->state.retained_active && l->lseq[i].x == 32 && l->lseq[i].y == 255 )
759 {
760 k = b->bitmap.bmap[b->bitmap.nba - 1]->bitmap_to[ixloop];
761 // Get the bitmaped descriptor k
762 if ( ixloop == 0 )
763 {
764 b->bitmap.bmap[b->bitmap.nba - 1]->retain = d->nd;
765 }
766 if ( bufrdeco_tableB_val ( & ( d->sequence[d->nd] ), b, & ( l->lseq[k] ) ) )
767 {
768 return 1;
769 }
770
771 d->sequence[d->nd].related_to = b->bitmap.bmap[b->bitmap.nba - 1]->bitmap_to[ixloop];
772 if ( d->nd < ( d->dim - 1 ) )
773 {
774 d->nd += 1;
775 }
776 else
777 {
778 snprintf ( b->error, sizeof ( b->error ), "%s(): Reached limit. Consider increas BUFR_NMAXSEQ\n", __func__ );
779 return 1;
780 }
781 }
782
783 // Case of first order statistics
784 //
785 // This operator shall signify a data item containing a
786 // first-order statistical value of the type indicated by
787 // the preceding 0 08 023 element descriptor; the
788 // element descriptor to which the first-order statistic
789 // relates is obtained by the application of the data
790 // present bit-map associated with the first-order
791 // statistical values follow operator; first-order statistical
792 // values shall be represented as defined by this element
793 // descriptor.
794 if ( b->state.stat1_active && l->lseq[i].x == 24 && l->lseq[i].y == 255 )
795 {
796 k = b->bitmap.bmap[b->bitmap.nba - 1]->bitmap_to[ixloop];
797
798 // Get the bitmaped descriptor k
799 if ( ixloop == 0 )
800 {
801 b->bitmap.bmap[b->bitmap.nba - 1]->stat1[b->bitmap.bmap[b->bitmap.nba - 1]->ns1 -1] = d->nd;
802 }
803
804 if ( bufrdeco_tableB_val ( & ( d->sequence[d->nd] ), b, & ( l->lseq[k] ) ) )
805 {
806 return 1;
807 }
808
809 d->sequence[d->nd].related_to = b->bitmap.bmap[b->bitmap.nba - 1]->bitmap_to[ixloop];
810 if ( d->nd < ( d->dim - 1 ) )
811 {
812 d->nd += 1;
813 }
814 else
815 {
816 snprintf ( b->error, sizeof ( b->error ), "%s(): Reached limit. Consider increas BUFR_NMAXSEQ\n", __func__ );
817 return 1;
818 }
819 }
820
821 // Case of difference statistics
822 //
823 // This operator shall signify a data item containing a
824 // difference statistical value of the type indicated by
825 // the preceding 0 08 024 element descriptor; the
826 // element descriptor to which the difference statistical
827 // value relates is obtained by the application of the
828 // data present bit-map associated with the difference
829 // statistical values follow operator; difference statistical
830 // values shall be represented as defined by this
831 // element descriptor, but with a reference value of –2**n
832 // and a data width of (n+1), where n is the data width
833 // given by the original descriptor. This special reference
834 // value allows the statistical difference values to
835 // be centred around zero.
836 if ( b->state.dstat_active && l->lseq[i].x == 25 && l->lseq[i].y == 255 )
837 {
838 k = b->bitmap.bmap[b->bitmap.nba - 1]->bitmap_to[ixloop];
839
840 // Get the bitmaped descriptor k
841 if ( ixloop == 0 )
842 {
843 b->bitmap.bmap[b->bitmap.nba - 1]->stat1[b->bitmap.bmap[b->bitmap.nba - 1]->nds -1] = d->nd;
844 }
845
846 // in bufrdeco_tableB_val() is taken into acount when is difference statistics active
847 if ( bufrdeco_tableB_val ( & ( d->sequence[d->nd] ), b, & ( l->lseq[k] ) ) )
848 {
849 return 1;
850 }
851
852 /*d->sequence[d->nd].ref = - ( ( int32_t ) 1 << d->sequence[d->nd].bits );
853 d->sequence[d->nd].bits++;*/
854 d->sequence[d->nd].related_to = b->bitmap.bmap[b->bitmap.nba - 1]->bitmap_to[ixloop];
855 if ( d->nd < ( d->dim - 1 ) )
856 {
857 d->nd += 1;
858 }
859 else
860 {
861 snprintf ( b->error, sizeof ( b->error ), "%s(): Reached limit. Consider increas BUFR_NMAXSEQ\n", __func__ );
862 return 1;
863 }
864 }
865
866 break;
867
868 case 3:
871 if ( bufrdeco_decode_subset_data_recursive ( d, l->sons[i], b ) )
872 {
873 return 1;
874 }
875 break;
876
877 default:
878 // this case is not possible
879 snprintf ( b->error, sizeof ( b->error ), "%s(): Found bad 'f' in descriptor\n", __func__ );
880 return 1;
881 break;
882 }
883 }
884 }
885 return 0;
886}
uint32_t buf_t
Type to set offsets and dimension of arrays or counters used in bufrdeco.
Definition: bufrdeco.h:346
buf_t bufrdeco_print_json_separator(FILE *out)
Print the comma ',' separator in an output.
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
buf_t bufrdeco_print_json_object_operator_descriptor(FILE *out, struct bufr_descriptor *d, char *aux)
print an operator desciptor as a json object
#define BUFR_MAX_QUALITY_DATA
Max amount of quality data which is maped by a struct bufrdeco_bitmap element.
Definition: bufrdeco.h:226
buf_t bufrdeco_print_json_object_replicator_descriptor(FILE *out, struct bufr_descriptor *d, char *aux)
print an operator desciptor as a json object
#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
int bufrdeco_tableB_val(struct bufr_atom_data *a, struct bufrdeco *b, struct bufr_descriptor *d)
Get data from a table B descriptor.
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_increase_data_array(struct bufrdeco_subset_sequence_data *d)
doubles the allocated space for a struct bufrdeco_subset_sequence_data whenever is posible
int bufrdeco_decode_replicated_subsequence(struct bufrdeco_subset_sequence_data *d, struct bufr_replicator *r, struct bufrdeco *b)
Decodes a replicated sequence.
buf_t related_to
Definition: bufrdeco.h:449
double val
Definition: bufrdeco.h:440
buf_t is_bitmaped_by
Definition: bufrdeco.h:447
buf_t bitmap_to
Definition: bufrdeco.h:448
store the information when parsing related to replicators
Definition: bufrdeco.h:422
struct bufr_sequence * s
Definition: bufrdeco.h:423
Stores an unexpanded sequence of descriptors.
Definition: bufrdeco.h:572
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 * sons[NMAXSEQ_DESCRIPTORS]
Definition: bufrdeco.h:584
struct bufrdeco_bitmap * bmap[BUFR_MAX_BITMAPS]
Definition: bufrdeco.h:493
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 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
struct bufr_atom_data * sequence
Definition: bufrdeco.h:462
struct bufrdeco_bitmap_array bitmap
Definition: bufrdeco.h:980
uint32_t mask
Definition: bufrdeco.h:966
FILE * out
Definition: bufrdeco.h:984

References bufr_sequence_index_range::active, bufrdeco::bitmap, bufr_atom_data::bitmap_to, bufrdeco_bitmap::bitmap_to, bufrdeco_decoding_data_state::bitmaping, bufrdeco_bitmap_array::bmap, BUFR_MAX_QUALITY_DATA, bufrdeco_add_to_bitmap(), bufrdeco_assert, bufrdeco_decode_replicated_subsequence(), bufrdeco_decode_subset_data_recursive(), bufrdeco_increase_data_array(), BUFRDECO_OUTPUT_JSON_SUBSET_DATA, bufrdeco_parse_f2_descriptor(), bufrdeco_print_json_object_atom_data(), bufrdeco_print_json_object_operator_descriptor(), bufrdeco_print_json_object_replicator_descriptor(), bufrdeco_print_json_separator(), bufrdeco_tableB_val(), bufrdeco_decoding_data_state::data_repetition_factor, bufrdeco_subset_sequence_data::dim, bufrdeco_decoding_data_state::dstat_active, bufrdeco_bitmap::dstat_desc, bufrdeco::error, bufr_descriptor::f, bufr_sequence_index_range::first, bufr_atom_data::is_bitmaped_by, bufr_replicator::ixdel, bufr_replicator::ixrep, bufr_sequence::lseq, bufrdeco::mask, bufrdeco_bitmap_array::nba, bufrdeco_subset_sequence_data::nd, bufr_replicator::ndesc, bufrdeco_bitmap::nds, bufr_replicator::nloops, bufr_sequence::no_data_present, bufrdeco_bitmap::nq, bufrdeco_bitmap::ns1, bufrdeco::out, bufrdeco_bitmap::quality, bufrdeco_decoding_data_state::quality_active, bufr_atom_data::related_to, bufrdeco_bitmap::retain, bufrdeco_decoding_data_state::retained_active, bufr_replicator::s, bufrdeco_subset_sequence_data::sequence, bufr_sequence::sons, bufrdeco_bitmap::stat1, bufrdeco_decoding_data_state::stat1_active, bufrdeco_bitmap::stat1_desc, bufrdeco::state, bufrdeco_bitmap::subs, bufrdeco_decoding_data_state::subs_active, bufr_atom_data::val, bufr_descriptor::x, and bufr_descriptor::y.

Referenced by 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_decode_subset_data_recursive()

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

Parameters
dpointer to the target struct bufrdeco_subset_sequence_data
lpointer to the source struct bufr_sequence
bpointer to the base struct bufrdeco
Returns
0 in case of success, 1 otherwise

Definition at line 171 of file bufrdeco_data.c.

172{
173 size_t i, j, k;
174 struct bufr_sequence *seq;
175 struct bufr_replicator replicator;
176
177 bufrdeco_assert ( b != NULL );
178
179 if ( d == NULL )
180 {
181 snprintf ( b->error, sizeof ( b->error ), "%s(): Unspected NULL argument(s)\n", __func__ );
182 return 1;
183 }
184
185
186 // clean subset data, if l == NULL we are at the begining of a subset, level 0
187 if ( l == NULL )
188 {
189
190 //memset ( s, 0, sizeof ( struct bufr_subset_sequence_data ) );
191 d->nd = 0;
192 d->ss = b->state.subset;
193 seq = & ( b->tree->seq[0] );
194 if ( b->state.subset == 0 )
195 {
196 b->state.bit_offset = 0;
197 }
198
199 // Manage bit offset of the subset
200 if ( b->state.subset < BUFR_MAX_SUBSETS )
201 {
202 // No bit offset still set for this subset
203 if ( b->offsets.ofs[b->state.subset] == 0 )
204 {
205 if ( b->offsets.nr <= b->state.subset )
206 b->offsets.nr = b->state.subset + 1;
208 }
209 else
210 {
211 // offset is already set, so we can go directly to the data
213 }
214 }
215 else
216 {
217 snprintf ( b->error, sizeof ( b->error ), "%s(): Cannot manage subset bit offset for subset %u. Consider increase BUFR_MAX_SUBSETS\n",
218 __func__, b->state.subset );
219 return 1;
220 }
221
222 // also reset reference and bits inc
223 b->state.added_bit_length = 0;
224 b->state.added_scale = 0;
225 b->state.added_reference = 0;
226 b->state.assoc_bits = 0;
227 b->state.changing_reference = 255;
228 b->state.fixed_ccitt = 0;
230 b->state.factor_reference = 1;
231 b->state.quality_active = 0;
232 b->state.subs_active = 0;
233 b->state.retained_active = 0;
234 b->state.stat1_active = 0;
235 b->state.dstat_active = 0;
236 b->state.bitmaping = 0;
238 b->state.bitmap = NULL;
239
240 // print prologue if needed
243
244 }
245 else
246 {
247 seq = l;
248 }
249
250 // loop for a sequence
252 {
253 //if (seq->iseq)
254 // bufrdeco_print_json_separator ( b->out ); // print json array element separator
256 }
257
258 for ( i = 0, j = 0 ; i < seq->ndesc ; i++ )
259 {
260 switch ( seq->lseq[i].f )
261 {
262 case 0:
263
264 // Checks if no_data_present is active for this descriptor in this sequence
265 if ( seq->no_data_present.active &&
266 i >= seq->no_data_present.first &&
267 i <= seq->no_data_present.last )
268 {
269 // If here then no_data_present has been active in this sequence
270 if ( seq->lseq[i].x > 9 &&
271 seq->lseq[i].x != 31 )
272 {
273 snprintf ( b->error, sizeof ( b->error ), "%s(): Getting data from table b with class other than 1-9,31 and no data present activated\n",
274 __func__ );
275 return 1;
276 }
277
278 }
279
280
281 // Repeat the extraction of data if b->state.data_repetition_factor != 0
282 // It get data al least a time
283 // It is supossed that prior parsed descriptor was 0 31 011 or 0 31 012 which set de value of repetition data
284 do
285 {
286 // decrement counter if not zero
289
290 // Get data from table B
291 if ( bufrdeco_tableB_val ( & ( d->sequence[d->nd] ), b, & ( seq->lseq[i] ) ) )
292 {
293 return 1;
294 }
296 {
297 if (j)
299 bufrdeco_print_json_object_atom_data ( b->out, & ( d->sequence[d->nd] ), NULL );
300 j++;
301 }
302 }
303 while ( b->state.data_repetition_factor != 0 );
304
305 // case of delayed replicator description and data
306 if ( seq->lseq[i].x == 31 && ( seq->lseq[i].y == 11 || seq->lseq[i].y == 12 ) )
307 {
309 }
310
311 //case of first order statistics
312 if ( b->state.stat1_active &&
313 seq->lseq[i].x == 8 && seq->lseq[i].y == 23 )
314 {
315 k = b->bitmap.bmap[b->bitmap.nba - 1]->ns1; // index un stqts
316 b->bitmap.bmap[b->bitmap.nba - 1]->stat1_desc[k] = d->nd; // Set the value of statistical parameter
317 // update the number of quality variables for the bitmap
318 if ( k < BUFR_MAX_QUALITY_DATA )
319 ( b->bitmap.bmap[b->bitmap.nba - 1]->ns1 )++;
320 else
321 {
322 snprintf ( b->error, sizeof ( b->error ), "%s(): No more space for first order statistic vars in bitmap. Check BUFR_MAX_QUALITY_DATA\n",
323 __func__ );
324 return 1;
325 }
326 }
327
328 //case of difference statistics
329 if ( b->state.dstat_active &&
330 seq->lseq[i].x == 8 && seq->lseq[i].y == 24 )
331 {
332 k = b->bitmap.bmap[b->bitmap.nba - 1]->nds; // index in stats
333 b->bitmap.bmap[b->bitmap.nba - 1]->dstat_desc[k] = d->nd; // Set the value of statistical parameter
334 // update the number of quality variables for the bitmap
335 if ( k < BUFR_MAX_QUALITY_DATA )
336 ( b->bitmap.bmap[b->bitmap.nba - 1]->nds )++;
337 else
338 {
339 snprintf ( b->error, sizeof ( b->error ), "%s(): No more space for difference statistic vars in bitmap. Check BUFR_MAX_QUALITY_DATA\n",
340 __func__ );
341 return 1;
342 }
343 }
344
345
346
347 // Add info about common sequence to which bufr_atom_data belongs
348 d->sequence[d->nd].seq = seq;
349 d->sequence[d->nd].ns = i;
350
351 //bufr_print_atom_data_stdout(& ( d->sequence[d->nd] ));
352 if ( d->nd < ( d->dim - 1 ) )
353 {
354 ( d->nd ) ++;
355 }
356 else if ( bufrdeco_increase_data_array ( d ) == 0 )
357 {
358 ( d->nd ) ++;
359 }
360 else
361 {
362 snprintf ( b->error, sizeof ( b->error ), "%s(): No more bufr_atom_data available. Check BUFR_NMAXSEQ\n", __func__ );
363 return 1;
364 }
365 break;
366
367 case 1:
368 // Case of replicator descriptor
369 replicator.s = seq;
370 replicator.ixrep = i;
372 {
373 if (j)
376 j++;
377 }
378
379 if ( seq->lseq[i].y != 0 )
380 {
381 // no delayed
382 replicator.ixdel = i;
383 replicator.ndesc = seq->lseq[i].x;
384 replicator.nloops = seq->lseq[i].y;
385
386 // Check if this replicator is for a bit-map defining
387 if ( b->state.bitmaping )
388 {
389 b->state.bitmaping = replicator.nloops; // set it properly
390 }
391
392 bufrdeco_decode_replicated_subsequence ( d, &replicator, b );
393
394 // and then set again bitamping to 0, because it is finished
395 b->state.bitmaping = 0;
396
397 i += replicator.ndesc;
398 }
399 else
400 {
401 // case of delayed;
402 replicator.ixdel = i + 1;
403 replicator.ndesc = seq->lseq[i].x;
404 // here we read ndesc from delayed replicator descriptor
405 if ( bufrdeco_tableB_val ( & ( d->sequence[d->nd] ), b, & ( seq->lseq[i + 1] ) ) )
406 {
407 return 1;
408 }
410 {
411 if (j)
413 bufrdeco_print_json_object_atom_data ( b->out, & ( d->sequence[d->nd] ), NULL );
414 j++;
415 }
416 // Add info about common sequence to which bufr_atom_data belongs
417 d->sequence[d->nd].seq = seq;
418 d->sequence[d->nd].ns = i + 1;
419
420 replicator.nloops = ( size_t ) ( d->sequence[d->nd].val );
421
422 // Check if this replicator is for a bit-map defining
423 if ( b->state.bitmaping )
424 {
425 b->state.bitmaping = replicator.nloops; // set it properly
426 }
427
428 if ( d->nd < ( d->dim - 1 ) )
429 {
430 ( d->nd ) ++;
431 }
432 else if ( bufrdeco_increase_data_array ( d ) == 0 )
433 {
434 ( d->nd ) ++;
435 }
436 else
437 {
438
439 snprintf ( b->error, sizeof ( b->error ), "%s(): No more bufr_atom_data available. Check BUFR_NMAXSEQ\n", __func__ );
440 return 1;
441 }
442 bufrdeco_decode_replicated_subsequence ( d, &replicator, b );
443
444 // and then set again bitamping to 0, because it is finished
445 b->state.bitmaping = 0;
446
447 i += replicator.ndesc + 1;
448 }
449 //i = replicator.ixdel + replicator.ndesc; // update i properly
450 break;
451
452 case 2:
453 // Case of operator descriptor
454 if ( bufrdeco_parse_f2_descriptor ( d, & ( seq->lseq[i] ), b ) )
455 {
456 return 1;
457 }
459 {
460 if (j)
462 bufrdeco_print_json_object_operator_descriptor ( b->out, & ( seq->lseq[i] ), NULL );
463 j++;
464 }
465 break;
466
467 case 3:
469 {
470 if (j)
471 bufrdeco_print_json_separator ( b->out ); // print json array element separator
472 j++;
473 }
474 // Case of sequence descriptor
475 if ( bufrdeco_decode_subset_data_recursive ( d, seq->sons[i], b ) )
476 {
477 return 1;
478 }
479 break;
480
481 default:
482 // this case is not possible
483 snprintf ( b->error, sizeof ( b->error ), "%s(): Found bad 'f' in descriptor '%s' \n", seq->lseq[i].c, __func__ );
484 return 1;
485 break;
486 }
487 }
488
489 // End of sequence
492
493 // End of data subset
494 if ( l == NULL && ( b->mask & BUFRDECO_OUTPUT_JSON_SUBSET_DATA ) )
496
497 return 0;
498
499};
buf_t bufrdeco_print_json_subset_data_prologue(FILE *out, struct bufrdeco *b)
Definition: bufrdeco_json.c:58
buf_t bufrdeco_print_json_sequence_descriptor_final(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)
Definition: bufrdeco_json.c:94
#define BUFR_MAX_SUBSETS
Max number of subsets in the array off bitoffset subset marks the bufrdeco library can manage.
Definition: bufrdeco.h:244
buf_t bufrdeco_print_json_subset_data_epilogue(FILE *out)
Definition: bufrdeco_json.c:77
struct bufr_sequence * seq
Definition: bufrdeco.h:445
char c[12]
Definition: bufrdeco.h:414
buf_t ndesc
Definition: bufrdeco.h:575
struct bufrdeco_bitmap * bitmap
Definition: bufrdeco.h:542
struct bufr_sequence seq[BUFR_MAX_EXPANDED_SEQUENCES]
Definition: bufrdeco.h:598
buf_t ofs[BUFR_MAX_SUBSETS]
Definition: bufrdeco.h:687
struct bufrdeco_subset_bit_offsets offsets
Definition: bufrdeco.h:977

References bufr_sequence_index_range::active, bufrdeco_decoding_data_state::added_bit_length, bufrdeco_decoding_data_state::added_reference, bufrdeco_decoding_data_state::added_scale, bufrdeco_decoding_data_state::assoc_bits, bufrdeco_decoding_data_state::bit_offset, bufrdeco_decoding_data_state::bitmap, bufrdeco::bitmap, bufrdeco_decoding_data_state::bitmaping, bufrdeco_bitmap_array::bmap, BUFR_MAX_QUALITY_DATA, BUFR_MAX_SUBSETS, bufrdeco_assert, bufrdeco_decode_replicated_subsequence(), bufrdeco_decode_subset_data_recursive(), bufrdeco_increase_data_array(), BUFRDECO_OUTPUT_JSON_SUBSET_DATA, bufrdeco_parse_f2_descriptor(), bufrdeco_print_json_object_atom_data(), bufrdeco_print_json_object_operator_descriptor(), bufrdeco_print_json_object_replicator_descriptor(), bufrdeco_print_json_separator(), bufrdeco_print_json_sequence_descriptor_final(), bufrdeco_print_json_sequence_descriptor_header(), bufrdeco_print_json_subset_data_epilogue(), bufrdeco_print_json_subset_data_prologue(), bufrdeco_tableB_val(), bufr_descriptor::c, bufrdeco_decoding_data_state::changing_reference, bufrdeco_decoding_data_state::data_repetition_factor, bufrdeco_subset_sequence_data::dim, bufrdeco_decoding_data_state::dstat_active, bufrdeco_bitmap::dstat_desc, bufrdeco::error, bufr_descriptor::f, bufrdeco_decoding_data_state::factor_reference, bufr_sequence_index_range::first, bufrdeco_decoding_data_state::fixed_ccitt, bufr_replicator::ixdel, bufr_replicator::ixrep, bufrdeco_decoding_data_state::local_bit_reserved, bufr_sequence::lseq, bufrdeco::mask, bufrdeco_bitmap_array::nba, bufrdeco_subset_sequence_data::nd, bufr_replicator::ndesc, bufr_sequence::ndesc, bufrdeco_bitmap::nds, bufr_replicator::nloops, bufr_sequence::no_data_present, bufrdeco_subset_bit_offsets::nr, bufr_atom_data::ns, bufrdeco_bitmap::ns1, bufrdeco::offsets, bufrdeco_subset_bit_offsets::ofs, bufrdeco::out, bufrdeco_decoding_data_state::quality_active, bufrdeco_decoding_data_state::retained_active, bufr_replicator::s, bufr_atom_data::seq, bufrdeco_expanded_tree::seq, bufrdeco_subset_sequence_data::sequence, bufr_sequence::sons, bufrdeco_subset_sequence_data::ss, bufrdeco_decoding_data_state::stat1_active, bufrdeco_bitmap::stat1_desc, bufrdeco::state, bufrdeco_decoding_data_state::subs_active, bufrdeco_decoding_data_state::subset, bufrdeco::tree, bufr_atom_data::val, bufr_descriptor::x, and bufr_descriptor::y.

Referenced by bufrdeco_decode_data_subset(), 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_get_subset_sequence_data()

struct bufrdeco_subset_sequence_data * bufrdeco_get_subset_sequence_data ( struct bufrdeco b)

Parse and get a struct bufrdeco_subset_sequence_data.

Parameters
bbasic container struct bufrdeco
Returns
If succeeded returns a pointer to the struct bufrdeco_subset_sequence_data with the results for a subset, otherwise returns NULL

Note that if succeeded the counter to current subset index is increased. Remember that in case of non compressed data we must to decode all previous subsets to get the desired one. In case of compressed we can access directly to a the desired subset

Definition at line 39 of file bufrdeco_data.c.

40{
41 bufrdeco_assert ( b != NULL );
42
44 {
45 return NULL;
46 }
47 return & ( b->seq );
48}
int bufrdeco_decode_data_subset(struct bufrdeco *b)
User interface to decode a BUFR subset.
Definition: bufrdeco_data.c:62

References bufrdeco_assert, bufrdeco_decode_data_subset(), and bufrdeco::seq.

Referenced by bufrdeco_get_target_subset_sequence_data().

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

◆ bufrdeco_increase_data_array()

int bufrdeco_increase_data_array ( struct bufrdeco_subset_sequence_data d)

doubles the allocated space for a struct bufrdeco_subset_sequence_data whenever is posible

Parameters
dpointer to source struct bufrdeco_subset_sequence_data
Returns
0 when success, otherwise return 1 and the struct is unmodified

The amount of data in a bufr must be huge. In a first moment, the dimension of a sequence of structs bufr_atom_data is BUFR_NMAXSEQ but may be increased. This function task is try to double the allocated dimension and reallocate it.

Definition at line 139 of file bufrdeco_data.c.

140{
141 bufrdeco_assert ( d != NULL );
142
143 if ( d->dim < ( BUFR_NMAXSEQ * 8 ) ) // check if reached the limit
144 {
145 if ( ( d->sequence = ( struct bufr_atom_data * ) realloc ( ( void * ) d->sequence,
146 d->dim * 2 * sizeof ( struct bufr_atom_data ) ) ) == NULL )
147 {
148 return 1;
149 }
150 else
151 {
152 d->dim *= 2;
153 return 0;
154 }
155 }
156 else
157 {
158 return 1;
159 }
160}
#define BUFR_NMAXSEQ
Maximum expected descriptors in a expanded sequence for a single subset.
Definition: bufrdeco.h:116
Contains all the information for a single data related with a descriptor in a expanded squence.
Definition: bufrdeco.h:435

References BUFR_NMAXSEQ, bufrdeco_assert, bufrdeco_subset_sequence_data::dim, and bufrdeco_subset_sequence_data::sequence.

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: