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
int getdfilec( const char * fname , int rstatus, int fstatus, int reclen, const char * pname )
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.
#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.
... 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... ...
... #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 */ } ...
To: Models-3/EDSS I/O API: The Help Pages