1 /*$$$ SUBPROGRAM DOCUMENTATION BLOCK
4 C PRGMMR: ATOR ORG: NP12 DATE: 2005-11-29
6 C ABSTRACT: THIS ROUTINE OPENS A SPECIFIED SYSTEM FILE FOR READING
7 C OR WRITING VIA THE BUFR ARCHIVE LIBRARY C I/O INTERFACE. THERE
8 C CAN BE AT MOST TWO SYSTEM FILES OPEN AT ANY GIVEN TIME (ONE FOR
9 C READING/INPUT AND ONE FOR WRITING/OUTPUT). IF A CALL TO THIS
10 C ROUTINE IS MADE FOR EITHER READING/INPUT OR WRITING/OUTPUT AND
11 C SUCH A FILE IS ALREADY OPEN TO THE BUFR ARCHIVE LIBRARY C I/O
12 C INTERFACE, THEN THAT FILE WILL BE CLOSED BEFORE OPENING THE
15 C PROGRAM HISTORY LOG:
16 C 2005-11-29 J. ATOR -- ORIGINAL AUTHOR
18 C USAGE: CALL COBFL( BFL, IO )
19 C INPUT ARGUMENT LIST:
20 C BFL - CHARACTER*(*): SYSTEM FILE TO BE OPENED. INCLUSION
21 C OF DIRECTORY PREFIXES OR OTHER LOCAL FILESYSTEM
22 C NOTATION IS ALLOWED UP TO 120 TOTAL CHARACTERS.
23 C IO - CHARACTER: FLAG INDICATING HOW BFL IS TO BE OPENED
24 C FOR USE WITH THE C I/O INTERFACE:
25 C 'r' = READING (INPUT)
26 C 'w' = WRITING (OUTPUT)
29 C THIS ROUTINE CALLS: BORT WRDLEN
30 C THIS ROUTINE IS CALLED BY: None
31 C Normally called only by application
36 C MACHINE: PORTABLE TO ALL PLATFORMS
40 #define BUFRLIB_GLOBAL
45 void cobfl( char *bfl
, char *io
)
52 char foparg
[3] = " b"; /* 3rd character will automatically
57 ** Copy the input arguments into local variables and check them for validity.
58 ** This is especially important in case either of the arguments was passed in
59 ** as a string literal by the calling program or else doesn't have a trailing
62 for ( i
= 0; ( ! isspace( bfl
[i
] ) && ! iscntrl( bfl
[i
] ) ); i
++ ) {
64 sprintf( errstr
, "BUFRLIB: COBFL - INPUT FILENAME CONTAINS"
65 " MORE THAN %d CHARACTERS", MXFNLEN
);
66 bort( errstr
, ( f77int
) strlen( errstr
) );
73 if ( ( foparg
[0] = (char) tolower( lio
) ) == 'r' ) {
76 else if ( foparg
[0] == 'w' ) {
80 sprintf( errstr
, "BUFRLIB: COBFL - SECOND ARGUMENT WAS (%c),"
81 " WHICH IS AN ILLEGAL VALUE", lio
);
82 bort( errstr
, ( f77int
) strlen( errstr
) );
86 ** If a file of this type is already open, then close it before
87 ** opening the new one.
89 if ( pbf
[j
] != NULL
) fclose( pbf
[j
] );
92 ** Open the requested file.
94 if ( ( pbf
[j
] = fopen( lbf
, foparg
) ) == NULL
) {
95 sprintf( errstr
, "BUFRLIB: COBFL - COULD NOT OPEN FILE %s", lbf
);
96 bort( errstr
, ( f77int
) strlen( errstr
) );
100 ** Call wrdlen to initialize some important information about the
101 ** local machine, just in case it hasn't already been called.