HP Fortran Programmer's Reference (September 2007)

I/O and file handling
Connecting a file to a unit
Chapter 8208
Automatically opened unit numbers
Unit numbers that have not been associated with a file by an OPEN statement can be
automatically opened using the READ or WRITE statement. When a file is automatically
opened, a string is created of the form:
ftn
XX
where
XX
is replaced by the unit number in the range 01 to 99.
If you have made an environment variable assignment of the form ftn
XX
=
path
, the file
named in
path
is opened. Otherwise, the file whose name is ftn
XX
is opened in the current
directory. If the file does not exist, it is created.
The following program
PROGRAM Auto
WRITE (11,'(A)') 'Hello, world!'
END
writes the string
Hello, world!
to the file ftn11.
If this program is compiled to a.out and is run as follows (using /bin/sh or /bin/ksh)
ftn11=datafile
export ftn11
a.out
the output string is written to the file datafile instead of ftn11.
Automatically opened files are always opened as sequential files. Other characteristics of an
automatically opened file, such as record length and format, are determined by the data
transfer statement that creates the file. If the statement does not specify formatted,
list-directed, or namelist-directed I/O, the file is created as an unformatted file.