HP Fortran Programmer's Reference (September 2007)

HP Fortran statements
READ
Chapter 10 443
Description
The READ statement transfers data from an external or internal file to internal storage. An
external file can be opened for sequential access or direct access. If it is opened for sequential
access, the READ statement can perform the following types of I/O:
Formatted
Unformatted
List-directed
Namelist-directed
If the file is opened for direct access, the READ statement can perform formatted or
unformatted I/O.
READ statements operating on internal files can perform formatted or list-directed I/O.
Examples
The following examples illustrate different uses of the READ statement.
Formatted sequential I/O
The following READ statement reads 10 formatted records from a file opened for sequential
access, using an implied-DO list to read the data into the array x_array. If the end-of-file
record is encountered before the array is filled, execution control passes to the statement at
label 99.
READ (41, '(F10.2)', END=99) (x_array(i),i=1,10)
Nonadvancing I/O
The following READ statement takes its input from a file that was opened for sequential access
and is connected to unit 9. It uses nonadvancing I/O to read an integer into the variable key.
If the statement encounters the end-of-record condition before it can complete execution,
control will pass to the executable statement at label 100. After the statement executes, the
number of characters that have been read will be stored in cnt.
INTEGER :: key
READ (UNIT=9, '(I4)', ADVANCE='NO', SIZE=cnt, EOR=100) key
Internal file
The following statement inputs a string of characters from the internal file cfile, uses an
embedded format specification to perform format conversion, and stores the results in the
variables i and x:
READ (cfile, FMT='(I5, F10.5)') i, x