bufr2synop 0.24.0
Functions | Variables
bufrtotac.c File Reference

This file includes the code to test bufr to TAC libraries using bufrdeco library to decode bufr. More...

#include "bufrtotac.h"
Include dependency graph for bufrtotac.c:

Go to the source code of this file.

Functions

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

Variables

struct bufrdeco BUFR
 
struct metreport REPORT
 
struct bufr2tac_subset_state STATE
 
struct bufr2tac_error_stack ERRS
 
const char SELF [] = "bufrtotac"
 
char ERR [256]
 
char BUFRTABLES_DIR [256]
 
char LISTOFFILES [256]
 
char INPUTFILE [256]
 
char OFFSETFILE [BUFRDECO_PATH_LENGTH+8]
 
char OUTPUTFILE [256]
 
int VERBOSE
 
int SHOW_SEQUENCE
 
int DEBUG
 
int NFILES
 
int GTS_HEADER
 
int XML
 
int JSON
 
int CSV
 
int EXTRACT
 
int ECMWF
 
int HTML
 
int NOTAC
 
int FIRST_SUBSET
 
int LAST_SUBSET
 
int PRINT_WIGOS_ID
 
int PRINT_GEO
 
int READ_OFFSETS
 
int WRITE_OFFSETS
 
int USE_CACHE
 
int SUBSET
 
int PRINT_JSON_DATA
 
int PRINT_JSON_SEC0
 
int PRINT_JSON_SEC1
 
int PRINT_JSON_SEC2
 
int PRINT_JSON_SEC3
 
int PRINT_JSON_EXPANDED_TREE
 
FILE * FL
 
FILE * OUT
 

Detailed Description

This file includes the code to test bufr to TAC libraries using bufrdeco library to decode bufr.

Definition in file bufrtotac.c.

Function Documentation

◆ main()

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

Definition at line 134 of file bufrtotac.c.

