Next: WRITE Statement
Up: Input / Output
Previous: OPEN Statement
Syntax (not all the specifiers can be used at the same time,)
READ([UNIT=]< unit >, [FMT=]< format >, IOSTAT=< int-variable >, ERR=< label >, &
END=< label >, EOR=< label >, ADVANCE=< advance-mode >, REC=< int-expr >, &
SIZE=< num-chars >) < output-list >
where
- UNIT=< unit > is a valid logical unit number or
* for the default (standard) output, if it is the first field then
the specifier is optional.
- FMT=< format > is a string of formatting
characters, a valid FORMAT statement label or a *
for free format. If this is the second field then the specifier is
optional.
- IOSTAT=< int-variable > specifies an integer variable to
hold a return code,
as usual, zero means no error.
- < label > in ERR= is a valid label to where
control jumps if there is a read error.
- < label > in END= is a valid label to where
control jumps if an end-of-file is encountered, this can only be present
in a READ statement.
- < advance-mode > specifies whether each READ should
start a new record or not, setting the specifier to 'NO' initiates
non-advancing I/O. The default is 'YES'. If non-advancing I/O is
used then the file must be connected for
sequential access and the format must be explicitly stated.
- EOR will jump to the specified label if an end-of-record is
encountered. This can only be present in a READ statement and only
if ADVANCE='NO' is also present.
- REC=< int-expr > is the record number for direct access.
- the SIZE specifier is used in conjunction with an integer
variable, in this case nch. The variable will hold the number of
characters read. This can only be present in a READ statement and only
if ADVANCE='NO' is also present.
Consider,
READ(14,FMT='(3(F10.7,1x))',REC=iexp) a,b,c
here, the record specified by the integer
iexp is read -- this record should contain 3 real numbers
separated by a space with 10 column and 7 decimal places. The values
will be placed in a, b and c.
READ(*,'(A)',ADVANCE='NO',EOR=12,SIZE=nch) str
Since non-advancing output has been specified, the cursor will remain
on the same line as the string is read. Under normal
circumstances (default advancing output) the cursor would be positioned
at the start of the next line. Note the explicit format descriptor.
SIZE reurns the length of the string and EOR= specifies an
destination if an end-of-record is encountered.
Return to corresponding overview page
Next: WRITE Statement
Up: Input / Output
Previous: OPEN Statement
©University of Liverpool, 1997
Wed May 28 20:20:27 BST 1997Not for commercial use.