Input-output

by Michael Metcalf / CERN CN-AS

Non-advancing I/O

Normally, records of external, formatted files are positioned at their ends after a read or write operation. This can now be overridden with the additional specifiers:
          ADVANCE = 'NO'           (default is 'YES')
          EOR = eor_label          (optional, READ only)
          SIZE = size              (optional, READ only)
An example shows how to read a record three characters at a time, and to take action if there are fewer than three left in the record:
     CHARACTER(3) key
     INTEGER unit, size
     READ (unit, '(A3)', ADVANCE='NO', SIZE=size, EOR=66) key
     :
! key is not in one record
  66 key(size+1:) = ''
     :
and how to keep the cursor positioned after a prompt:
     WRITE (*, *, ADVANCE='NO') 'Enter next prime number:'
     READ  (*, '(I10)')          prime_number

New edit descriptors

The first three new edit descriptors are modelled on the I edit descriptor: There are two new descriptors for real numbers: and the G edit descriptor is generalized to all intrinsic types (E/F, I, L, A).

For entities of derived types, the programmer must elaborate a format for the ultimate components:

     TYPE string
        INTEGER length
        CHARACTER(LEN=20) word
     END TYPE string
     TYPE(string) :: text
     READ(*, '(I2, A)') text

New specifiers

On the OPEN and INQUIRE statements there are new specifiers:
      POSITION=   'ASIS'       'REWIND'   'APPEND'
      ACTION  =   'READ'       'WRITE'    'READWRITE'
      DELIM   =   'APOSTROPHE' 'QUOTE'    'NONE'
      PAD     =   'YES'        'NO'
and on the INQUIRE there are also
      READ     = }
      WRITE    = }'YES'        'NO'       'UNKNOWN'
      READWRITE= }
Finally, inquiry by I/O list (unformatted only) is possible:
      INQUIRE (IOLENGTH = length) item1, item2,...
and this is useful to set RECL, or to check that a list is not too long. It is in the same processor-dependent units and thus is a portability aid.