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.

I/O and file handling<br />

File access methods<br />

As in list-directed output, character values are output without delimiters by default,<br />

making them unsuitable for namelist-directed input. However, you can use the DELIM=<br />

specifier in the OPEN statementtospecifythesingleordoublequotationmarkasthe<br />

delimiter to use for character constants.<br />

Only character and complex values may be split between two records.<br />

Unformatted I/O<br />

Unformatted I/O does not perform format conversion on data it transfers. Instead, data is<br />

kept in its internal, machine-representable format. You cannot perform unformatted I/O on<br />

files that have been connected for formatted I/O (see “Formatted I/O” on page 177).<br />

Unformatted I/O is more efficient than formatted, list-directed, or namelist-directed I/O<br />

because the transfer occurs without the conversion overhead. However, because unformatted<br />

I/O transfers data in internal format, it is not portable.<br />

Direct access<br />

When performing I/O on a direct-access file, records can be read or written in any order. The<br />

records in a direct-access file are all of the same length.<br />

Reading and writing records is accomplished by READ and WRITE statements containing the<br />

REC= specifier. Each record is identified by a record number that is a positive integer. For<br />

example, the first record is record number 1; the second, number 2; and so on. If REC= is not<br />

specified:<br />

The READ statement inputs from the current record, and the file pointer moves to the next<br />

record.<br />

The WRITE statement outputs to the record at the position of the file pointer, and the file<br />

pointer is advanced to the next record.<br />

As an extension, <strong>HP</strong> <strong>Fortran</strong> allows sequential I/O statements to access a file connected for<br />

direct access.<br />

Once established, a record number of a specific record cannot be changed or deleted, although<br />

the record may be rewritten. A direct-access file does not contain an end-of-file record as an<br />

integral part of the file with a specific record number. Therefore, when accessing a file with a<br />

direct-access read or write statement, the END= specifier is not valid and is not allowed.<br />

Direct-access files support both formatted and unformatted record types. Both formatted and<br />

unformatted I/O work exactly as they do for sequential files. However, you cannot perform<br />

list-directed, namelist-directed, or nonadvancing I/O on direct-access files.<br />

For an example program that uses direct access, see “File access” on page 197.<br />

Chapter 8 183

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

Saved successfully!

Ooh no, something went wrong!