HP Fortran Programmer's Reference (September 2007)

HP Fortran statements
OPEN
Chapter 10414
Description
The OPEN statement connects a unit to a file so that data can be read from or written to that
file. Once a file is connected to a unit, the unit can be referenced by any program unit in the
program.
I/O specifiers do not have to appear in any specific order in the OPEN statement. However, if
the optional keyword UNIT= is omitted,
unit
must be the first item in the list.
Only one unit can be connected to a file at a time. That is, the same file cannot be connected to
two different units. Attempting to open a file that is connected to a different unit will produce
undefined results.
However, multiple OPENs can be performed on the same unit. In other words, if a unit is
connected to a file that exists, it is permissible to execute another OPEN statement for the
same unit. If FILE= specifies a different file, the previously opened file is automatically closed
before the second file is connected to the unit. If FILE= specifies the same file, the file remains
connected in the same position; the values of the BLANK=, DELIM=, PAD=, ERR=, and IOSTAT=
specifiers can be changed, but attempts to change the values of any of the other specifiers will
be ignored.
Examples
The following examples illustrate different uses of the OPEN statement.
Opening a file for sequential access
The following OPEN statement connects the existing file inv to unit 10 and opens it (by
default) for sequential access. Only READ statements are permitted to perform data transfers.
If an error occurs, control passes to the executable statement labeled 100 and the error code is
placed in the variable ios:
'REPLACE' If the file does not exist, create
it with a status of OLD; if it does
exist, delete it and open it with
a status of NEW. If
STATUS='REPLACE' is specified,
FILE= must also be specified.
'SCRATCH' Create a scratch file. FILE=
specifier must
not
be specified.
For information about scratch
files, see “Scratch files” on
page 204.
Table 10-40 (Continued)