HP Fortran Programmer's Reference (September 2007)

HP Fortran statements
READ
Chapter 10444
Namelist-directed I/O
Each of the four READ statements in the next example uses a different style of syntax to do
exactly the same thing:
NAMELIST /nl/ a, b, c
READ (UNIT=5, NML=nl) ! 5 = standard input
READ (5, nl)
READ (*, NML=nl) ! * = standard input
READ nl ! assume standard input
List-directed I/O
The following statement takes its data from standard input, storing the converted value in
int_var. The format conversion is based on the type of int_var.
READ *, int_var
If you knew the format, you could substitute for the asterisk one of the following:
The label of the FORMAT statement with the format specification, as in the following:
READ 100, int_var
100 FORMAT(I4)
An embedded format specification, as in the following:
READ '(I4)', int_var
Unformatted direct-access I/O
The following statement takes its input from the file connected to unit 31. The REC= specifier
indicates that the file has been opened for direct access and that this statement will read the
record whose number is stored in the variable rec_num. If an I/O error occurs during the
execution of the statement, an error number will be stored in ios, and execution control will
branch to the executable statement at label 99.
READ (31, REC=rec_num, ERR=99, IOSTAT=ios) a, b
Related statements
CLOSE, OPEN, and WRITE.
Related concepts
For more about I/O concepts, including information about files and different types of I/O, see
Chapter 8, “I/O and file handling,” on page 201. This chapter also lists example programs that
use I/O. For information about I/O formatting, see Chapter 9, “I/O formatting,” on page 235.