Intel® Fortran Compiler Classic and Intel® Fortran Compiler Developer Guide and Reference

ID 767251
Date 9/08/2022
Public

A newer version of this document is available. Customers should click here to go to the newest version.

Document Table of Contents

Close Files: CLOSE Statement

Usually, any external file opened should be closed by the same program before it completes. The CLOSE statement flushes any output buffers and disconnects the unit and its external file. You must specify the unit number (UNIT specifier) to be closed.

You can also specify:

  • Whether the file should be deleted or kept (STATUS specifier)

  • Error handling information (ERR and IOSTAT specifiers)

To delete a file when closing it:

  • In the OPEN statement, specify the ACTION keyword (such as ACTION='READ'). Avoid using the READONLY keyword, because a file opened using the READONLY keyword cannot be deleted when it is closed.

  • In the CLOSE statement, specify the keyword STATUS='DELETE'.

If you opened an external file and performed an inquire by unit, but do not like the default value for the ACCESS specifier, you can close the file and then reopen it. When you reopen it, explicitly specify the ACCESS desired.

Typically, it is not necessary to close preconnected units. Internal files are neither opened nor closed.