LOGICAL FUNCTION OPEN3( FNAME, FSTATUS, PGNAME ) CHARACTER*(*) FNAME ! file name for query INTEGER FSTATUS ! FSREAD3, FSRDWR3, FSNEW3, FSUNKN3, FSCREA3 CHARACTER*(*) PGNAME ! name of calling program
int open3c( const char * fname , const IOAPI_Bdesc3 * bdesc , const IOAPI_Cdesc3 * cdesc , int fstatus , const char * pgname ) ;
Also see GETDFILE() and GETEFILE(), for opening Fortran sequential and direct access files by logical name.
FSREAD3==1 for read-only, FSRDWR3==2 for read/write/update of existing files, FSNEW3 ==3 for read/write of new files, FSUNKN3==4 for read/write/update of unknown (new vs. old) files. If file does not exist, create it; else check for consistency with user-supplied file description FSCREA3==5 for create/truncate/read/write of files. If file exists, delete it; then create a new (empty) file according to the user-supplied file description
If FNAME is being opened for write, copies scenario description from file with logical name SCENDESC, name PGNAME of the caller, and value of environment variable EXECUTION_ID to the file's history (maintained in the file header).
If file may possibly be created (i.e., if the access mode is either FSNEW3, FSUNKN3, or FSCREA3), the user must supply a file description in the COMMONs in INCLUDE-file FDESC3.EXT (for Fortran) or in the data structures pointed to by arguments bdesc and cdesc (for C). In the latter case, the file description struct pointers are only required when the file is being opened "new" or "unknown".
NOTE: Joan Novak (EPA) and Ed Bilicki (MCNC) have declared as a software standard that modeling programs may not use FSCREA3 as the mode for opening files. FSCREA3 is reserved for use by analysis/data extraction programs only.
May be called multiple times for a file (provided you don't attempt to go from readonly to any read/write status).
INCLUDE 'IODECL3.EXT'
and
INCLUDE 'FDESC3.EXT'
for Fortran, or
#include "iodecl3.h"
and
#include "fdesc3.h"
for C.
FNAME must have length at most 16.
For FSREAD3 or FSRDWR3, file must already exist.
For FSNEW3, file must not already exist.
For FSNEW3, FSUNKN3, or FSCREA3, caller must supply file description (which must follow Models-3 date and time conventions ).
I/O API must already be initialized by a call to INIT3() or init3c().
OPEN3() must not be called for read/write/update (FSRDWR3, FSNEW3, FSUNK3, or FSCREA3) on a file already open for read-only (FSREAD3).
OPEN3() must not be called for new (FSNEW3) on a file already open.
USE M3UTILIO
(See sample programs LATLON or PRESZ for additional usage examples.)
... USE M3UTILIO ... IF ( OPEN3( 'MYFILE', FSREAD3, 'Myprogram' ) ) THEN C MYFILE successfully opened for read-only ... ELSE C Could not open MYFILE for read-only. See program log C for further info. ... END IF ... C <Fill in the file's description to variables in FDESC3.EXT> SDATE3D = 1988021 ... IF ( OPEN3( 'AFILE', FSNEW3, 'Myprogram' ) ) THEN C AFILE successfully opened as a new file ... ELSE C Could not open AFILE as a new file: probably AFILE already C exists. See program log for further info. ... END IF ... ... C <Fill in the file's description to variables in FDESC3.EXT> SDATE3D = 1988022 ... IF ( OPEN3( 'BFILE', FSUNKN3, 'Myprogram' ) ) THEN C BFILE successfully opened as unknown ... ELSE C Could not open BFILE as unknown: probably BFILE already C exists and has a different description than you gave. C See program log for further info. ... END IF ...
... #include "iodecl3.h" ... IOAPI_Bdesc3 bdesc ; IOAPI_Cdesc3 cdesc ; ... /* put file description in bdesc and cdesc. Then: */ if ( open3c( "MYFILE", &bdesc, &cdesc, FSREAD3, "Myprogram" ) ) { /* MYFILE successfully opened for read-only */ ... } ... /* etc... */
To: Models-3/EDSS I/O API: The Help Pages