210int main (
int argc,
char *argv[] )
212 size_t nb = 0, nc, nx = 0, nbuf = 0, nsel = 0, nerr = 0, i, nh = 0, nw;
216 unsigned char b[4], header[256];
217 unsigned int expected = 0;
218 char name[256], namex[256], namec[256];
220 struct timeval tini, tfin, tt;
223 gettimeofday ( &tini, NULL );
228 exit ( EXIT_FAILURE );
234 printf (
"%s: Cannot stat %s\n",
OWN,
ENTRADA );
235 exit ( EXIT_FAILURE );
239 if ( ( ficin = fopen (
ENTRADA,
"r" ) ) == NULL )
241 printf (
"%s: Cannot open %s\n",
OWN,
ENTRADA );
242 exit ( EXIT_FAILURE );
254 if ( ( ficol = fopen ( namec,
"w" ) ) == NULL )
256 printf (
"%s: Cannot open %s\n",
OWN, namec );
257 exit ( EXIT_FAILURE );
264 memset ( &b, 0, 4 *
sizeof (
unsigned char ) );
266 while ( ( nc = fread ( &
BUF[0],
sizeof (
unsigned char ),
BLEN, ficin ) ) > 0 )
268 for ( i = 0; i < nc ; i++ )
281 memset ( &header[0], 0, 64 *
sizeof (
unsigned char ) );
315 if ( b[0] != 0x0a && b[0] != 0x0d )
318 memset ( &name[0], 0, 128 *
sizeof (
unsigned char ) );
337 if ( b[0] == 0x01a || b[0] == 0x0d )
343 else if ( b[0] ==
' ' )
377 printf (
"Error: Bufr message length > %d",
BUFRLEN );
379 exit ( EXIT_FAILURE );
384 expected = (
unsigned int ) b[0] + (
unsigned int ) b[1] * 256 + (
unsigned int ) b[2] * 65536;
399 if ( nb == expected )
406 printf (
"%s\n", name );
414 strcat ( namex,
"_" );
415 strcat ( namex, name );
416 strcat ( namex,
".bufr" );
417 if ( ( ficout = fopen ( namex,
"w" ) ) == NULL )
419 printf (
"Error: cannot open %s\n", name );
421 exit ( EXIT_FAILURE );
423 if ( ( nw = fwrite ( &
BUFR[0],
sizeof (
unsigned char ), nb, ficout ) ) != nb )
425 printf (
"Error: Writen %lu bytes instead of %lu in %s file\n", nw, nb, namex );
428 exit ( EXIT_FAILURE );
438 if ( ( nw = fwrite ( &header[0],
sizeof (
char ), nh, ficol ) ) != nh )
440 printf (
"%s: Error: Writen %lu bytes instead of %lu in %s file\n",
OWN, nw, nh, namec );
443 exit ( EXIT_FAILURE );
447 if ( ( nw = fwrite ( &
BUFR[0],
sizeof (
unsigned char ), nb, ficol ) ) != nb )
449 printf (
"%s: Error: Writen %lu bytes instead of %lu in %s file\n",
OWN, nw, nb, namex );
452 exit ( EXIT_FAILURE );
457 if ( ( nw = fwrite ( &
FINAL_SEP[0],
sizeof (
char ), 3, ficol ) ) != 3 )
459 printf (
"%s: Error: Writen %lu bytes instead of 3 chars separing messages in %s\n",
OWN, nw, namex );
462 exit ( EXIT_FAILURE );
488 gettimeofday ( &tfin, NULL );
494 printf (
"Found %lu bufr reports. Selected: %lu. Wrong: %lu\n", nbuf, nsel, nerr );
496 tx = ( double ) tt.tv_sec + (
double ) tt.tv_usec *1e-6;
497 printf (
"%lf seg. ", tx );
498 if ( nbuf && tx != 0.0 )
499 printf (
"%lf reports/sec.\n", (
double ) nbuf / tx );
503 exit ( EXIT_SUCCESS );
int read_args(int _argc, char *_argv[])
read the arguments from stdio
int main(int argc, char *argv[])
unsigned char BUFR[BUFRLEN]
inclusion file for binary bufrnoaa
int bufr_is_selected(char *name)
returns 1 if selected message 0 otherwise
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
int is_endb(unsigned char *b)
checks if an unsigned char from an array is the first char of '7777'
int mtime_from_stat(char *filename, struct stat *st)
modifies a file update time from a struct stat
int date_mtime_from_stat(char *date, struct stat *st)
get a string with date and time from a struct stat
int is_bufr(unsigned char *b)
checks if an unsigned char from an array is the first char of 'BUFR'
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.