NCEPLIBS-bufr  11.7.0
 All Data Structures Files Functions Variables Pages
cobfl.c
Go to the documentation of this file.
1 
5 #include "bufrlib.h"
6 #define IN_COBFL
7 #include "cobfl.h"
8 
9 #define MXFNLEN 200
10 
82 void cobfl( char *bfl, char *io )
83 {
84  char lbf[MXFNLEN+1];
85  char lio;
86 
87  char errstr[MXFNLEN+50];
88 
89  char foparg[3] = " b"; /* 3rd character will automatically
90  initialize to NULL */
91  unsigned short i, j;
92 
93 /*
94 ** Copy the input arguments into local variables and check them for validity.
95 ** This is especially important in case either of the arguments was passed in
96 ** as a string literal by the calling program or else doesn't have a trailing
97 ** NULL character.
98 */
99  for ( i = 0; ( ! isspace( bfl[i] ) && ! iscntrl( bfl[i] ) ); i++ ) {
100  if ( i == MXFNLEN ) {
101  sprintf( errstr, "BUFRLIB: COBFL - INPUT FILENAME CONTAINS"
102  " MORE THAN %hu CHARACTERS",
103  ( unsigned short ) MXFNLEN );
104  bort( errstr, ( f77int ) strlen( errstr ) );
105  }
106  lbf[i] = bfl[i];
107  }
108  lbf[i] = '\0';
109 
110  lio = io[0];
111  if ( ( foparg[0] = (char) tolower( lio ) ) == 'r' ) {
112  j = 0;
113  }
114  else if ( foparg[0] == 'w' ) {
115  j = 1;
116  }
117  else {
118  sprintf( errstr, "BUFRLIB: COBFL - SECOND ARGUMENT WAS (%c),"
119  " WHICH IS AN ILLEGAL VALUE", lio );
120  bort( errstr, ( f77int ) strlen( errstr ) );
121  }
122 
123 /*
124 ** If a file of this type is already open, then close it before
125 ** opening the new one.
126 */
127  if ( pbf[j] != NULL ) fclose( pbf[j] );
128 
129 /*
130 ** Open the requested file.
131 */
132  if ( ( pbf[j] = fopen( lbf, foparg ) ) == NULL ) {
133  sprintf( errstr, "BUFRLIB: COBFL - COULD NOT OPEN FILE %s", lbf );
134  bort( errstr, ( f77int ) strlen( errstr ) );
135  }
136 
137 /*
138 ** Call wrdlen to initialize some important information about the
139 ** local machine, just in case it hasn't already been called.
140 */
141  wrdlen( );
142 
143  return;
144 }
Define signatures to enable a number of BUFRLIB subprograms to be called directly from C application ...
FILE * pbf[2]
File pointers.
Define signatures and declare variables for reading or writing BUFR messages via a C language interfa...
subroutine wrdlen
This subroutine figures out some important information about the local machine on which the BUFRLIB s...
Definition: wrdlen.F:35
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:82
subroutine bort(STR)
This subroutine calls subroutine errwrt() to log an error message, then calls subroutine bort_exit() ...
Definition: bort.f:22