15#define prtusage prtusage_
36 printf(
"\nUSAGE: %s [-v] [-h] [-g] bufrfile\n\n", prgnam );
38 printf(
" -v prints program version information and exits\n" );
39 printf(
" -h prints program help and usage information and exits\n" );
40 printf(
" -g preserves within each output file any GTS bulletin header and\n" );
41 printf(
" control characters associated with the corresponding BUFR message\n" );
42 printf(
" from the input file\n" );
43 printf(
" bufrfile [path/]name of input file containing one or more BUFR messages\n" );
44 printf(
" to be extracted into separate output files within the current\n" );
45 printf(
" working directory\n\n" );
46 printf(
"The output will be stored within the current working directory using the\n" );
47 printf(
"following filenames:\n\n" );
48 printf(
" (basename).xbfmg.out.000001\n" );
49 printf(
" (basename).xbfmg.out.000002\n" );
50 printf(
" (basename).xbfmg.out.000003\n" );
53 printf(
" (basename).xbfmg.out.(last#)\n\n" );
54 printf(
"where:\n\n" );
55 printf(
" (basename) = basename of bufrfile\n" );
56 printf(
" (last#) = total number of BUFR messages in bufrfile\n\n" );
110int main(
int argc,
char *argv[] ) {
112 struct stat fileinfo;
114 char *pc, *pmsg, *psb;
116 int save_GTSbull = 0;
118 char outfile[MXFLEN];
119 char outfile_temp[MXFLEN];
128 f77int msglen, wkint;
129 f77int c24 = 24, c1 = 1;
131 unsigned long i, filesize, noutfile;
138 while ( ( ch = getopt ( argc, argv,
"vgh" ) ) != EOF ) {
141 bvstr = (
char * ) calloc( 9,
sizeof(
char) );
142 bvers( bvstr,
sizeof(bvstr) );
143 printf(
"This is xbfmg v3.2.0, built with BUFRLIB v%s\n", bvstr );
149 printf(
"\nPROGRAM %s\n", argv[0] );
150 printf(
"\nABSTRACT: This program reads an input file containing one or more\n" );
151 printf(
" BUFR messages as given by the first argument. It then extracts each\n" );
152 printf(
" each individual BUFR message into its own separate output file within\n" );
153 printf(
" the current working directory.\n" );
163 if ( (optind+1) != argc ) {
164 printf(
"\nERROR: You must specify an input BUFR file of BUFR messages!\n" );
172 if ( stat( argv[optind], &fileinfo ) != 0 ) {
173 printf(
"\nERROR: Could not stat the file %s!\n", argv[optind] );
176 filesize = fileinfo.st_size;
181 if ( ( pc = malloc( filesize + 1 ) ) == NULL ) {
182 printf(
"\nERROR: Could not allocate memory for file %s!\n", argv[optind] );
189 if ( ( fp = fopen( argv[optind],
"rb" ) ) == NULL ) {
190 printf(
"\nERROR: Could not open input file %s!\n", argv[optind] );
193 for ( i = 0; i < filesize; i++ ) {
194 pc[i] = (char) fgetc( fp );
202 strcpy( wkstr, argv[optind] );
203 strcpy( outfile_temp, basename( wkstr ) );
204 strcat( outfile_temp,
".xbfmg.out" );
220 while ( ( ( pmsg - pc + 4 ) < filesize ) &&
221 ( ( *(pmsg) !=
'B' ) ||
222 ( *(pmsg + 1) !=
'U' ) ||
223 ( *(pmsg + 2) !=
'F' ) ||
224 ( *(pmsg + 3) !=
'R' ) ) ) {
225 if ( *pmsg ==
'\x01' ) psb = pmsg;
228 if ( ( pmsg - pc + 4 ) >= filesize ) {
236 sprintf( outfile,
"%s.%06lu", outfile_temp, ++noutfile );
237 if ( ( fp = fopen( outfile,
"wb" ) ) == NULL ) {
238 printf(
"\nERROR: Could not open output file %s!\n", outfile );
245 if ( save_GTSbull ) {
246 while ( psb < pmsg ) {
254 memcpy( &wkint, ( pmsg + 4 ), 3 );
255 msglen =
iupb( &wkint, &c1, &c24 );
260 if ( ( pmsg + msglen - pc - 1 ) <= filesize ) {
261 for ( i = 1; i <= msglen; i++ ) {
262 fputc( *pmsg++, fp );
269 if ( ( *(pmsg - 4) !=
'7' ) || ( *(pmsg - 3) !=
'7' ) ||
270 ( *(pmsg - 2) !=
'7' ) || ( *(pmsg - 1) !=
'7' ) ) {
271 printf(
"\nERROR: Could not find 7777 indicator in output file %s!\n",
278 if ( save_GTSbull ) {
Define signatures to enable a number of BUFRLIB subprograms to be called directly from C application ...
subroutine bvers(CVERSTR)
This subroutine returns a character string containing the version number of the BUFRLIB software.
function iupb(MBAY, NBYT, NBIT)
THIS FUNCTION UNPACKS AND RETURNS A BINARY INTEGER WORD CONTAINED WITHIN NBIT BITS OF A BUFR MESSAGE ...
subroutine wrdlen
This subroutine figures out some important information about the local machine on which the BUFRLIB s...
int main(int argc, char *argv[])
This program splits a single file containing one or more BUFR messages into one or more BUFR files ea...
void prtusage(char *)
This function prints program usage information to standard output.