02.07.2013 Views

HP Fortran Programmer's Reference

HP Fortran Programmer's Reference

HP Fortran Programmer's Reference

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>HP</strong> <strong>Fortran</strong> statements<br />

CLOSE<br />

Description<br />

The CLOSE statement closes the file whose unit number was obtained from an OPEN statement.<br />

A CLOSE statement must contain a unit number and at most one each of the other I/O<br />

specifiers.<br />

A CLOSE statement need not be in the same program unit as the OPEN statement that<br />

connected the file to the specified unit. If a CLOSE statement specifies a unit that does not<br />

exist or has no file connected to it, no action occurs.<br />

Examples<br />

The following examples illustrate different uses of the CLOSE statement. In the first example,<br />

the CLOSE statement closes the file connected to unit 10; after it is closed, the file will continue<br />

to exist, unless it was opened with the STATUS='SCRATCH' specifier:<br />

CLOSE (10)<br />

In the next example, after the file connected to unit 6 is closed, it will cease to exist:<br />

CLOSE(UNIT=6,STATUS='DELETE')<br />

The following code produces the same results as the previous example:<br />

CHARACTER(LEN=6) cstat<br />

cstat='delete'<br />

CLOSE(UNIT=6,STATUS=cstat)<br />

The following example closes the file connected to unit 5. If an error occurs, control is<br />

transferred to the executable statement labeled 100, and the error code is stored in the<br />

variable ios:<br />

CLOSE(5,IOSTAT=ios,ERR=100)<br />

Related statements<br />

OPEN<br />

Related concepts<br />

For information about I/O concepts, see Chapter 8, “I/O and file handling,” on page 169, which<br />

also lists example programs that use I/O.<br />

266<br />

Chapter 10

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!