NCEPLIBS-bufr  11.5.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 100
10 
79 void cobfl( char *bfl, char *io )
80 {
81  char lbf[MXFNLEN+1];
82  char lio;
83 
84  char errstr[150];
85 
86  char foparg[3] = " b"; /* 3rd character will automatically
87  initialize to NULL */
88  unsigned short i, j;
89 
90 /*
91 ** Copy the input arguments into local variables and check them for validity.
92 ** This is especially important in case either of the arguments was passed in
93 ** as a string literal by the calling program or else doesn't have a trailing
94 ** NULL character.
95 */
96  for ( i = 0; ( ! isspace( bfl[i] ) && ! iscntrl( bfl[i] ) ); i++ ) {
97  if ( i == MXFNLEN ) {
98  sprintf( errstr, "BUFRLIB: COBFL - INPUT FILENAME CONTAINS"
99  " MORE THAN %d CHARACTERS", MXFNLEN );
100  bort( errstr, ( f77int ) strlen( errstr ) );
101  }
102  lbf[i] = bfl[i];
103  }
104  lbf[i] = '\0';
105 
106  lio = io[0];
107  if ( ( foparg[0] = (char) tolower( lio ) ) == 'r' ) {
108  j = 0;
109  }
110  else if ( foparg[0] == 'w' ) {
111  j = 1;
112  }
113  else {
114  sprintf( errstr, "BUFRLIB: COBFL - SECOND ARGUMENT WAS (%c),"
115  " WHICH IS AN ILLEGAL VALUE", lio );
116  bort( errstr, ( f77int ) strlen( errstr ) );
117  }
118 
119 /*
120 ** If a file of this type is already open, then close it before
121 ** opening the new one.
122 */
123  if ( pbf[j] != NULL ) fclose( pbf[j] );
124 
125 /*
126 ** Open the requested file.
127 */
128  if ( ( pbf[j] = fopen( lbf, foparg ) ) == NULL ) {
129  sprintf( errstr, "BUFRLIB: COBFL - COULD NOT OPEN FILE %s", lbf );
130  bort( errstr, ( f77int ) strlen( errstr ) );
131  }
132 
133 /*
134 ** Call wrdlen to initialize some important information about the
135 ** local machine, just in case it hasn't already been called.
136 */
137  wrdlen( );
138 
139  return;
140 }
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:43
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
subroutine bort(STR)
This subroutine calls subroutine errwrt() to log an error message, then calls subroutine bort_exit() ...
Definition: bort.f:23