FORTRAN Reference Manual

Introduction to File I/O in the HP NonStop
Environment
FORTRAN Reference Manual528615-001
5-21
Structured Files
If you READ the file directly with REC= specifying the nonnegative record number
(including 0) of a record that does not exist, then
°
If the specified record number is beyond the end of the file, you get an end-
offile indication.
°
Otherwise, you get the record with the smallest record number that is greater
than or equal to the specified record number. FORTRAN does not consider this
an error. Consequently, you should execute an INQUIRE statement with the
NEXTREC specifier after this type of READ.
The following example shows how to create the file RESERVED:
To connect the file to a unit for direct access, your program might contain the following:
OPEN (15, file='reserved', ACCESS='DIRECT',
& FORM='FORMATTED', STATUS='OLD')
To read a record from the file:
READ *, k
READ (15, FMT=20, REC=k) name, date, flight
To update a record:
READ *, k
WRITE (15, FMT=20, UPDATE=.TRUE., REC=k) name, date, flight
Key-Sequenced Files
Records in key-sequenced files are logically stored in order of ascending primary-key
values. A primary key is a record field that uniquely identifies the record. You can also
use alternate keys to access data in a key-sequenced file.
In a key-sequenced file:
The space occupied by the record depends on the length you specify when you
write it.
You can shorten, lengthen, or delete records.
1> FUP
File Utility Program - T6553D10 - (08JUN92) System \ASYS
Copyright Tandem Computers Incorporated 1981, 1983, 1985-1992
-SET TYPE R <-- Set file type
-SET REC 120 <-- Set record length
-SHOW <-- Show the current values
TYPE R
EXT (1 PAGES, 1 PAGES)
REC 120
BLOCK 4096
MAXEXTENTS 16
-CREATE reserved <-- Create file
CREATED - $JUICE.BUJES.RESERVED
-EXIT <-- Exit FUP
2>