02.07.2013 Views

HP Fortran Programmer's Reference

HP Fortran Programmer's Reference

HP Fortran Programmer's Reference

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

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

OPEN<br />

Table 10-40 (Continued)<br />

'REPLACE' If the file does not exist, create<br />

it with a status of OLD; if it does<br />

exist, delete it and open it with<br />

a status of NEW. If<br />

STATUS='REPLACE' is specified,<br />

FILE= must also be specified.<br />

'SCRATCH' Create a scratch file. FILE=<br />

specifier must not be specified.<br />

For information about scratch<br />

files, see “Scratch files” on<br />

page 172.<br />

Description<br />

The OPEN statement connects a unit to a file so that data can be read from or written to that<br />

file. Once a file is connected to a unit, the unit can be referenced by any program unit in the<br />

program.<br />

I/O specifiers do not have to appear in any specific order in the OPEN statement. However, if<br />

the optional keyword UNIT= is omitted, unit must be the first item in the list.<br />

Only one unit can be connected to a file at a time. That is, the same file cannot be connected to<br />

two different units. Attempting to open a file that is connected to a different unit will produce<br />

undefined results.<br />

However, multiple OPENs can be performed on the same unit. In other words, if a unit is<br />

connected to a file that exists, it is permissible to execute another OPEN statement for the<br />

same unit. If FILE= specifies a different file, the previously opened file is automatically closed<br />

before the second file is connected to the unit. If FILE= specifies the same file, the file remains<br />

connected in the same position; the values of the BLANK=, DELIM=, PAD=, ERR=, andIOSTAT=<br />

specifiers can be changed, but attempts to change the values of any of the other specifiers will<br />

be ignored.<br />

Examples<br />

The following examples illustrate different uses of the OPEN statement.<br />

Opening a file for sequential access<br />

The following OPEN statement connects the existing file inv to unit 10 and opens it (by<br />

default) for sequential access. Only READ statements are permitted to perform data transfers.<br />

If an error occurs, control passes to the executable statement labeled 100 and the error code is<br />

placed in the variable ios:<br />

380<br />

Chapter 10

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

Saved successfully!

Ooh no, something went wrong!