Sun Studio 12: Fortran Programming Guide

2.1.3 Opening Files Without an OPEN Statement

Use of the OPEN statement is optional in those cases where default conventions can be assumed. If the first operation on a logical unit is an I/O statement other than OPEN or INQUIRE, the file fort.n is referenced, where n is the logical unit number (except for 0, 5, and 6, which have special meaning).

These files need not exist before program execution. If the first operation on the file is not an OPEN or INQUIRE statement, they are created.

Example: The WRITE in the following code creates the file fort.25 if it is the first input/output operation on that unit:


demo% cat TestUnit.f
      IU=25
      WRITE( IU, ’(I4)’ ) IU
      END
demo%

The preceding program opens the file fort.25 and writes a single formatted record onto that file:


demo% f95 -o testunit TestUnit.f
demo% testunit
demo% cat fort.25
  25
demo%