bufr2synop 0.24.0
Macros | Functions | Variables
bufrnoaa.h File Reference

inclusion file for binary bufrnoaa More...

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <getopt.h>
#include <time.h>
#include <utime.h>
#include <sys/time.h>
#include <sys/stat.h>
Include dependency graph for bufrnoaa.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define BLEN   1024
 
#define BUFRLEN   8388608
 

Functions

int is_bufr (unsigned char *b)
 checks if an unsigned char from an array is the first char of 'BUFR' More...
 
int is_endb (unsigned char *b)
 checks if an unsigned char from an array is the first char of '7777' More...
 
int is_head (unsigned char *b)
 checks if an unsigned char from an array is the first char of '****' More...
 
int is_head_custom (unsigned char *b, char mark)
 checks if an unsigned char from an array is the first char of repeated mark char four times More...
 
int timeval_substract (struct timeval *result, struct timeval *x, struct timeval *y)
 Subtract the ‘struct timeval’ values X and Y, storing the result in RESULT. More...
 
int read_args (int _argc, char *_argv[])
 read the arguments from stdio More...
 
void print_usage (void)
 
void print_version (void)
 
int bufr_is_selected (char *name)
 returns 1 if selected message 0 otherwise More...
 
int date_mtime_from_stat (char *date, struct stat *st)
 get a string with date and time from a struct stat More...
 
int mtime_from_stat (char *filename, struct stat *st)
 modifies a file update time from a struct stat More...
 

Variables

int STAGE
 
int SELECT
 
int INDIVIDUAL
 
int COLECT
 
int VERBOSE
 
int LISTF
 
unsigned char BUFR [BUFRLEN]
 
unsigned char BUF [BLEN]
 
char ENTRADA [256]
 
char PREFIX [64]
 
struct stat INSTAT
 
char SEL [64]
 
char SELS [64]
 
char SELO [64]
 
char SELU [64]
 
char OWN []
 
char HEADER_MARK
 
char FINAL_SEP [4]
 
char SEP []
 

Detailed Description

inclusion file for binary bufrnoaa

Definition in file bufrnoaa.h.

Macro Definition Documentation

◆ BLEN

#define BLEN   1024

Definition at line 34 of file bufrnoaa.h.

◆ BUFRLEN

#define BUFRLEN   8388608

Definition at line 36 of file bufrnoaa.h.

Function Documentation

◆ bufr_is_selected()

int bufr_is_selected ( char *  name)

returns 1 if selected message 0 otherwise

Parameters
namestring with name to check

Definition at line 124 of file bufrnoaa_utils.c.

125{
126 if ( strlen ( SEL ) == 0 )
127 return 0;
128 if ( strchr ( SEL, name[1] ) == NULL )
129 return 0;
130 if ( name[1] == 'S' )
131 {
132 if ( strlen ( SELS ) == 0 )
133 return 1;
134 else if ( strchr ( SELS, name[2] ) == NULL )
135 return 0;
136 }
137
138 if ( name[1] == 'O' )
139 {
140 if ( strlen ( SELO ) == 0 )
141 return 1;
142 else if ( strchr ( SELO, name[2] ) == NULL )
143 return 0;
144 }
145
146 if ( name[1] == 'U' )
147 {
148 if ( strlen ( SELU ) == 0 )
149 return 1;
150 else if ( strchr ( SELU, name[2] ) == NULL )
151 return 0;
152 }
153
154 return 1;
155}
char SELU[64]
Definition: bufrnoaa.c:199
char SELS[64]
Definition: bufrnoaa.c:198
char SELO[64]
Definition: bufrnoaa.c:200

References SELO, SELS, and SELU.

Referenced by main().

Here is the caller graph for this function:

◆ date_mtime_from_stat()

nt date_mtime_from_stat ( char *  date,
struct stat *  st 
)

get a string with date and time from a struct stat

Parameters
datestring wuth the result
stpointer to a strucr stat

Definition at line 163 of file bufrnoaa_utils.c.

164{
165 struct tm tim;
166 memset ( &tim, 0, sizeof ( tim ) );
167 gmtime_r ( & ( st->st_mtime ), &tim );
168 strftime ( date, 16, "%Y%m%d%H%M%S", &tim );
169 return 1;
170}

