HP Fortran Programmer's Reference (September 2007)

HP Fortran statements
OPEN
Chapter 10 415
OPEN(10, FILE='inv', ERR=100, I0STAT=ios, &
ACTION='READ', STATUS='OLD')
Opening a file for direct access
The following OPEN statement opens the file whose name is contained in the variable next1,
connecting it to unit 4 as a formatted, direct-access file with a record length of 50 characters:
OPEN(ACCESS=”DIRECT”, UNIT=4, RECL=50, &
FORM=”FORMATTED”, FILE=next1)
Opening a device for I/O transfers
The next example connects the system device /dev/console to unit 6; all data transfers that
specify unit 6 will go to this device:
OPEN(6,FILE='/DEV/CONSOLE')
Opening a scratch file
The following two OPEN statements produce the same results: open a scratch file that is
connected to unit 19 (if the FILE=
name
specifier had appeared in the first statement, the
named file would have been opened instead):
OPEN (UNIT=19)
OPEN (UNIT=19, STATUS=”SCRATCH”)
I/O specifiers in an OPEN statement
Because the I/O specifiers that can be used in an OPEN statement do not have to appear in any
specific order, the following three OPEN statements are all equivalent:
OPEN(UNIT=3, STATUS='NEW', FILE='OUT.DAT')
OPEN(3, STATUS='NEW', FILE='OUT.DAT')
OPEN(STATUS='NEW', FILE='OUT.DAT', UNIT=3)
Note, however, that in the second OPEN statement the number 3 must appear first because of
the omission of the optional keyword UNIT=. Thus, the following OPEN statement is illegal:
OPEN(STATUS='NEW', 3, FILE='OUT.DAT') ! illegal
Related statements
CLOSE, INQUIRE, READ, and WRITE
Related concepts
For information about I/O concepts and examples of programs that perform I/O, see
Chapter 8, “I/O and file handling,” on page 201. For information about I/O formatting, see
Chapter 9, “I/O formatting,” on page 235.