135{
136 int first_subset, last_subset;
137 char subset_id[32];
139
140
141 if ( bufrtotac_read_args ( argc, argv ) < 0 )
142 exit ( EXIT_FAILURE );
143
144 // init bufr struct
145#ifdef DEBUG_TIME
146 clk_start = clock ();
147#endif
148 if ( bufrdeco_init ( &BUFR ) )
149 {
150 printf ( "%s(): Cannot init bufr struct\n", SELF );
151 return 1;
152 }
153
154#ifdef DEBUG_TIME
155 clk_end = clock();
156 print_timing (clk_start,clk_end,bufrdeco_init());
157#endif
158
159 /**** set bitmask according with args readed from shell ****/
161
162 /**** Set bufr tables dir ****/
164
165 /**** Big loop. a cycle per file. Get input filenames from LISTOFFILES[] ****/
167 {
168#ifdef __DEBUG
169 printf ( "####### %s ######\n", INPUTFILE );
170#endif
171 if ( DEBUG )
172 printf ( "# %s\n", INPUTFILE );
173
174 // The following call to bufrdeco_read_bufr() does the folowing tasks:
175 // - Read the file and checks the marks at the begining and end to see wheter is a BUFR file
176 // - Init the structs and allocate the needed memory if not done previously
177 // - Splits and parse the BUFR sections (without expanding descriptors nor parsing data)
178 // - Reads the needed Table files and store them in memory.
179 //
180 // If EXTRACT != 0 then the function bufrdeco_extract_bufr() is used instead of bufrdeco_read_bufr()
181 // This act in the same way, but search and extract the first BUFR embebed in a file.
182#ifdef DEBUG_TIME
183 clk_start = clock ();
184#endif
185
186 if ( ( EXTRACT && bufrdeco_extract_bufr ( &BUFR, INPUTFILE ) ) ||
187 ( EXTRACT == 0 && bufrdeco_read_bufr ( &BUFR, INPUTFILE ) ) )
188 {
189 if ( DEBUG )
190 printf ( "# %s\n", BUFR.error );
191 NFILES++;
192 bufrdeco_reset ( &BUFR );
193 continue;
194 }
195#ifdef DEBUG_TIME
196 clk_end = clock();
197 print_timing (clk_start,clk_end,bufrdeco_extract_bufr());
198#endif
199
200 // Check if have to read bit offsets file
201 if ( READ_OFFSETS &&
202 BUFR.sec3.compressed == 0 &&
203 BUFR.sec3.subsets > 1 )
204 {
205 #ifdef DEBUG_TIME
206 clk_start = clock ();
207 #endif
209#ifdef DEBUG_TIME
210 clk_end = clock();
211 print_timing (clk_start,clk_end,bufrdeco_read_subset_offset_bits());
212#endif
213 }
214
215 /* Try to guess a GTS header from filename*/
216 GTS_HEADER = guess_gts_header ( &BUFR.header, INPUTFILE ); // GTS_HEADER = 1 if succeeded
217 if ( GTS_HEADER && DEBUG )
218 printf ( "# Guessed GTS Header: %s %s %s %s %s\n", BUFR.header.timestamp, BUFR.header.bname, BUFR.header.center,
220
221 /* Prints sections if verbose */
222 if ( VERBOSE )
223 {
228 }
229
230 // To get any data from any subset we need to parse the tree
231#ifdef DEBUG_TIME
232 clk_start = clock ();
233#endif
234 if ( bufrdeco_parse_tree ( &BUFR ) )
235 {
236 if ( DEBUG )
237 printf ( "# %s", BUFR.error );
238 NFILES++;
239 bufrdeco_reset ( &BUFR );
240 continue;
241 }
242#ifdef DEBUG_TIME
243 clk_end = clock();
244 print_timing (clk_start,clk_end,bufrdeco_parse_tree());
245#endif
248
249 if ( VERBOSE )
251
252 first_subset = FIRST_SUBSET;
253 last_subset = LAST_SUBSET;
254
255 // Fix first and last subset
256 if ( first_subset >= ( int ) BUFR.sec3.subsets )
257 goto fin;
258
259 if ( last_subset < first_subset)
260 last_subset = BUFR.sec3.subsets - 1;
261
262 for ( SUBSET = first_subset; SUBSET <= last_subset ; SUBSET++ )
263 {
264#ifdef DEBUG_TIME
265 clk_start = clock ();
266#endif
267 if ( ( seq = bufrdeco_get_target_subset_sequence_data ( SUBSET, &BUFR ) ) == NULL )
268 {
269 if ( DEBUG )
270 printf ( "# %s", BUFR.error );
271 goto fin;
272 }
273#ifdef DEBUG_TIME
274 clk_end = clock();
275 print_timing (clk_start, clk_end,bufrdeco_get_target_subset_sequence_data());
276#endif
277
278 if ( VERBOSE )
279 {
280 if ( ( SUBSET == first_subset ) && BUFR.sec3.compressed )
283 {
284 sprintf ( subset_id, "subset_%d", SUBSET );
286 }
287 else
289 }
290
291 if ( ! NOTAC )
292 {
293 // Here we perform the decode to TAC
294#ifdef DEBUG_TIME
295 clk_start = clock ();
296#endif
298 {
299 if ( DEBUG )
300 fprintf ( stderr, "# %s\n", ERR );
301 }
302#ifdef DEBUG_TIME
303 clk_end = clock();
304 print_timing (clk_start, clk_end, bufrtotac_parse_subset_sequence());
305#endif
306
307 // And here print the results
308 if ( XML )
309 {
310 if ( SUBSET == 0 )
311 fprintf ( OUT, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" );
312 print_xml ( stdout, &REPORT );
313 }
314 else if ( JSON )
315 {
316 print_json ( OUT, &REPORT );
317 }
318 else if ( CSV )
319 {
320 if ( SUBSET == 0 )
321 fprintf ( OUT, "TYPE,FILE,DATETIME,INDEX,NAME,COUNTRY,LATITUDE,LONGITUDE,ALTITUDE,REPORT\n" );
322 print_csv ( OUT, &REPORT );
323 }
324 else if ( HTML )
325 {
326 print_html ( OUT, &REPORT );
327 }
328 else
329 {
330 print_plain ( OUT, &REPORT );
331 }
332 }
333 }
334 fin:
335 ;
336
337 // check if has to write bit offsets file
338 if ( BUFR.sec3.compressed == 0 &&
339 BUFR.sec3.subsets > 1 &&
341 {
343 }
344
345#ifdef DEBUG_TIME
346 clk_start = clock ();
347#endif
348 bufrdeco_reset ( &BUFR );
349#ifdef DEBUG_TIME
350 clk_end = clock();
351 print_timing (clk_start, clk_end, bufrdeco_reset());
352#endif
353 NFILES ++;
354 } // End of big loop parsing files
355
356 bufrdeco_close ( &BUFR );
357
358 // Close the file if needed
359 if (OUTPUTFILE[0])
360 fclose (OUT);
361
362 exit ( EXIT_SUCCESS );
363}
int guess_gts_header(struct gts_header *h, const char *f)
Guess the WMO GTS header from filename.
int print_json(FILE *f, struct metreport *m)
prints a struct metreport in json format
Definition: bufr2tac_json.c:62
int print_csv(FILE *f, struct metreport *m)
prints a struct metreport in labeled csv format
Definition: bufr2tac_csv.c:85
int print_xml(FILE *f, struct metreport *m)
prints a struct metreport in xml format
Definition: bufr2tac_xml.c:71
int print_plain(FILE *f, struct metreport *m)
Print in a file the report decoded to Traditional Alphanumeric Code in plain text format....
int print_html(FILE *f, struct metreport *m)
Print in a file the report decoded to Traditional Alphanumeric Code in plain html format....
int bufrdeco_reset(struct bufrdeco *b)
Reset an struct bufrdeco. This is needed when changing to another bufr.
Definition: bufrdeco.c:180
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_write_subset_offset_bits(struct bufrdeco *b, char *filename)
Write offset bit array for subsets in a non-compressed bufr.
Definition: bufrdeco.c:330
int bufrdeco_parse_tree(struct bufrdeco *b)
Parse the tree of descriptors without expand the replicators.
Definition: bufrdeco.c:120
int bufrdeco_read_subset_offset_bits(struct bufrdeco *b, char *filename)
Write offset bit array for subsets in a non-compressed bufr.
Definition: bufrdeco.c:358
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
int bufrdeco_print_subset_sequence_data(struct bufrdeco_subset_sequence_data *s)
Prints a struct bufrdeco_subset_sequence_data.
buf_t bufrdeco_print_json_tree(struct bufrdeco *b)
int print_sec0_info(struct bufrdeco *b)
Prints info from sec0.
int print_bufrdeco_compressed_data_references(struct bufrdeco_compressed_data_references *r)
prints a struct bufrdeco_compressed_references
#define BUFRDECO_OUTPUT_HTML
Bit mask to the member mask for struct bufrdeco to format output as html for SECs 0 to 3.
Definition: bufrdeco.h:256
int print_sec3_info(struct bufrdeco *b)
Prints info from sec3.
int bufrdeco_print_subset_sequence_data_tagged_html(struct bufrdeco_subset_sequence_data *s, char *id)
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_print_tree(struct bufrdeco *b)
Print a tree of descriptors.
int print_sec4_info(struct bufrdeco *b)
Prints info from sec3.
int bufrdeco_read_bufr(struct bufrdeco *b, char *filename)
Read bufr file and does preliminary and first decode pass.
Definition: bufrdeco_read.c:41
int print_sec1_info(struct bufrdeco *b)
Prints info from sec1.
int JSON
Definition: bufrtotac.c:107
char OUTPUTFILE[256]
Definition: bufrtotac.c:100
int PRINT_JSON_EXPANDED_TREE
Definition: bufrtotac.c:126
char ERR[256]
Definition: bufrtotac.c:95
const char SELF[]
Definition: bufrtotac.c:94
int XML
Definition: bufrtotac.c:106
char INPUTFILE[256]
Definition: bufrtotac.c:98
FILE * OUT
Definition: bufrtotac.c:129
int GTS_HEADER
Definition: bufrtotac.c:105
int NFILES
Definition: bufrtotac.c:104
int DEBUG
Definition: bufrtotac.c:103
int WRITE_OFFSETS
Definition: bufrtotac.c:118
int READ_OFFSETS
Definition: bufrtotac.c:117
int CSV
Definition: bufrtotac.c:108
struct bufr2tac_subset_state STATE
Definition: bufrtotac.c:91
struct bufrdeco BUFR
Definition: bufrtotac.c:89
char OFFSETFILE[BUFRDECO_PATH_LENGTH+8]
Definition: bufrtotac.c:99
int SUBSET
Definition: bufrtotac.c:120
int HTML
Definition: bufrtotac.c:111
int FIRST_SUBSET
Definition: bufrtotac.c:113
int NOTAC
Definition: bufrtotac.c:112
int VERBOSE
Definition: bufrtotac.c:101
struct metreport REPORT
Definition: bufrtotac.c:90
int EXTRACT
Definition: bufrtotac.c:109
int LAST_SUBSET
Definition: bufrtotac.c:114
char BUFRTABLES_DIR[256]
Definition: bufrtotac.c:96
int bufrtotac_parse_subset_sequence(struct metreport *m, struct bufr2tac_subset_state *st, struct bufrdeco *b, char *err)
Definition: bufrtotac_io.c:356
char * get_bufrfile_path(char *filename, char *fileoffset, char *err)
Definition: bufrtotac_io.c:419
int bufrtotac_set_bufrdeco_bitmask(struct bufrdeco *b)
Set the bufrdeco struct bitmask according with readed args from shell.
Definition: bufrtotac_io.c:463
int bufrtotac_read_args(int _argc, char *_argv[])
Definition: bufrtotac_io.c:145
uint8_t compressed
Definition: bufrdeco.h:812
uint32_t ndesc
Definition: bufrdeco.h:813
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
uint32_t mask
Definition: bufrdeco.h:966
struct bufrdeco_compressed_data_references refs
Definition: bufrdeco.h:978
char bufrtables_dir[BUFRDECO_PATH_LENGTH]
Definition: bufrdeco.h:982
struct bufr_sec3 sec3
Definition: bufrdeco.h:971
struct gts_header header
Definition: bufrdeco.h:967
char error[1024]
Definition: bufrdeco.h:983
char center[8]
Definition: bufrdeco.h:709
char dtrel[16]
Definition: bufrdeco.h:710
char order[8]
Definition: bufrdeco.h:711
char bname[16]
Definition: bufrdeco.h:708
char timestamp[16]
Definition: bufrdeco.h:713

References gts_header::bname, BUFR, bufrdeco_close(), bufrdeco_extract_bufr(), bufrdeco_get_target_subset_sequence_data(), bufrdeco_init(), BUFRDECO_OUTPUT_HTML, bufrdeco_parse_tree(), bufrdeco_print_json_tree(), bufrdeco_print_subset_sequence_data(), bufrdeco_print_subset_sequence_data_tagged_html(), bufrdeco_print_tree(), bufrdeco_read_bufr(), bufrdeco_read_subset_offset_bits(), bufrdeco_reset(), bufrdeco_write_subset_offset_bits(), BUFRTABLES_DIR, bufrdeco::bufrtables_dir, bufrtotac_parse_subset_sequence(), bufrtotac_read_args(), bufrtotac_set_bufrdeco_bitmask(), gts_header::center, bufr_sec3::compressed, CSV, DEBUG, gts_header::dtrel, ERR, bufrdeco::error, EXTRACT, FIRST_SUBSET, get_bufrfile_path(), GTS_HEADER, guess_gts_header(), bufrdeco::header, HTML, INPUTFILE, JSON, LAST_SUBSET, bufrdeco::mask, bufr_sec3::ndesc, NFILES, NOTAC, OFFSETFILE, gts_header::order, OUT, OUTPUTFILE, print_bufrdeco_compressed_data_references(), print_csv(), print_html(), print_json(), PRINT_JSON_EXPANDED_TREE, print_plain(), print_sec0_info(), print_sec1_info(), print_sec3_info(), print_sec4_info(), print_xml(), READ_OFFSETS, bufrdeco::refs, REPORT, bufrdeco::sec3, SELF, STATE, SUBSET, bufr_sec3::subsets, gts_header::timestamp, VERBOSE, WRITE_OFFSETS, and XML.

Here is the call graph for this function:

Variable Documentation

◆ BUFR

struct bufrdeco BUFR

Definition at line 89 of file bufrtotac.c.

Referenced by main().

◆ BUFRTABLES_DIR

char BUFRTABLES_DIR[256]

Directory for BUFR tables set by user

Definition at line 96 of file bufrtotac.c.

Referenced by bufrtotac_read_args(), and main().

◆ CSV

int CSV

If == 1 then output is in csv format

Definition at line 108 of file bufrtotac.c.

Referenced by bufrtotac_read_args(), and main().

◆ DEBUG

int DEBUG

Show debug information

Definition at line 103 of file bufrtotac.c.

Referenced by bufrtotac_read_args(), and main().

◆ ECMWF

int ECMWF

If == 1 then use tables from ECMWF package

Definition at line 110 of file bufrtotac.c.

◆ ERR

char ERR[256]

< the name of this binary string with an error

Definition at line 95 of file bufrtotac.c.

Referenced by main().

◆ ERRS

struct bufr2tac_error_stack ERRS

struct to store warnings and errors

Definition at line 92 of file bufrtotac.c.

◆ EXTRACT

int EXTRACT

if != 0 then the decoder tries to extract an embebed bufr in a file seraching for a first '7777' after first 'BUFR'

Definition at line 109 of file bufrtotac.c.

Referenced by main().

◆ FIRST_SUBSET

int FIRST_SUBSET

First subset index in output. First available is 0

Definition at line 113 of file bufrtotac.c.

Referenced by main().

◆ FL

FILE* FL

Buffer to read the list of files

Definition at line 128 of file bufrtotac.c.

Referenced by get_bufrfile_path().

◆ GTS_HEADER

int GTS_HEADER

If == 1 GTS header have been guessed from filename

Definition at line 105 of file bufrtotac.c.

Referenced by main().

◆ HTML

int HTML

If == 1 then output is in HTML format

Definition at line 111 of file bufrtotac.c.

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

◆ INPUTFILE

char INPUTFILE[256]

The pathname of input file

Definition at line 98 of file bufrtotac.c.

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

◆ JSON

int JSON

If == 1 then output is in json format

Definition at line 107 of file bufrtotac.c.

Referenced by bufrtotac_read_args(), and main().

◆ LAST_SUBSET

int LAST_SUBSET

Last subset index in output. First available is 0

Definition at line 114 of file bufrtotac.c.

Referenced by main().

◆ LISTOFFILES

char LISTOFFILES[256]

The pathname of a file which includes a list of bufr files to parse

Definition at line 97 of file bufrtotac.c.

Referenced by bufrtotac_read_args(), and get_bufrfile_path().

◆ NFILES

int NFILES

The amount of files processed

Definition at line 104 of file bufrtotac.c.

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

◆ NOTAC

int NOTAC

if == 1 then do not decode to TAC

Definition at line 112 of file bufrtotac.c.

Referenced by bufrtotac_read_args(), and main().

◆ OFFSETFILE

char OFFSETFILE[BUFRDECO_PATH_LENGTH+8]

Definition at line 99 of file bufrtotac.c.

Referenced by bufrtotac_read_args(), and main().

◆ OUT

FILE* OUT

Buffer to write to OUTPUTFILE

Definition at line 129 of file bufrtotac.c.

Referenced by bufrtotac_read_args(), and main().

◆ OUTPUTFILE

char OUTPUTFILE[256]

The pathname of output file

Definition at line 100 of file bufrtotac.c.

Referenced by bufrtotac_read_args(), and main().

◆ PRINT_GEO

int PRINT_GEO

if != 0 then print latitude, longitude and altitude

Definition at line 116 of file bufrtotac.c.

Referenced by bufrtotac_parse_subset_sequence(), and bufrtotac_read_args().

◆ PRINT_JSON_DATA

int PRINT_JSON_DATA

If != 0 then the data subset is in json format

Definition at line 121 of file bufrtotac.c.

Referenced by bufrtotac_read_args(), and bufrtotac_set_bufrdeco_bitmask().

◆ PRINT_JSON_EXPANDED_TREE

int PRINT_JSON_EXPANDED_TREE

If != 0 Prints expanded tree in json format

Definition at line 126 of file bufrtotac.c.

Referenced by main().

◆ PRINT_JSON_SEC0

int PRINT_JSON_SEC0

If != 0 Prints Sec 0 information in json format

Definition at line 122 of file bufrtotac.c.

◆ PRINT_JSON_SEC1

int PRINT_JSON_SEC1

If != 0 Prints Sec 1 information in json format

Definition at line 123 of file bufrtotac.c.

◆ PRINT_JSON_SEC2

int PRINT_JSON_SEC2

If != 0 Prints Sec 2 information in json format

Definition at line 124 of file bufrtotac.c.

◆ PRINT_JSON_SEC3

int PRINT_JSON_SEC3

If != 0 Prints Sec 3 information in json format

Definition at line 125 of file bufrtotac.c.

◆ PRINT_WIGOS_ID

int PRINT_WIGOS_ID

if != 0 then print wigos id in output

Definition at line 115 of file bufrtotac.c.

Referenced by bufrtotac_parse_subset_sequence(), and bufrtotac_read_args().

◆ READ_OFFSETS

int READ_OFFSETS

if != then read bit offsets

Definition at line 117 of file bufrtotac.c.

Referenced by bufrtotac_read_args(), and main().

◆ REPORT

struct metreport REPORT

stuct to set the parsed report

Definition at line 90 of file bufrtotac.c.

Referenced by main().

◆ SELF

const char SELF[] = "bufrtotac"

Definition at line 94 of file bufrtotac.c.

Referenced by bufrtotac_print_usage(), bufrtotac_print_version(), and main().

◆ SHOW_SEQUENCE

int SHOW_SEQUENCE

Output explained sequence

Definition at line 102 of file bufrtotac.c.

Referenced by bufrtotac_read_args().

◆ STATE

struct bufr2tac_subset_state STATE

Includes the info when parsing a subset sequence

Definition at line 91 of file bufrtotac.c.

Referenced by main().

◆ SUBSET

int SUBSET

Index of subset in a BUFR being parsed

Definition at line 120 of file bufrtotac.c.

Referenced by bufrtotac_parse_subset_sequence(), and main().

◆ USE_CACHE

int USE_CACHE

if != 0 then use cache of tables

Definition at line 119 of file bufrtotac.c.

Referenced by bufrtotac_read_args(), and bufrtotac_set_bufrdeco_bitmask().

◆ VERBOSE

int VERBOSE

If != 0 the verbose output

Definition at line 101 of file bufrtotac.c.

Referenced by main().

◆ WRITE_OFFSETS

int WRITE_OFFSETS

if != 0 then write bit offsets

Definition at line 118 of file bufrtotac.c.

Referenced by bufrtotac_read_args(), and main().

◆ XML

int XML

If == 1 then output is in xml format

Definition at line 106 of file bufrtotac.c.

Referenced by bufrtotac_read_args(), and main().