HP Fortran Programmer's Reference (September 2007)

I/O and file handling
Connecting a file to a unit
Chapter 8 207
OPEN (9, FILE='new_file')
...
! process file
...
! terminate connection
CLOSE (9)
Performing I/O on internal files
An internal file is not connected to a unit number and therefore does not require an OPEN
statement. It is referenced as a character variable. In the following example, the WRITE
statement transfers the data from char_var to the internal file int_file, using list-directed
formatting. Because int_file is declared to be 80 characters long, it is assumed that the
length of char_var will be no more than 80 characters.
CHARACTER(LEN=80) :: int_file
...
WRITE (FILE=int_file, FMT=*) char_var
For information about internal files, see “Internal files” on page 204.
Preconnected unit numbers
Unit numbers 5, 6, and 7 are preconnected; that is, they do not have to be explicitly opened
and are connected to system-defined files, as follows:
Unit 5 is connected to standard input—by default, the keyboard of the machine on which
the program is running.
Unit 6 is connected to standard output—by default, the terminal/display of the machine
on which the program is running.
Unit 7 is connected to standard error—by default, the terminal/display of the machine on
which the program is running.
Each predefined logical unit is automatically opened when a Fortran 90 program begins
executing and remains open for the duration of the program. This means, for example, that
standard output can be used by a PRINT statement without prior execution of an OPEN
statement. Attempting to CLOSE a preconnected logical unit has no effect.
A preconnected unit number can be reused with an OPEN statement that assigns it to a new
file. Once a preconnected unit number is connected to a new file, however, it cannot be
reconnected to its original designation.
You can use the HP-UX input/output redirection (< and >) and piping (|) operators to redirect
from standard input, standard output, or standard error to a file of your own choosing.