bufr2synop 0.24.0
Functions | Variables
bufrdeco_json.c File Reference

This file includes the code to get data from a BUFR report using bufrdeco library. More...

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

Go to the source code of this file.

Functions

void print_usage (void)
 
int read_args (int _argc, char *_argv[])
 read the arguments from stdio More...
 
int set_bufrdeco_mask (struct bufrdeco *b)
 
int main (int argc, char *argv[])
 

Variables

struct bufrdeco BUFR
 
int EXTRACT
 
char ENTRADA [256]
 
int PRINT_JSON_SEC0
 
int PRINT_JSON_SEC1
 
int PRINT_JSON_SEC2
 
int PRINT_JSON_SEC3
 
int PRINT_JSON_SEC4
 
int PRINT_JSON_EXPANDED_TREE
 
int FIRST_SUBSET
 
int LAST_SUBSET
 

Detailed Description

This file includes the code to get data from a BUFR report using bufrdeco library.

Definition in file bufrdeco_json.c.

Function Documentation

◆ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 188 of file bufrdeco_json.c.

189{
190 size_t subset, first_subset, last_subset;
192
193 if ( read_args ( argc, argv ) < 0 )
194 exit ( EXIT_FAILURE );
195
196 bufrdeco_init ( &BUFR );
197
198 // sets the bit mask according to readed args
200
201 // Check read file
202 if ( EXTRACT )
203 {
205 {
206 printf ( "%s", BUFR.error );
207 exit ( EXIT_FAILURE );
208 }
209 }
210 else if ( bufrdeco_read_bufr ( &BUFR, ENTRADA ) )
211 {
212 printf ( "%s", BUFR.error );
213 exit ( EXIT_FAILURE );
214 }
215
216 if ( bufrdeco_parse_tree ( &BUFR ) )
217 {
218 printf ( "# %s", BUFR.error );
219 bufrdeco_close ( &BUFR );
220 exit ( EXIT_FAILURE );
221 }
222
225
226 first_subset = FIRST_SUBSET;
227 last_subset = LAST_SUBSET;
228
229 // Fix first and last subset
230 if ( first_subset >= BUFR.sec3.subsets )
231 {
232 fprintf ( BUFR.err, "Error, first subset to parse is greater than subset number in BUFR\n" );
233 exit ( EXIT_FAILURE );
234 }
235
236 if ( last_subset < first_subset )
237 last_subset = BUFR.sec3.subsets - 1;
238
239
240 for ( subset = first_subset; subset <= last_subset ; subset++ )
241 {
242 if ( ( seq = bufrdeco_get_target_subset_sequence_data ( subset, &BUFR ) ) == NULL )
243 {
244 printf ( "# %s", BUFR.error );
245 bufrdeco_close ( &BUFR );
246 exit ( EXIT_FAILURE );
247 }
248 }
249
250 //printf ( "So far so good !!\n" );
251 bufrdeco_close ( &BUFR );
252 exit ( EXIT_SUCCESS );
253}
int PRINT_JSON_EXPANDED_TREE
Definition: bufrdeco_json.c:33
char ENTRADA[256]
Definition: bufrdeco_json.c:27
int read_args(int _argc, char *_argv[])
read the arguments from stdio
Definition: bufrdeco_json.c:63
int set_bufrdeco_mask(struct bufrdeco *b)
struct bufrdeco BUFR
Definition: bufrdeco_json.c:25
int FIRST_SUBSET
Definition: bufrdeco_json.c:34
int EXTRACT
Definition: bufrdeco_json.c:26
int LAST_SUBSET
Definition: bufrdeco_json.c:35
int bufrdeco_close(struct bufrdeco *b)
Free all allocated memory. Needed when no more task to do with bufrdeco library.
Definition: bufrdeco.c:259
int bufrdeco_parse_tree(struct bufrdeco *b)
Parse the tree of descriptors without expand the replicators.
Definition: bufrdeco.c:120
struct bufrdeco_subset_sequence_data * bufrdeco_get_target_subset_sequence_data(buf_t nset, struct bufrdeco *b)
Prepare the struct bufrdeco to get data from the solicited subset.
Definition: bufrdeco.c:396
int bufrdeco_init(struct bufrdeco *b)
Inits and allocate memory for a struct bufrdeco.
Definition: bufrdeco.c:138
buf_t bufrdeco_print_json_tree(struct bufrdeco *b)
int bufrdeco_extract_bufr(struct bufrdeco *b, char *filename)
Read file and try to find a bufr report inserted in. Once found do the same that bufrdeco_read_file()
int bufrdeco_read_bufr(struct bufrdeco *b, char *filename)
Read bufr file and does preliminary and first decode pass.
Definition: bufrdeco_read.c:41
uint32_t subsets
Definition: bufrdeco.h:810
Contains all the information for a subset in a expanded squence This is a version to use with bufrdec...
Definition: bufrdeco.h:458
FILE * err
Definition: bufrdeco.h:985
struct bufr_sec3 sec3
Definition: bufrdeco.h:971
char error[1024]
Definition: bufrdeco.h:983

