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.

OPEN(10, FILE='inv', ERR=100, I0STAT=ios, &<br />

ACTION='READ', STATUS='OLD')<br />

Opening a file for direct access<br />

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

OPEN<br />

The following OPEN statement opens the file whose name is contained in the variable next1,<br />

connecting it to unit 4 as a formatted, direct-access file with a record length of 50 characters:<br />

OPEN(ACCESS=”DIRECT”, UNIT=4, RECL=50, &<br />

FORM=”FORMATTED”, FILE=next1)<br />

Opening a device for I/O transfers<br />

The next example connects the system device /dev/console to unit 6; all data transfers that<br />

specify unit 6 will go to this device:<br />

OPEN(6,FILE='/DEV/CONSOLE')<br />

Opening a scratch file<br />

The following two OPEN statements produce the same results: open a scratch file that is<br />

connected to unit 19 (if the FILE=name specifier had appeared in the first statement, the<br />

named file would have been opened instead):<br />

OPEN (UNIT=19)<br />

OPEN (UNIT=19, STATUS=”SCRATCH”)<br />

I/OspecifiersinanOPENstatement<br />

Because the I/O specifiers that can be used in an OPEN statement do not have to appear in any<br />

specific order, the following three OPEN statements are all equivalent:<br />

OPEN(UNIT=3, STATUS='NEW', FILE='OUT.DAT')<br />

OPEN(3, STATUS='NEW', FILE='OUT.DAT')<br />

OPEN(STATUS='NEW', FILE='OUT.DAT', UNIT=3)<br />

Note, however, that in the second OPEN statement the number 3 must appear first because of<br />

the omission of the optional keyword UNIT=. Thus,thefollowingOPEN statement is illegal:<br />

OPEN(STATUS='NEW', 3, FILE='OUT.DAT') ! illegal<br />

Related statements<br />

CLOSE, INQUIRE, READ, andWRITE<br />

Related concepts<br />

For information about I/O concepts and examples of programs that perform I/O, see<br />

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

Chapter 9, “I/O formatting,” on page 201.<br />

Chapter 10 381

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

Saved successfully!

Ooh no, something went wrong!