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.

File access methods<br />

I/O and file handling<br />

File access methods<br />

<strong>HP</strong> <strong>Fortran</strong> allows both sequential access and direct access. You specify the access method<br />

with the OPEN statement when you connect the file to a unit number. The following example<br />

opens the file new_data for direct access:<br />

OPEN(40, ACCESS='DIRECT', RECL=128, FILE='new_data')<br />

If you do not specify an access method, the file is opened for sequential access.<br />

The following sections describe both sequential and direct methods.<br />

Sequential access<br />

Records in a file opened for sequential access can be accessed only in the order in which they<br />

were written to the file. A sequential file may consist of either formatted or unformatted<br />

records. If the records are formatted, you can use list-directed, namelist-directed, and<br />

formatted I/O statements to operate on them. If the records are unformatted, you must use<br />

unformatted I/O statements only. The last record of a sequential file is the end-of-file record.<br />

The following sections describe the types of I/O that can be used with sequential files, namely:<br />

Formatted I/O<br />

List-directed I/O<br />

Namelist-directed I/O<br />

Unformatted I/O<br />

Formatted I/O<br />

Formatted I/O uses format specifications to define the appearance of data input to or output<br />

from the program, producing ASCII records that are formatted for display. (Format<br />

specifications are described in detail in “Format specification” on page 204.) Data is<br />

transferred and converted, as necessary, between binary values and character format. You<br />

cannot perform formatted I/O on a file that has been connected for unformatted I/O; see<br />

“Unformatted I/O” on page 183.<br />

Formatted I/O can be performed only by data transfer statements that include a format<br />

specification. The format specification can be defined in the statement itself or in a FORMAT<br />

statement referenced by the statement.<br />

For an example of a program that accesses a formatted file, see “File access” on page 197.<br />

Chapter 8 177

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

Saved successfully!

Ooh no, something went wrong!