References BUFR, bufrdeco_close(), bufrdeco_extract_bufr(), bufrdeco_get_target_subset_sequence_data(), bufrdeco_init(), bufrdeco_parse_tree(), bufrdeco_print_json_tree(), bufrdeco_read_bufr(), ENTRADA, bufrdeco::err, bufrdeco::error, EXTRACT, FIRST_SUBSET, LAST_SUBSET, PRINT_JSON_EXPANDED_TREE, read_args(), bufrdeco::sec3, set_bufrdeco_mask(), and bufr_sec3::subsets.

Here is the call graph for this function:

◆ print_usage()

void print_usage ( void  )

Definition at line 37 of file bufrdeco_json.c.

38{
39 printf ( "Usage: \n" );
40 printf ( "bufrdeco_test -i input_file [-h][more optional args...]\n" );
41 printf ( " -h Print this help\n" );
42 printf ( " -i Input file. Complete input path file for bufr file\n" );
43 printf ( " -J. Information, tree and data in json format. Equivalent to option -E01234\n" );
44 printf ( " -S first..last . Print only results for subsets in range first..last (First subset available is 0). Default is all subsets\n" );
45 printf ( " -T. Print expanded tree in json format\n" );
46 printf ( " -X. Extract first BUFR buffer found in input file (from first 'BUFR' item to next '7777')\n" );
47 printf ( " -0. Prints BUFR Sec 0 information in json format\n" );
48 printf ( " -1. Prints BUFR Sec 1 information in json format\n" );
49 printf ( " -2. Prints BUFR Sec 2 information in json format\n" );
50 printf ( " -3. Prints BUFR Sec 3 information in json format\n" );
51 printf ( " -4. Prints BUFR data in json format\n" );
52
53}

Referenced by read_args().

Here is the caller graph for this function:

◆ read_args()

int read_args ( int  _argc,
char *  _argv[] 
)

read the arguments from stdio

Parameters
_argcnumber of arguments passed
_argvarray of arguments

Returns 1 if succcess, -1 othewise

Definition at line 63 of file bufrdeco_json.c.

64{
65 int iopt;
66 char *c, aux[128];
67
68 // Default values
69 EXTRACT = 0;
75
76 /*
77 Read input options
78 */
79 while ( ( iopt = getopt ( _argc, _argv, "hi:JXT01234" ) ) !=-1 )
80 switch ( iopt )
81 {
82 case 'X':
83 EXTRACT = 1;
84 break;
85
86 case '0':
88 break;
89
90 case '1':
92 break;
93
94 case '2':
96 break;
97
98 case '3':
100 break;
101
102 case '4':
103 PRINT_JSON_SEC4 = 1;
104 break;
105
106 case 'T':
108 break;
109
110 case 'J':
111 PRINT_JSON_SEC0 = 1;
112 PRINT_JSON_SEC1 = 1;
113 PRINT_JSON_SEC2 = 1;
114 PRINT_JSON_SEC3 = 1;
115 PRINT_JSON_SEC4 = 1;
117 break;
118
119 case 'S':
120 // Process subset sequence to show
121 if ( strlen ( optarg ) < 128 &&
122 strspn ( optarg, "0123456789." ) == strlen ( optarg ) )
123 {
124 if ( strstr ( optarg, ".." ) != NULL )
125 {
126 strcpy ( aux, optarg );
127 c = strstr ( aux, ".." );
128 if ( strlen ( c ) > 2 )
129 {
130 LAST_SUBSET = atoi ( c + 2 );
131 }
132 *c = '\0';
133 if ( aux[0] )
134 {
135 FIRST_SUBSET = atoi ( aux );
136 }
137 }
138 else
139 {
140 FIRST_SUBSET = atoi ( optarg );
142 }
143 }
144 break;
145 case 'i':
146 if ( strlen ( optarg ) < 256 )
147 strcpy ( ENTRADA, optarg );
148 break;
149
150 case 'h':
151 default:
152 print_usage();
153 exit ( EXIT_SUCCESS );
154 }
155
156 if ( ENTRADA[0] == '\0' )
157 {
158 printf ( "read_args(): It is needed an input file. Use -i option\n" );
159 return -1;
160 }
161 return 1;
162}
int PRINT_JSON_SEC4
Definition: bufrdeco_json.c:32
int PRINT_JSON_SEC1
Definition: bufrdeco_json.c:29
int PRINT_JSON_SEC2
Definition: bufrdeco_json.c:30
int PRINT_JSON_SEC0
Definition: bufrdeco_json.c:28
int PRINT_JSON_SEC3
Definition: bufrdeco_json.c:31
void print_usage(void)
Definition: bufrdeco_json.c:37

References ENTRADA, EXTRACT, FIRST_SUBSET, LAST_SUBSET, PRINT_JSON_EXPANDED_TREE, PRINT_JSON_SEC0, PRINT_JSON_SEC1, PRINT_JSON_SEC2, PRINT_JSON_SEC3, PRINT_JSON_SEC4, and print_usage().

