OPEN3() and open3c()

Fortran version:

    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

C version:

open3c() is a C wrapper calling the Fortran OPEN3()
    int open3c( const char          * fname ,
                const IOAPI_Bdesc3  * bdesc ,
                const IOAPI_Cdesc3  * cdesc ,
                int                   fstatus ,
                const char          * pgname ) ;

See Also:

PROMPTMFILE(), which is a (text-mode interactive) wrapper around OPEN3() that prompts the user for the logical name of the file to be opened.

Also see GETDFILE() and GETEFILE(), for opening Fortran sequential and direct access files by logical name.

Summary:

Open or create Models-3 file with logical name FNAME, with file mode/status FSTATUS of one of the following "magic number" tokens (defined in INCLUDE-file PARMS3.EXT ):
    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).

Preconditions:

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.

Fortran Usage:

For Fortran-90 declarations and interface checking:
    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&gt;
    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&gt;
    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
    ...

C Usage:

    ...
    #include &quot;iodecl3.h&quot;
    ...
    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... */


Previous: INTERP3

Next: READ3

Up: Public I/O Routines

To: Models-3/EDSS I/O API: The Help Pages