HP Fortran Programmer's Reference (September 2007)

HP Fortran statements
CLOSE
Chapter 10300
Description
The CLOSE statement closes the file whose unit number was obtained from an OPEN statement.
A CLOSE statement must contain a unit number and at most one each of the other I/O
specifiers.
A CLOSE statement need not be in the same program unit as the OPEN statement that
connected the file to the specified unit. If a CLOSE statement specifies a unit that does not exist
or has no file connected to it, no action occurs.
Examples
The following examples illustrate different uses of the CLOSE statement. In the first example,
the CLOSE statement closes the file connected to unit 10; after it is closed, the file will continue
to exist, unless it was opened with the STATUS='SCRATCH' specifier:
CLOSE (10)
In the next example, after the file connected to unit 6 is closed, it will cease to exist:
CLOSE(UNIT=6,STATUS='DELETE')
The following code produces the same results as the previous example:
CHARACTER(LEN=6) cstat
cstat='delete'
CLOSE(UNIT=6,STATUS=cstat)
The following example closes the file connected to unit 5. If an error occurs, control is
transferred to the executable statement labeled 100, and the error code is stored in the
variable ios:
CLOSE(5,IOSTAT=ios,ERR=100)
Related statements
OPEN
Related concepts
For information about I/O concepts, see Chapter 8, “I/O and file handling,” on page 201, which
also lists example programs that use I/O.