GETDFILE()

Fortran version:

    INTEGER FUNCTION GETDFILE( LNAME, RDONLY, FMTFLAG, RECLEN, CALLER )
        CHARACTER*(*), INTENT(IN   ) :: LNAME          !  logical file name
        LOGICAL      , INTENT(IN   ) :: RDONLY         !  TRUE iff file is input-only
        LOGICAL      , INTENT(IN   ) :: FMTFLAG        !  TRUE iff file should be formatted
        INTEGER      , INTENT(IN   ) :: RECLEN         !  direct access record length
        CHARACTER*(*), INTENT(IN   ) :: CALLER         !  caller-name for logging

C version:

    int getdfilec( const char          * fname ,
                   int                   rstatus,
                   int                   fstatus,
                   int                   reclen,
                   const char          * pname )

See also:

GETEFILE() for sequential files instead of direct access files, and PROMPTDFILE(), a wrapper around GETDFILE() that prompts the user for the file's logical name.

Summary:

Gets value of logical name LNAME from the environment, checks for existence of a file whose file name is that value, then opens the file as a Fortran direct access file with the indicated record length RECLEN, according to the LOGICAL flags RDONLY (open for read-only iff TRUE, read/write if FALSE) and FMTFLAG (formatted iff TRUE, else unformatted).

WARNING: interpretation of RECLEN — whether it measures record length in words or in bytes — is vendor-dependent (and not always easy to dig out of the vendor's documentation). For gfortran, sunf95, and pgf90, record length is specified in bytes; for ifort, record length is specified in 4-byte "words" unless the compiler command-line flag -assume byterecl is used, in which case record length is specified in bytes.
Note that mis-interpretation of this can lead to obscure run-time errors...

Logs the file-opening, together with the CALLER version, and returns the unit number of the file opened, or -1 for failure.

Uses JUNIT() to get a unit number.

For Fortran-90 declarations and interface checking:

    USE M3UTILIO
    

See also GETEFILE() for opening sequential Fortran files.

Preconditions:

#include "iodecl3.h" if called from C.

Logical name for the file set (else it will open a file with the indicated name in the current working directory).

If RDONLY, file must already exist.

If file already exists, record lengths must be consistent.

Fortran Usage:

    ...
    INTEGER        JDEV, KDEV, LDEV, MDEV
    INTEGER        GETDFILE
    ...
    JDEV = GETDFILE( 'AFILE, .TRUE. , .TRUE. , 512, 'me' ) ! read-only  formatted
    KDEV = GETDFILE( 'BFILE, .TRUE. , .FALSE., 512, 'me' ) ! read-only  unformatted
    LDEV = GETDFILE( 'CFILE, .FALSE., .TRUE. , 512, 'me' ) ! read-write formatted
    MDEV = GETDFILE( 'DFILE, .FALSE., .FALSE., 512, 'me' ) ! read-write unformatted
    ...
    IF ( JDEV .LT. 0 ) THEN
        !  error opening AFILE:  deal with it
        ...
    END IF
    ...etc...
    ...

C Usage:

    ...
    #include "iodecl3.h"
    ...
    integer   jdev ;
    if ( 0 > ( jdev = getdfilec( "AFILE", 1, 1, 512, "me from C" ) ) )
        {
        /*  oops -- attempt to open file with logical name AFILE failed */
        }
    ...


Previous: GETDBLE

Next: GETEFILE

Up: Utility Routines

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