updated top-level README and version_decl for V4.5 (#1847)
[WRF.git] / var / external / bufr / cobfl.c
blob80453cd96d12a2247992f187e64e23cd50cfaf56
1 /*$$$ SUBPROGRAM DOCUMENTATION BLOCK
3 C SUBPROGRAM: COBFL
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
13 C NEW ONE.
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)
28 C REMARKS:
29 C THIS ROUTINE CALLS: BORT WRDLEN
30 C THIS ROUTINE IS CALLED BY: None
31 C Normally called only by application
32 C programs.
34 C ATTRIBUTES:
35 C LANGUAGE: C
36 C MACHINE: PORTABLE TO ALL PLATFORMS
38 C$$$*/
40 #define BUFRLIB_GLOBAL
41 #include "bufrlib.h"
43 #define MXFNLEN 120
45 void cobfl( char *bfl, char *io )
47 char lbf[MXFNLEN+1];
48 char lio;
50 char errstr[129];
52 char foparg[3] = " b"; /* 3rd character will automatically
53 initialize to NULL */
54 unsigned short i, j;
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
60 ** NULL character.
62 for ( i = 0; ( ! isspace( bfl[i] ) && ! iscntrl( bfl[i] ) ); i++ ) {
63 if ( i == MXFNLEN ) {
64 sprintf( errstr, "BUFRLIB: COBFL - INPUT FILENAME CONTAINS"
65 " MORE THAN %d CHARACTERS", MXFNLEN );
66 bort( errstr, ( f77int ) strlen( errstr ) );
68 lbf[i] = bfl[i];
70 lbf[i] = '\0';
72 lio = io[0];
73 if ( ( foparg[0] = (char) tolower( lio ) ) == 'r' ) {
74 j = 0;
76 else if ( foparg[0] == 'w' ) {
77 j = 1;
79 else {
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.
103 wrdlen( );
105 return;