FORTRAN 77 Language Reference

Direct Access

A direct-access file contains a number of records that are written to or read from by referring to the record number. Direct access is also called random access.

In direct access:

Unformatted I/O

Example: Direct access, unformatted:


	OPEN( 2, FILE='data.db', ACCESS='DIRECT', RECL=20,
& 			FORM='UNFORMATTED', ERR=90 ) 
	READ( 2, REC=13, ERR=30 ) X, Y 
	READ( 2 ' 13, ERR=30 ) X, Y		   !  Alternate form 
@

This code opens a file for direct-access, unformatted I/O, with a record length of 20 characters, then reads the thirteenth record as is.

Formatted I/O

Example: Direct access, formatted:


	OPEN( 2, FILE='inven.db', ACCESS='DIRECT', RECL=20, 
& 			FORM='FORMATTED', ERR=90 ) 
	READ( 2, FMT='(I10,F10.3)', REC=13, ERR=30 ) A, B 

This code opens a file for direct-access, formatted I/O, with a record length of 20 characters, then reads the thirteenth record and converts it according to the (I10,F10.3) format.