Referenced by main().

Here is the caller graph for this function:

◆ is_bufr()

int is_bufr ( unsigned char *  b)

checks if an unsigned char from an array is the first char of 'BUFR'

Parameters
bpointer to unsigned char to check

Returns 1 if success, 0 othewise

Definition at line 33 of file bufrnoaa_utils.c.

34{
35 if ( b[0] == 'R' && b[1] == 'F' && b[2] == 'U' && b[3] == 'B' )
36 return 1;
37 return 0;
38}

Referenced by main().

Here is the caller graph for this function:

◆ is_endb()

int is_endb ( unsigned char *  b)

checks if an unsigned char from an array is the first char of '7777'

Parameters
bpointer to unsigned char to check

Returns 1 if success, 0 othewise

Definition at line 76 of file bufrnoaa_utils.c.

77{
78 if ( b[0] == '7' && b[1] == '7' && b[2] == '7' && b[3] == '7' )
79 return 1;
80 return 0;
81}

Referenced by main().

Here is the caller graph for this function:

◆ is_head()

int is_head ( unsigned char *  b)

checks if an unsigned char from an array is the first char of '****'

Parameters
bpointer to unsigned char to check

Returns 1 if success, 0 othewise

Definition at line 47 of file bufrnoaa_utils.c.

48{
49 if ( b[0] == '*' && b[1] == '*' && b[2] == '*' && b[3] == '*' )
50 return 1;
51 return 0;
52}

◆ is_head_custom()

int is_head_custom ( unsigned char *  b,
char  mark 
)

checks if an unsigned char from an array is the first char of repeated mark char four times

Parameters
bpointer to unsigned char to check
markchar to be found repeated four times since b Returns 1 if success, 0 othewise

Definition at line 61 of file bufrnoaa_utils.c.

62{
63 if ( b[0] == mark && b[1] == mark && b[2] == mark && b[3] == mark )
64 return 1;
65 return 0;
66}

Referenced by main().

Here is the caller graph for this function:

◆ mtime_from_stat()

int mtime_from_stat ( char *  filename,
struct stat *  st 
)

modifies a file update time from a struct stat

Parameters
filenamestring with the pathname of file to modify
stpointer to a struct stat as reference

Definition at line 178 of file bufrnoaa_utils.c.

179{
180 struct utimbuf ut;
181 ut.modtime = st->st_mtime;
182 ut.actime = st->st_mtime;
183 utime ( filename, &ut );
184 return 1;
185}

Referenced by main().

Here is the caller 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}

References OWN, PACKAGE_VERSION, print_version(), and SELF.

Referenced by main(), and read_args().

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

◆ print_version()

void print_version ( void  )

Definition at line 114 of file bufrnoaa_io.c.

115{
116 char version[16], build[64], builder[32];
117
118 bufrnoaa_get_version(version, build, builder, NULL, NULL, NULL);
119 printf ("%s: Version '%s' built %s and %s.\n" , OWN, VERSION, build, builder);
120}
char OWN[]
Definition: bufrnoaa.c:205
char * bufrnoaa_get_version(char *version, char *build, char *builder, int *version_major, int *version_minor, int *version_patch)
Get strings with version information and build date and time.
Definition: bufrnoaa_io.c:72
#define VERSION
Definition: config.h:8

References bufrnoaa_get_version(), OWN, and VERSION.

Referenced by print_usage(), and read_args().

Here is the call graph for this function:
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_EXPANDED_TREE
Definition: bufrdeco_json.c:33
int PRINT_JSON_SEC4
Definition: bufrdeco_json.c:32
int PRINT_JSON_SEC1
Definition: bufrdeco_json.c:29
char ENTRADA[256]
Definition: bufrdeco_json.c:27
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
int FIRST_SUBSET
Definition: bufrdeco_json.c:34
int EXTRACT
Definition: bufrdeco_json.c:26
int LAST_SUBSET
Definition: bufrdeco_json.c:35

