The READ statement transfers values from an input/output unit to the data objects specified in an input list or a namelist group.
Syntax
READ (io-control-specs) [inputs] or READ format [, inputs]Where:inputs is a comma-separated list of variable or io-implied-do
variable is a variable.
io-implied-do is (inputs, implied-do-control)
implied-do-control is do-variable=start, end [, increment]
start, end, and increment are scalar numeric expressions of type INTEGER
do-variable is a scalar variable of type INTEGER
io-control-specs is a comma-separated list of:
[UNIT =] io-unit [FMT =] format [NML =] namelist-group-name REC=record IOSTAT=stat ERR=errlabel END=endlabel EOR=eorlabel ADVANCE=advance SIZE=sizeio-unit is an external file unit or *
format is a format specification (see Input/Output Editing).
namelist-group-name is the name of a namelist group.
record is the number of the direct access record that is to be read.
stat is a scalar default INTEGER variable that is assigned a positive value if an error condition occurs, a negative value if an end-of-file or end-of-record condition occurs, and zero otherwise.
errlabel is a label that is branched to if an error condition occurs and no end-of-record condition or end-of-file condition occurs during execution of the statement.
endlabel is a label that is branched to if an end-of-file condition occurs and no error condition occurs during execution of the statement.
eorlabel is a label that is branched to if an end-of-record condition occurs and no error condition or end-of-file condition occurs during execution of the statement.
advance is a scalar default CHARACTER expression that evaluates to NO if non-advancing input/output is to occur, and YES if advancing input/output is to occur. The default value is YES.
size is a scalar default INTEGER variable that is assigned the number of characters transferred by data edit descriptors during execution of the current non-advancing input/output statement.
io-control-specs must contain only one io-unit, and cannot contain both a format and a namelist-group-name.
A namelist-group-name must not appear if inputs is present.
If the optional characters UNIT= are omitted before io-unit, io-unit must be the first item in io-control-specs. If the optional characters FMT= are omitted before format, format must be the second item in io-control-specs. If the optional characters NML= are omitted before namelist-group-name, namelist-group-name must be the second item in io-control-specs.
If io-unit is an internal file, io-control-specs must not contain a REC= specifier or a namelist-group-name.
If the file is open for DIRECT, BINARY or TRANSPARENT access, an END= specifier must not appear, a namelist-group-name must not appear, and format must not be an asterisk indicating list-directed I/O.
An ADVANCE= specifier can appear only in formatted sequential I/O with an explicit format specification (format-expr) whose control list does not contain an internal file specifier. If an EOR= or SIZE= specifier is present, an ADVANCE= specifier must also appear with the value NO.
The do-variable of an implied-do-control that is contained within another io-implied-do must not appear as the do-variable of the containing io-implied-do.
Example
character(len=30) :: intfile integer :: ios read *,a,b,c ! read values from stdin ! using list directed i/o read (3,"(3i10)") i,j,k ! read from unit 3 using format read 10,i,j,k ! read stdin using format at label 10 10 format (3i10) read (11) a,b,c ! read unformatted data from unit 11 intfile=" 1 2 3" read(intfile,10) i,j,k ! read from internal file read(12,rec=2) a,b,c ! read direct access file read(13,10,err=20) i,j ! read with error branch 20 read(13,10,iostat=ios) a ! read with status return read(13,10,advance='no') i,j ! next read from same line