Units

A unit is a means of referring to an external file. Programs refer to external files by the unit numbers indicated by unit specifiers in input/output statements. See [UNIT=] for the form of a unit specifier.

Connection of a unit

A connection refers to the association between an external file and a unit. A connection must occur before the records of a file can be read or written.

There are three ways to connect a file to a unit:

Preconnection

Preconnection occurs when the program begins executing. You can specify preconnection in I/O statements without the prior execution of an OPEN statement.

IBM Extension

Using formatted sequential access always preconnects units 0, 5 and 6 as unnamed files to the devices below:

The other properties of these files are the default specifier values for the OPEN statement with the following exceptions:

End of IBM Extension
IBM Extension

Implicit connection

Implicit connection occurs when a sequential statement that is; ENDFILE, PRINT, READ, REWIND, or WRITE executes on a unit not already connected to an external file. The executing statement connects that unit to a file with a predetermined name. By default, this connection is unit n to file fort.n. You do not need to create the file before implicit connection. To implicitly connect to a different file name, see the UNIT_VARS run-time option under Setting Run-Time Options in the XL Fortran Compiler Reference.

You can not specify unit 0 for implicit connection.

You can only connect a preconnected unit implicitly if you terminate the connection between the unit and the external file. In the next example a preconnected unit closes before implicit connection takes place.

Sample Implicit Connection

      PROGRAM TRYME
      WRITE ( 6, 10 ) "Hello1"   ! "Hello1" written to standard output
      CLOSE ( 6 )
      WRITE ( 6, 10 ) "Hello2"   ! "Hello2" written to fort.6
10    FORMAT (A)
      END

A unit with an implicit connection uses the default specifier values of the OPEN statement, except for the FORM= and ASYNCH= specifiers. The first data transfer statement determines the values for FORM= and ASYNCH=.

If the first I/O statement uses format-directed, list-directed, or namelist formatting, the value of the FORM= specifier is set to FORMATTED. An unformatted I/O statement sets the specifier to UNFORMATTED.

If the first I/O statement is asynchronous, the value of the ASYNCH= specifier is set to YES. A synchronous I/O statement sets the specifier to NO.

End of IBM Extension

Disconnection

The CLOSE statement disconnects a file from a unit. You can connect the file again within the same program to the same unit or to a different unit. You can connect the unit again within the same program to the same file or a different file.

IBM Extension

End of IBM Extension