HP Fortran Programmer's Reference (September 2007)

I/O and file handling
File access methods
Chapter 8 209
File access methods
HP Fortran allows both sequential access and direct access. You specify the access method
with the OPEN statement when you connect the file to a unit number. The following example
opens the file new_data for direct access:
OPEN(40, ACCESS='DIRECT', RECL=128, FILE='new_data')
If you do not specify an access method, the file is opened for sequential access.
The following sections describe both sequential and direct methods.
Sequential access
Records in a file opened for sequential access can be accessed only in the order in which they
were written to the file. A sequential file may consist of either formatted or unformatted
records. If the records are formatted, you can use list-directed, namelist-directed, and
formatted I/O statements to operate on them. If the records are unformatted, you must use
unformatted I/O statements only. The last record of a sequential file is the end-of-file record.
The following sections describe the types of I/O that can be used with sequential files, namely:
Formatted I/O
List-directed I/O
Namelist-directed I/O
Unformatted I/O
Formatted I/O
Formatted I/O uses format specifications to define the appearance of data input to or output
from the program, producing ASCII records that are formatted for display. (Format
specifications are described in detail in “Format specification” on page 238.) Data is
transferred and converted, as necessary, between binary values and character format. You
cannot perform formatted I/O on a file that has been connected for unformatted I/O; see
“Unformatted I/O” on page 215.
Formatted I/O can be performed only by data transfer statements that include a format
specification. The format specification can be defined in the statement itself or in a FORMAT
statement referenced by the statement.
For an example of a program that accesses a formatted file, see “File access” on page 231.