Statement: Transfers input data from external sequential, direct-access, or internal records.
Syntax
Sequential
Formatted:
READ (eunit, format [, advance] [, asynchronous] [, id] [, size] [, iostat] [, err] [, end] [, eor]) [io-list]
READ form [, io-list]
Formatted - List-Directed:
READ (eunit, * [, asynchronous] [, id] [, iostat] [, err] [, end]) [io-list]
READ * [, io-list]
Formatted - Namelist:
READ (eunit, nml-group [, iostat] [, err] [, end])
READ nml
Unformatted:
READ (eunit [, asynchronous] [, id] [, iostat] [, err] [, end]) [io-list]
Direct-Access
Formatted:
READ (eunit, format, rec [, asynchronous] [, id] [, iostat] [, err]) [io-list]
Unformatted:
READ (eunit, rec [, asynchronous] [, id] [, iostat] [, err]) [io-list]
Internal
READ (iunit, format [, iostat] [, err] [, end]) [io-list]
eunit
Is an external unit specifier, optionally prefaced by UNIT=. UNIT= is required if eunit is not the first specifier in the list.
format
Is a format specifier. It is optionally prefaced by FMT= if format is the second specifier in the list and the first specifier indicates a logical or internal unit specifier without the optional keyword UNIT=.
For internal READs, an asterisk (*) indicates list-directed formatting. For direct-access READs, an asterisk is not permitted.
advance
Is an advance specifier (ADVANCE=c-expr). If the value of c-expr is 'YES', the statement uses advancing input; if the value is 'NO', the statement uses nonadvancing input. The default value is 'YES'.
asynchronous
Is an asynchronous specifier (ASYNCHRONOUS=i-expr).
If the value of i-expr is 'YES', the statement uses asynchronous input; if the value is 'NO',
the statement uses synchronous input. The default value is 'NO'.
id
Is an id specifier (ID=id-var) that identifies a pending data transfer operation for the specified unit. If an id is specified, a wait
operation is performed for the operation. If it is omitted, wait operations are
performed for all pending data transfers for the specified unit. This specifier can only be used if the
value of ASYNCHRONOUS=i-expr is 'YES'.
size
Is a character count specifier (SIZE=i-var). It can only be specified for nonadvancing READ statements.
iostat
Is the name of a variable to contain the completion status of the I/O operation. Optionally prefaced by IOSTAT=.
err, end, eor
Are branch specifiers if an error (ERR=label), end-of-file (END=label), or end-of-record (EOR=label) condition occurs.
EOR can only be specified for nonadvancing READ statements.
io-list
Is an I/O list: the names of the variables, arrays, array elements, or character substrings from which or to which data will be transferred. Optionally an implied-DO list.
form
Is the nonkeyword form of a format specifier (no FMT=).
*
Is the format specifier indicating list-directed formatting. (It can also be specified as FMT=*.)
nml-group
Is the namelist group specification for namelist I/O. Optionally prefaced by NML=. NML= is required if nml-group is not the second I/O specifier. For more information, see Namelist Specifier.
nml
Is the nonkeyword form of a namelist specifier (no NML=) indicating namelist I/O.
rec
Is the cell number of a record to be accessed directly. Optionally prefaced by REC=.
iunit
Is an internal unit specifier, optionally prefaced by UNIT=. UNIT= is required if iunit is not the first specifier in the list.
It must be a character variable. It must not be an array section with a vector subscript.
If an item in io-list is an expression that calls a function, that function must not execute an I/O statement or the EOF intrinsic function on the same external unit as eunit.
If I/O is to or from a formatted device, io-list cannot contain derived-type variables, but it can contain components of derived types. If I/O is to a binary or unformatted device, io-list can contain either derived type components or a derived type variable.
The READ statement can disrupt the results of certain graphics text functions (such as SETTEXTWINDOW) that alter the location of the cursor. You can avoid the problem by getting keyboard input with the GETCHARQQ function and echoing the keystrokes to the screen using OUTTEXT. Alternatively, you can use SETTEXTPOSITION to control cursor location.
See Also
I/O Lists, I/O Control List, Forms for Sequential READ Statements, Forms for Direct-Access READ Statements, Forms and Rules for Internal READ Statements, PRINT, WRITE, I/O Formatting
Example
DIMENSION ia(10,20)
! Read in the bounds for the array.
! Then read in the array in nested implied-DO lists
! with input format of 8 columns of width 5 each.
READ (6, 990) il, jl, ((ia(i,j), j = 1, jl), i =1, il)
990 FORMAT (2I5, /, (8I5))
! Internal read gives a variable string-represented numbers
CHARACTER*12 str
str = '123456'
READ (str,'(i6)') i
! List-directed read uses no specified format
REAL x, y
INTEGER i, j
READ (*,*) x, y, i, j