Creating Files with the OPEN Statement [ HP FORTRAN 77/iX Programmer's Guide ] MPE/iX 5.0 Documentation
HP FORTRAN 77/iX Programmer's Guide
Creating Files with the OPEN Statement
Existing files (OLD or TEMP) connected with the OPEN statement already
have defined characteristics; therefore, the arguments to the FOPEN
intrinsic are ignored. Similarly, FILE equations referenced in the OPEN
statement are overridden by the characteristics of the corresponding
device or file.
By default, files connected by the OPEN statement processor besides FTN05
and FTN06 are opened by FOPEN with AOPTIONS of 4, requesting read/write
access. This prepares the system for any arbitrary mix of READ and WRITE
statements. As an extension to the ANSI standard, the READONLY specifier
on OPEN is allowed. Such files are opened by FOPEN with AOPTIONS of 0,
requesting readonly access. OPEN statements corresponding to files (or
file equations) that can only be read or written are valid unless an
operation is requested that is not allowed on the file. Invalid requests
cause a file system error.
STATUS='NEW'
When the OPEN statement specifies STATUS='NEW', the FORTRAN compiler
makes sure that the referenced file does not exist by attempting to open
the file as an MPE/iX OLD or TEMP file. If the file exists, the file is
closed and an error is reported. Normally, the first FOPEN fails because
no file exists and the FOPEN is tried again with FOPTIONS requesting an
MPE/iX NEW file. This attempt usually succeeds in creating the file; if
not, a file system error is reported.
STATUS='OLD'
When the OPEN statement specifies STATUS='OLD', the corresponding FOPEN
intrinsic specifies to only search the MPE/iX OLD or TEMP file domains.
The temporary job domain is searched first; therefore, TEMP files are
connected before permanent (OLD) files of the same name. If the FOPEN
fails (no such named file exists), an error is reported.
STATUS='SCRATCH'
When the OPEN statement specifies STATUS='SCRATCH', the file is opened as
a nameless MPE/iX file. Therefore, in accordance with the ANSI standard,
it is impossible to save the file. If the file is not a scratch file,
the file is defined by the FORM and ACCESS options in the OPEN statement.
STATUS='UNKNOWN'
OPEN statements that omit the STATUS specifier default to
STATUS='UNKNOWN'. STATUS='UNKNOWN' is implemented as if OLD were
specified, with the exception that if the first FOPEN fails, the open is
reattempted with NEW status.
FORM='UNFORMATTED' and FORM='FORMATTED'
The FORM option specifies the type of transfers that can be performed on
the file. FORM='UNFORMATTED' implies that only unformatted (binary)
transfers are performed, so an MPE/iX BINARY file is requested in the
corresponding FOPEN intrinsic. When the OPEN statement specifies
FORM='UNFORMATTED', bit 13 is cleared to zero in the FOPTIONS parameter.
The default FORM='FORMATTED' implies that only formatted and/or
list-directed transfers can be performed. Accordingly, an MPE/iX ASCII
file is requested by setting bit 13 in the FOPTIONS parameter.
Attempting a transfer type not allowed on the associated file results in
an error.
ACCESS='SEQUENTIAL'
Sequential READ and WRITE statements can have I/O lists of records with
varying lengths; in fact, the ANSI standard does not specify an upper
limit to the length of a sequential record. To efficiently implement
varying lengths, use MPE/iX variable record length files as the default
sequential file type (FOPTIONS bit eight cleared to zero and bit nine
set). This implies that files opened for sequential access cannot be
accessed directly because it is impossible to access variable record
length files by FREADDIR or FWRITEDIR. The record length requested for
sequential files is zero, implying that the MPE/iX default of the
configured physical record size of the device is to be used (256 bytes on
disk files). Also, on variable record length files created by the OPEN
statement, the MPE/iX default becomes the maximum logical record length.
The default can be overridden by using a FILE equation that specifies a
longer record length. For example, the command
:FILE outfile; REC = -5120,,V,ASCII
specifies that variable length records up to 5120 bytes long can be
written or read.
The FCONTROL intrinsic that implements the BACKSPACE statement for files
of fixed and undefined record lengths does not apply to variable record
length files. Therefore, variable record length files must be backspaced
by rewinding and then reading forward to the previous record. Even
though the FORTRAN 77 library performs the rewinding and reading forward,
this is clearly not a performance feature of the implementation. A file
equation to specify a new file as fixed record length type will save
execution time for programs that often backspace.
ACCESS='DIRECT'
OPEN statements that specify ACCESS='DIRECT' must include the maximum
length of the records to be read or written. This allows fixed record
length files of the appropriate length to be requested in the FOPEN.
Accordingly, bits eight and nine of the FOPTIONS are set to zero for the
FOPEN call. The required RECL specifier sets the record length of the
file created. If an odd number of bytes is requested for the RECL option
on a direct unformatted file, MPE/iX rounds the length up to the next
higher word length (the byte count becomes even). This is done because
binary files are strictly defined in terms of 16-bit words. The
increased byte count is returned if the INQUIRE statement requests the
record length.
MPE/iX 5.0 Documentation