HP Fortran Programmer's Reference (September 2007)

HP Fortran statements
WRITE
Chapter 10 499
In the next example, each of the four WRITE statements following the NAMELIST statement
uses a different style of syntax to do exactly the same thing:
NAMELIST /nl/ a, b, c
WRITE (UNIT=6, NML=nl) ! 6 = standard output
WRITE (6, nl)
WRITE (*, NML=nl) ! * = standard output
WRITE nl ! assume standard output
List-directed I/O
WRITE (6, *) int_var
This statement converts the value of int_var to character format and outputs the character
string to standard output. The format conversion is based on the type of 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:
WRITE (6, 100) int_var
100 FORMAT(I4)
An embedded format specification itself, as in:
WRITE (6, '(I4)') int_var
Unformatted direct-access I/O
WRITE (31, REC=rec_num, ERR=99, IOSTAT=ios) a, b
This statement outputs to the file connected to unit 31. The REC= specifier indicates that the
file has been opened for direct access and that this statement will output to 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.
Related statements
CLOSE, OPEN, PRINT, and READ
Related concepts
For information about I/O concepts, see Chapter 8, “I/O and file handling,” on page 201, which
also lists example programs that use I/O. For information about I/O formatting, see
Chapter 9, “I/O formatting,” on page 235.