Referenced by main().

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

◆ set_bufrdeco_mask()

int set_bufrdeco_mask ( struct bufrdeco b)

Definition at line 165 of file bufrdeco_json.c.

166{
167 if ( PRINT_JSON_SEC0 )
169
170 if ( PRINT_JSON_SEC1 )
172
173 if ( PRINT_JSON_SEC2 )
175
176 if ( PRINT_JSON_SEC3 )
178
179 if ( PRINT_JSON_SEC4 )
181
184
185 return 0;
186}
#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
#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 BUFRDECO_OUTPUT_JSON_SEC2
Bit mask to the member mask of struct bufrdeco to print bufr info for SEC 2 in json format.
Definition: bufrdeco.h:287
#define BUFRDECO_OUTPUT_JSON_SEC3
Bit mask to the member mask of struct bufrdeco to print bufr info for SEC 3 in json format.
Definition: bufrdeco.h:293
#define BUFRDECO_OUTPUT_JSON_SEC0
Bit mask to the member mask of struct bufrdeco to print info for SEC 0 in json format.
Definition: bufrdeco.h:275
#define BUFRDECO_OUTPUT_JSON_SEC1
Bit mask to the member mask of struct bufrdeco to print info for SEC 1 in json format.
Definition: bufrdeco.h:281
uint32_t mask
Definition: bufrdeco.h:966

References BUFRDECO_OUTPUT_JSON_EXPANDED_TREE, BUFRDECO_OUTPUT_JSON_SEC0, BUFRDECO_OUTPUT_JSON_SEC1, BUFRDECO_OUTPUT_JSON_SEC2, BUFRDECO_OUTPUT_JSON_SEC3, BUFRDECO_OUTPUT_JSON_SUBSET_DATA, bufrdeco::mask, PRINT_JSON_EXPANDED_TREE, PRINT_JSON_SEC0, PRINT_JSON_SEC1, PRINT_JSON_SEC2, PRINT_JSON_SEC3, and PRINT_JSON_SEC4.

Referenced by main().

Here is the caller graph for this function:

Variable Documentation

◆ BUFR

struct bufrdeco BUFR

Definition at line 25 of file bufrdeco_json.c.

Referenced by main().

◆ ENTRADA

char ENTRADA[256]

Definition at line 27 of file bufrdeco_json.c.

Referenced by main(), and read_args().

◆ EXTRACT

int EXTRACT

Definition at line 26 of file bufrdeco_json.c.

Referenced by bufrtotac_read_args(), main(), and read_args().

◆ FIRST_SUBSET

int FIRST_SUBSET

First subset to parse

Definition at line 34 of file bufrdeco_json.c.

Referenced by bufrtotac_read_args(), main(), and read_args().

◆ LAST_SUBSET

int LAST_SUBSET

Last subset to parse

Definition at line 35 of file bufrdeco_json.c.

Referenced by bufrtotac_read_args(), main(), and read_args().

◆ PRINT_JSON_EXPANDED_TREE

int PRINT_JSON_EXPANDED_TREE

If != 0 Prints expanded tree in json format

Definition at line 33 of file bufrdeco_json.c.

Referenced by bufrtotac_read_args(), bufrtotac_set_bufrdeco_bitmask(), main(), read_args(), and set_bufrdeco_mask().

◆ PRINT_JSON_SEC0

int PRINT_JSON_SEC0

If != 0 Prints Sec 0 information in json format

Definition at line 28 of file bufrdeco_json.c.

Referenced by bufrtotac_read_args(), bufrtotac_set_bufrdeco_bitmask(), read_args(), and set_bufrdeco_mask().

◆ PRINT_JSON_SEC1

int PRINT_JSON_SEC1

If != 0 Prints Sec 1 information in json format

Definition at line 29 of file bufrdeco_json.c.

Referenced by bufrtotac_read_args(), bufrtotac_set_bufrdeco_bitmask(), read_args(), and set_bufrdeco_mask().

◆ PRINT_JSON_SEC2

int PRINT_JSON_SEC2

If != 0 Prints Sec 2 information in json format

Definition at line 30 of file bufrdeco_json.c.

Referenced by bufrtotac_read_args(), bufrtotac_set_bufrdeco_bitmask(), read_args(), and set_bufrdeco_mask().

◆ PRINT_JSON_SEC3

int PRINT_JSON_SEC3

If != 0 Prints Sec 3 information in json format

Definition at line 31 of file bufrdeco_json.c.

Referenced by bufrtotac_read_args(), bufrtotac_set_bufrdeco_bitmask(), read_args(), and set_bufrdeco_mask().

◆ PRINT_JSON_SEC4

int PRINT_JSON_SEC4

If != 0 Prints Sec 4 data in json format

Definition at line 32 of file bufrdeco_json.c.

Referenced by read_args(), and set_bufrdeco_mask().