NCEPLIBS-bufr  11.5.0
 All Data Structures Files Functions Variables Pages
debufr.c
Go to the documentation of this file.
1 
5 #include <ctype.h>
6 #include <string.h>
7 #include <stdio.h>
8 #include <libgen.h>
9 #include <unistd.h>
10 
11 #include "bufrlib.h"
12 #include "cobfl.h"
13 
14 #ifdef UNDERSCORE
15 #define fdebufr fdebufr_
16 #define prtusage prtusage_
17 #endif
18 
19 void fdebufr( char *, char *, f77int *, char *, char *, char *, char *, char *,
20  f77int, f77int, f77int, f77int, f77int, f77int, f77int );
21 void prtusage( char * );
22 
23 #define MXFLEN 125
24 
37 void prtusage( char *prgnam ) {
38  printf( "\nUSAGE:\n" );
39  printf( " %s [-v] [-h] [-b] [-c] [-m] [-o outfile] [-t tabledir] [-f tablefil] [-p prmstg] bufrfile\n\n", prgnam );
40  printf( "\nWHERE:\n" );
41  printf( " -v prints program version information and exits\n\n" );
42  printf( " -h prints program help and usage information and exits\n\n" );
43  printf( " -b specifies the \"basic\" option, meaning that only the\n" );
44  printf( " information in Sections 0-3 will be decoded from each\n" );
45  printf( " BUFR message in the bufrfile, and no attempt will be\n" );
46  printf( " made to decode the data in Section 4\n\n" );
47  printf( " -c specifies that code and flag table meanings should not\n" );
48  printf( " be read from master BUFR tables and included in the output;\n" );
49  printf( " otherwise this feature is enabled by default\n\n" );
50  printf( " -m specifies that master BUFR tables will be used to\n" );
51  printf( " decode the data messages in the file, regardless of\n" );
52  printf( " whether it contains any embedded DX BUFR table messages.\n" );
53  printf( " This option can be used to view the actual contents of\n" );
54  printf( " DX BUFR table messages, which otherwise would not be\n" );
55  printf( " printed in the output listing.\n\n" );
56  printf( " outfile [path/]name of file to contain verbose output listing.\n" );
57  printf( " The default is \"bufrfilename.debufr.out\" in the current\n" );
58  printf( " working directory, where bufrfilename is the basename of\n" );
59  printf( " the bufrfile (i.e. bufrfile with any preceding [path/]\n" );
60  printf( " removed).\n\n" );
61  printf( " tabledir [path/]name of directory containing tables to be used\n" );
62  printf( " for decoding. This directory contains the DX BUFR tables\n" );
63  printf( " file to be used (if one was specified via the -f option),\n" );
64  printf( " or it may contain all of the master BUFR tables when these\n" );
65  printf( " are being used to decode a file. If unspecified, the\n" );
66  printf( " default directory location is\n" );
67  printf( " \"/gpfs/dell2/emc/obsproc/noscrub/Jeff.Ator/NCEPLIBS-bufr-GitHub/build3/install/tables\"\n\n" );
68  printf( " tablefil file within tabledir containing DX BUFR tables to be used\n" );
69  printf( " for decoding.\n\n" );
70  printf( " prmstg string of comma-separated PARAMETER=VALUE pairs, up to a\n" );
71  printf( " maximum of 20. For each pair, the dynamic allocation\n" );
72  printf( " PARAMETER will be set to VALUE within the underlying\n" );
73  printf( " BUFRLIB software, overriding the default value that would\n" );
74  printf( " otherwise be used. A complete list of parameters that can\n" );
75  printf( " be dynamically sized is included within the documentation\n" );
76  printf( " for BUFRLIB function isetprm.\n\n" );
77  printf( " bufrfile [path/]name of BUFR file to be decoded\n\n" );
78 }
79 
180 int main( int argc, char *argv[ ] ) {
181 
182  int ch;
183 
184  char basic = 'N';
185  char forcemt = 'N';
186  char cfms = 'Y';
187  char io = 'r';
188  char tbldir[MXFLEN] = "/gpfs/dell2/emc/obsproc/noscrub/Jeff.Ator/NCEPLIBS-bufr-GitHub/build3/install/tables";
189  char outfile[MXFLEN];
190  char wkstr[MXFLEN];
191  char wkstr2[MXFLEN];
192  char tblfil[(MXFLEN*2)+5];
193  char prmstg[300] = "NULLPSTG";
194  char bvstr[9] = " ";
195 
196  unsigned short ii;
197 
198  f77int lentd;
199 
200  /*
201  ** Get and process the valid options from the command line:
202  */
203  wkstr[0] = '\0'; /* initialize to empty string */
204  outfile[0] = '\0'; /* initialize to empty string */
205  while ( ( ch = getopt ( argc, argv, "vhbcmo:t:f:p:" ) ) != EOF ) {
206  switch ( ch ) {
207  case 'v':
208  bvers ( bvstr, sizeof(bvstr) );
209  /* append a trailing NULL to bvstr for printf */
210  for ( ii = 0; ii < sizeof(bvstr); ii++ ) {
211  if ( ( bvstr[ii] != '.' ) && ( !isdigit(bvstr[ii]) ) ) {
212  bvstr[ii] = '\0';
213  break;
214  }
215  }
216  printf( "This is debufr v3.1.0, built with BUFRLIB v%s\n",
217  bvstr );
218  return 0;
219  case 'h':
220  printf( "\nPROGRAM %s\n", argv[0] );
221  printf( "\nABSTRACT: This program decodes a BUFR file and generates a verbose\n" );
222  printf( " listing of the contents. If a DX BUFR tables file is specified\n" );
223  printf( " (using the -f option) or if the specified BUFR file contains an\n" );
224  printf( " embedded DX BUFR tables message as the first message in the file,\n" );
225  printf( " then this DX BUFR tables information is used to decode the data\n" );
226  printf( " messages in the file. Otherwise, or whenever the -m option is\n" );
227  printf( " specified, master BUFR tables are read and used to decode the\n" );
228  printf( " data messages in the file.\n" );
229  prtusage( argv[0] );
230  return 0;
231  break;
232  case 'b':
233  basic = 'Y';
234  break;
235  case 'm':
236  forcemt = 'Y';
237  break;
238  case 'c':
239  cfms = 'N';
240  break;
241  case 'o':
242  strcpy ( outfile, optarg );
243  break;
244  case 't':
245  strcpy ( tbldir, optarg );
246  break;
247  case 'f':
248  strcpy ( wkstr, optarg );
249  break;
250  case 'p':
251  strcpy ( prmstg, optarg );
252  break;
253  }
254  }
255 
256  /*
257  ** There should be one remaining command line argument specifying the
258  ** input BUFR file.
259  */
260  if ( (optind+1) != argc ) {
261  printf( "\nERROR: You must specify an input BUFR file to be decoded!\n" );
262  prtusage( argv[0] );
263  return -1;
264  }
265 
266  /*
267  ** Open the input BUFR file.
268  */
269  cobfl( argv[optind], &io );
270 
271  /*
272  ** Check whether a DX tables file was specified.
273  */
274  if ( strlen( wkstr ) > 0 ) {
275  sprintf( tblfil, "%s%c%s", tbldir, '/', wkstr );
276  }
277  else {
278  strcpy( tblfil, "NULLFILE" );
279  }
280 
281  /*
282  ** Check whether an output file was specified. If not, make a default
283  ** filename in the current working directory using the basename of the
284  ** input BUFR file.
285  */
286  if ( strlen( outfile ) == 0 ) {
287  strcpy( wkstr2, argv[optind] );
288  strcpy( outfile, basename( wkstr2 ) );
289  strcat( outfile, ".debufr.out" );
290  }
291 
292  /*
293  ** Confirm that the output directory is writeable.
294  */
295  strcpy( wkstr2, outfile );
296  strcpy( wkstr, dirname( wkstr2 ) );
297  if ( access( wkstr, W_OK ) != 0 ) {
298  printf( "\nERROR: Cannot write output file to directory %s\n",
299  ( strcmp( wkstr, "." ) == 0 ? getcwd( wkstr2, MXFLEN ) : wkstr ) );
300  prtusage( argv[0] );
301  return -1;
302  }
303 
304  /*
305  ** Read and decode each message from the input BUFR file.
306  */
307  lentd = (f77int) strlen(tbldir);
308  fdebufr( outfile, tbldir, &lentd, tblfil, prmstg, &basic, &forcemt, &cfms,
309  strlen(outfile), strlen(tbldir), strlen(tblfil), strlen(prmstg), 1, 1, 1 );
310 
311  /*
312  ** Close the input BUFR file.
313  */
314  ccbfl( );
315 
316  return 0;
317 }
Define signatures to enable a number of BUFRLIB subprograms to be called directly from C application ...
void ccbfl(void)
This subroutine closes all system files that were opened via previous calls to subroutine cobfl()...
Definition: ccbfl.c:18
void prtusage(char *)
This function prints program usage information to standard output.
Definition: debufr.c:37
subroutine fdebufr(ofile, tbldir, lentd, tblfil, prmstg, basic, forcemt, cfms)
This subroutine reads, decodes, and generates a verbose output listing of the contents of every BUFR ...
Definition: debufr.f:91
subroutine bvers(CVERSTR)
This subroutine returns a character string containing the version number of the BUFRLIB software...
Definition: bvers.f:32
Define signatures and declare variables for reading or writing BUFR messages via a C language interfa...
void cobfl(char *bfl, char *io)
This subroutine opens a new file for reading or writing BUFR messages via a C language interface...
Definition: cobfl.c:79
int main(int argc, char *argv[])
This program decodes a BUFR file and generates a verbose listing of the contents. ...
Definition: debufr.c:180