next up previous index
Next: Index Up: Fortran 90 Tutorial Previous: Intrinsic Procedures

Input/Output

 

Non-advancing input/output

 

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)

The next 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:) = ''
     :

This shows how to keep the cursor  positioned after a prompt  :

     WRITE (*, '(A)', 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:

B
binary,
O
octal,
Z
hexadecimal.

There are two new descriptors for real numbers:

EN
engineering, multiple-of-three exponent: 0.0217->21.70E-03(EN9.2)
ES
scientific, leading nonzero digit: 0.0217->2.17E-02(ES9.2)

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 as RECL and thus is a portability aid.



next up previous index
Next: Index Up: Fortran 90 Tutorial Previous: Intrinsic Procedures


Michel Goossens Mon Dec 18 12:34:22 MET 1995