References COLECT, ENTRADA, EXTRACT, FINAL_SEP, FIRST_SUBSET, HEADER_MARK, INDIVIDUAL, LAST_SUBSET, LISTF, OWN, PREFIX, PRINT_JSON_EXPANDED_TREE, PRINT_JSON_SEC0, PRINT_JSON_SEC1, PRINT_JSON_SEC2, PRINT_JSON_SEC3, PRINT_JSON_SEC4, print_usage(), print_version(), SELECT, SELO, SELS, SELU, SEP, and VERBOSE.

Referenced by main().

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

◆ timeval_substract()

int timeval_substract ( struct timeval *  result,
struct timeval *  x,
struct timeval *  y 
)

Subtract the ‘struct timeval’ values X and Y, storing the result in RESULT.

Parameters
resultpointer to a struct timeval where to set the result
xpointer to struct timeval as X in (X - Y)
ypointer to struct timeval as Y in (X - Y)

Return 1 if the difference is negative, otherwise 0.

Definition at line 93 of file bufrnoaa_utils.c.

95{
96 /* Perform the carry for the later subtraction by updating Y. */
97 if ( x->tv_usec < y->tv_usec )
98 {
99 int nsec = ( y->tv_usec - x->tv_usec ) / 1000000 + 1;
100 y->tv_usec -= 1000000 * nsec;
101 y->tv_sec += nsec;
102 }
103 if ( x->tv_usec - y->tv_usec > 1000000 )
104 {
105 int nsec = ( x->tv_usec - y->tv_usec ) / 1000000;
106 y->tv_usec += 1000000 * nsec;
107 y->tv_sec -= nsec;
108 }
109
110 /* Compute the time remaining to wait.
111 `tv_usec' is certainly positive. */
112 result->tv_sec = x->tv_sec - y->tv_sec;
113 result->tv_usec = x->tv_usec - y->tv_usec;
114
115 /* Return 1 if result is negative. */
116 return x->tv_sec < y->tv_sec;
117}

Referenced by main().

Here is the caller graph for this function:

Variable Documentation

◆ BUF

unsigned char BUF[BLEN]
extern

Definition at line 195 of file bufrnoaa.c.

Referenced by main().

◆ BUFR

unsigned char BUFR[BUFRLEN]
extern

Definition at line 25 of file bufrdeco_json.c.

◆ COLECT

int COLECT

Definition at line 38 of file bufrnoaa.h.

◆ ENTRADA

char ENTRADA[256]
extern

Definition at line 27 of file bufrdeco_json.c.

Referenced by main(), and read_args().

◆ FINAL_SEP

char FINAL_SEP[4]
extern

Definition at line 207 of file bufrnoaa.c.

Referenced by main(), and read_args().

◆ HEADER_MARK

char HEADER_MARK
extern

Header mark character who is repeated four times at the begining

Definition at line 202 of file bufrnoaa.c.

Referenced by main(), and read_args().

◆ INDIVIDUAL

int INDIVIDUAL

Definition at line 38 of file bufrnoaa.h.

◆ INSTAT

struct stat INSTAT
extern

Definition at line 204 of file bufrnoaa.c.

Referenced by main().

◆ LISTF

int LISTF
extern

if != then a list of messages in bin file is generated

Definition at line 193 of file bufrnoaa.c.

Referenced by main(), and read_args().

◆ OWN

char OWN[]
extern

Definition at line 205 of file bufrnoaa.c.

Referenced by main(), print_usage(), print_version(), and read_args().

◆ PREFIX

char PREFIX[64]

Definition at line 42 of file bufrnoaa.h.

◆ SEL

char SEL[64]
extern

Selection string for argument -T according with T1

Definition at line 197 of file bufrnoaa.c.

◆ SELECT

int SELECT

Definition at line 38 of file bufrnoaa.h.

◆ SELO

char SELO[64]

Definition at line 44 of file bufrnoaa.h.

◆ SELS

char SELS[64]

Definition at line 44 of file bufrnoaa.h.

◆ SELU

char SELU[64]

Definition at line 44 of file bufrnoaa.h.

◆ SEP

char SEP[]
extern

Definition at line 206 of file bufrnoaa.c.

Referenced by read_args().

◆ STAGE

int STAGE
extern

Definition at line 192 of file bufrnoaa.c.

Referenced by main().

◆ VERBOSE

int VERBOSE

Definition at line 38 of file bufrnoaa.h.