FORTRAN 77 Language Reference

Description

The READ statement accepts the following arguments.

Unit Identifier

u is either an external unit identifier or an internal file identifier.

An external unit identifier must be one of these:

If the optional characters UNIT= are omitted from the unit specifier, then u must be the first item in the list of specifiers.

Format Identifier

f is a format identifier and can be:

See "Runtime Formats " for details on formats evaluated at runtime.

If the optional characters, FMT=, are omitted from the format specifier, then f must appear as the second argument for a formatted read; otherwise, it must not appear at all.

Unformatted data transfer from internal files and terminal files is not allowed, hence, f must be present for such files.

List-directed data transfer from direct-access and internal files is allowed; hence, f can be an asterisk for such files. @

If a file is connected for formatted I/O, unformatted data transfer is not allowed, and vice versa.

I/O Status Specifier

ios must be an integer variable or an integer array element.

Record Number

rn must be a positive integer expression, and can be used for direct-access files only. rn can be specified for internal files. @

End-of-File Specifier

s must be the label of an executable statement in the same program unit in which the READ statement occurs.

The END=s and REC=rn specifiers can be present in the same READ statement. @

Error Specifier

s must be the label of an executable statement in the same program unit in which the READ statement occurs.

Input List

iolist can be empty or can contain input items or implied DO lists. The input items can be any of the following:

A simple unsubscripted array name specifies all of the elements of the array in memory storage order, with the leftmost subscript increasing more rapidly.

Implied DO lists are described on "Implied DO Lists".

Namelist-Directed READ

The third and fourth forms of the READ statement are used to read the items of the specified namelist group, and grname is the name of the group of variables previously defined in a NAMELIST statement.

Execution

Execution proceeds as follows:

  1. The file associated with the specified unit is determined.

    The format, if specified, is established. The file is positioned appropriately prior to the data transfer.

  2. If the input list is not empty, data is transferred from the file to the corresponding items in the list.

    The items are processed in order as long as the input list is not exhausted. The next specified item is determined and the value read is transmitted to it. Data editing in formatted READ is done according to the specified format.

  3. In the third and fourth forms of namelist-directed READ, the items of the specified namelist group are processed according to the rules of namelist-directed input.

  4. The file is repositioned appropriately after data transfer.

  5. If ios is specified and no error occurred, it is set to zero.

    ios is set to a positive value, if an error or end of file was encountered.

  6. If s is specified and end of file was encountered, control is transferred to s.

  7. If s is specified and an error occurs, control is transferred to s.

There are two forms of READ:

READ f [, iolist]

READ([NML= ] grname)

The above two forms operate the same way as the others, except that reading from the keyboard is implied.

Execution has the following differences:

If u specifies an external unit that is not connected to a file, an implicit OPEN operation is performed equivalent to opening the file with the options in the following example:


       OPEN(u,
FILE='FORT.u', STATUS='OLD', ACCESS='SEQUENTIAL', 
&              FORM=fmt
)

Note also: