CLOSE statement
Standard: F77 F90 F95 F2003 F2008 F2018 Example program
<Syntax>
CLOSE ( close-spec-list )
close-spec-list ::= close-spec [ , close-spec ]...
The close specifiers (close-spec) are as follows.
CLOSE specifier | Meaning | Syntax | Acceptable Values |
UNIT | The external unit number to close | [ UNIT= ] expression | Scalar non-negative integer |
STATUS | Whether to keep or delete the file | STATUS= expression | 'KEEP' or 'DELETE' |
ERR | Branch on error | ERR= label | |
IOMSG | Return i/o error message | IOMSG= variable | Scalar default character |
IOSTAT | Return i/o status code | IOSTAT= variable | Scalar integer |
<Semantics>
Closes a unit connected to an external file. If STATUS= is omitted, the default is 'KEEP' for normal files and 'DELETE' for scratch files (files opened with STATUS='SCRATCH'); a scratch file cannot be kept.
Closing a unit that is not connected is permitted and has no effect.
The IOMSG= specifier was added in Fortran 2003; this sets a character string variable to an error message if an error occurs. The ERR= or IOSTAT= specifier is still needed to prevent termination on error.
<Related>
BACKSPACE statement, ENDFILE statement, ERR= specifier, IOMSG= specifier, IOSTAT= specifier, OPEN statement, PRINT statement, READ statement, REWIND statement, UNIT= specifier, WRITE statement