## 10.3.4 Forms and Rules for Internal READ Statements

Internal READ statements transfer input data from an internal file.

An internal READ statement can only be formatted. It must include format specifiers (which can use list-directed formatting). Namelist formatting is not permitted.

An internal READ statement takes the following form:

  READ (iunit, format [, iostat] [, err] [, end]) [io-list]
  iunit
  Is an internal unit specifier ([UNIT=]io-unit). It must be a character variable. It must not be an array section with a vector subscript.
  format
  Is a format specifier ([FMT=]format). An asterisk (*) indicates list-directed formatting.
  iostat
  Is a status specifier (IOSTAT=i-var).
  err, end
  Are branch specifiers if an error (ERR=label) or end-of-file (END=label) condition occurs.
  io-list
  Is an I/O list.

Formatted, internal READ statements translate data from character to binary form by using format specifications for editing (if any). The translated data is assigned to the entities in the I/O list in the order in which the entities appear, from left to right.

This form of READ statement behaves as if the format begins with a BN edit descriptor. (You can override this behavior by explicitly specifying the BZ edit descriptor.)

Values can be transferred to objects of intrinsic or derived types. For derived types, values of intrinsic types are transferred to the components of intrinsic types that ultimately make up these structured objects.

Before data transfer occurs, the file is positioned at the beginning of the first record. This record becomes the current record.

If the number of I/O list items is less than the number of fields in an input record, the statement ignores the excess fields.

If the number of I/O list items is greater than the number of fields in an input record, the input record is padded with blanks. However, if PAD='NO' was specified for file connection, the input list and file specification must not require more characters from the record than it contains.

In list-directed formatting, character strings have no delimiters.

Examples

The following program segment reads a record and examines the first character to determine whether the remaining data should be interpreted as decimal, octal, or hexadecimal. It then uses internal READ statements to make appropriate conversions from character string representations to binary.

    INTEGER IVAL
    CHARACTER TYPE, RECORD*80
    CHARACTER*(*) AFMT, IFMT, OFMT, ZFMT
    PARAMETER (AFMT='(Q,A)', IFMT= '(I10)', OFMT= '(O11)',        &
               ZFMT= '(Z8)')
    ACCEPT AFMT, ILEN, RECORD
    TYPE = RECORD(1:1)
    IF (TYPE .EQ. 'D') THEN
        READ (RECORD(2:MIN(ILEN, 11)), IFMT) IVAL
    ELSE IF (TYPE .EQ. 'O') THEN
        READ (RECORD(2:MIN(ILEN, 12)), OFMT) IVAL
    ELSE IF (TYPE .EQ. 'X') THEN
        READ (RECORD(2:MIN(ILEN, 9)),ZFMT) IVAL
    ELSE
        PRINT *, 'ERROR'
    END IF
    END

For More Information:

- On I/O control-list specifiers, see Section 10.2.1.
- On I/O lists, see Section 10.2.2.
- On list-directed input, see Section 10.3.1.2.
- On using internal files, see your user manual or programmer's guide.

Previous Page Next Page Table of Contents