How are Fortran files chosen

The statement disconnects a file from a unit.



Unit identifier for an external unit. If is not used, then u must be first.

Determines the disposition of the file-- is a character expression whose value, when trailing blanks are removed, can be or . The default value for the status specifier is . For temporary (scratch) files, is forced to always. For other files besides scratch files, the default is .

I/O status specifier-- must be an integer variable or an integer array element.

Error specifier-- must be the label of an executable statement in the same program containing the statement. The program control is transferred to this statement in case an error occurs while executing the statement.


The options can be specified in any order.

The and options are allowable alternates for , with a warning, if the flag is set.

Execution of proceeds as follows:

  1. The specified unit is disconnected.

  2. If is , the file connected to the specified unit is deleted.

  3. If an argument is specified, ios is set to zero if no error was encountered; otherwise, it is set to a positive value.


All open files are closed with default sta at normal program termination. Regardless of the specified sta, scratch files, when closed, are always deleted.

Execution of a statement specifying a unit that does not exist, or a unit that has no file connected to it, has no effect.

Execution of a statement specifying a unit zero (standard error) is not allowed, but you can reopen it to some other file.

The unit or file disconnected by the execution of a statement can be connected again to the same, or a different, file or unit.

Note -

For tape I/O, use the routines.


Example 1: Close and keep:

       CLOSE ( 2, STATUS='KEEP')

Example 2: Close and delete:


Example 3: Close and keep a scratch file even though the status is :

       OPEN ( 2, STATUS='SCRATCH')        ...        CLOSE ( 2, STATUS='KEEP', IOSTAT=I )
  • © 2010, Oracle Corporation and/or its affiliates