HP Fortran Programmer's Reference (September 2007)

HP Fortran statements
WRITE
Chapter 10498
Description
The WRITE statement transfers data from internal storage to an external or internal file. An
external file can be opened for sequential access or direct access I/O. If it is opened for
sequential access, the WRITE statement can perform the following types of I/O:
Formatted
Unformatted
List-directed
Namelist-directed
If the file is opened for direct access, the WRITE statement can perform formatted or
unformatted I/O.
WRITE statements operating on internal files can perform formatted or list-directed I/O.
For detailed information about files and different types of I/O, see Chapter 8, “I/O and file
handling,” on page 201.
Examples
The examples in this section illustrate different uses of the WRITE statement.
Nonadvancing I/O
CHARACTER(LEN=17) :: prompt = 'Enter a number: '
WRITE (6, '(A)', ADVANCE='NO') prompt
The WRITE statement outputs to the file connected to unit 6, which is preconnected to
standard output. The ADVANCE='NO' specifier indicates the following:
The file has been opened for formatted sequential I/O.
The statement uses nonadvancing I/O to read an integer formatted as four characters into
the variable prompt.
The effect of the nonadvancing WRITE is to output the character string in prompt to standard
output without a terminating newline. This means that anything subsequently entered by the
user will appear on the same line.
Internal file
CHARACTER(LEN=80) :: cfile
WRITE (cfile, '(I5, F10.5)') i, x
The statement writes a string of characters into the internal file cfile, using the embedded
format specification to perform the format conversion.
Namelist-directed I/O