HP 3000 Manuals

CLOSE Statement (Executable) [ HP FORTRAN 77/iX Reference ] MPE/iX 5.0 Documentation


HP FORTRAN 77/iX Reference

CLOSE Statement (Executable) 

The CLOSE statement terminates the connection of a file to a unit.

	       Click here to view figure.
            

----------------------------------------------------------------------------------------------
|                              |                              |                              |
|             Item             |     Description/Default      |         Restrictions         |
|                              |                              |                              |
----------------------------------------------------------------------------------------------
|                              |                              |                              |
| unit                         | Specifies the unit number of | Must be an integer           |
|                              | the file.                    | expression.                  |
|                              |                              |                              |
----------------------------------------------------------------------------------------------
|                              |                              |                              |
| dsp                          | See "Semantics".             | None.                        |
|                              |                              |                              |
----------------------------------------------------------------------------------------------
|                              |                              |                              |
| dsps                         | See "Semantics".             | None.                        |
|                              |                              |                              |
----------------------------------------------------------------------------------------------
|                              |                              |                              |
| label                        | Statement label of an        | Must be in the same program  |
|                              | executable statement.        | unit as the CLOSE statement. |
|                              |                              |                              |
----------------------------------------------------------------------------------------------
|                              |                              |                              |
| character_expression         | Character expression that    | The value must be either     |
|                              | determines the disposition   | 'KEEP' or 'DELETE'.          |
|                              | of the file.                 |                              |
|                              |                              |                              |
----------------------------------------------------------------------------------------------
|                              |                              |                              |
| variable_name                | Error code return.           | Must be an integer type.     |
| array_element_name           |                              |                              |
| scalar_record_field_name     |                              |                              |
|                              |                              |                              |
----------------------------------------------------------------------------------------------

Semantics 

If the ERR specifier is used and an error occurs during execution of a
CLOSE statement, control transfers to the statement specified by label 
rather than aborting the program.

If the IOSTAT specifier is present and an error occurs, the error code is
returned in the IOSTAT variable and the program is not aborted.  Refer to
Appendix A  for IOSTAT error codes.

If STATUS='KEEP' is specified, the file continues to exist after
execution of the CLOSE statement.  'KEEP' is the default for named files;
that is, specifying STATUS='KEEP' or not specifying the STATUS parameter
has the same effect.  However, STATUS='KEEP' is an error if a scratch
file is being closed.

The STATUS='KEEP' specifier is not allowed on scratch files because
scratch files are deleted upon execution of CLOSE or at normal program
termination.

In the STATUS specifier, only the first character is significant.

If STATUS='DELETE' is specified, the file does not exist after execution
of the CLOSE statement.

The DISP and DISPOSE specifiers, which are extensions to the ANSI 77
standard, are included for compatibility with programs originally written
in another version of FORTRAN. If used in a program, their syntax is
checked, but they are otherwise ignored by the compiler. 

A CLOSE statement must contain a unit number and at most one each of the
other options.

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                                      Notes 

---------------------------------------------------------------------------------------

CLOSE (10)                                  Disconnects the file connected to unit 10.
                                            The file continues to exist.

CLOSE (UNIT=6,STATUS='DELETE')              Disconnects the file connected to unit 6.
                                            The file no longer exists.

CHARACTER*6 cstat                           This produces the same results as the
cstat = 'DELETE'                            preceding statement.
CLOSE (UNIT=6,STATUS=cstat)

CLOSE (5,IOSTAT=io_error,ERR=100)           Disconnects and keeps the file connected to
                                            unit 5.  If an error occurs, control is
                                            transferred to statement 100 and the error
                                            code is stored in the variable io_error.
                                            If no error occurs, io_error is set to 0
                                            and control transfers to the next
                                            statement.

CLOSE (5,IOSTAT=io_error)                   Disconnects and keeps the file connected to
                                            unit 5.  If an error occurs, the error code
                                            is stored in the variable io_error.  If no
                                            error occurs, io_error is set to 0.  In
                                            both cases, control transfers to the next
                                            statement.

CLOSE (5,ERR=100)                           Disconnects and keeps the file connected to
                                            unit 5.  If an error occurs, control
                                            transfers to statement 100.  If no error
                                            occurs, control transfers to the next
                                            statement.



MPE/iX 5.0 Documentation