next up previous contents
Next: READ Statement Up: Input / Output Previous: Input / Output

 

OPEN Statement

The OPEN statement is used to connect a named file to a logical unit. It is often possible to pre-connect a file before the program has begun, if this is the case then there is no need for an OPEN statement, however, there are many default I/O settings many of which are processor dependent. Its good practice not to rely on defaults but to specify exactly what is required in an explicit OPEN statement. This will make the program more portable.

The syntax isgif,

 
OPEN([UNIT=]< integer >, FILE=< filename >, ERR=< label >, &

STATUS=< status >, ACCESS=< method >, ACTION=< mode >, RECL=< int-expr >)

where,

There now follows an example of use,

    OPEN(17,FILE='output.dat',ERR=10, STATUS='REPLACE', &
            ACCESS='SEQUENTIAL',ACTION='WRITE')

A file output.dat is opened for writing, it is connected to logical unit number 17. The file is accessed on a line by line basis and already exists but is to be replaced. The label 10 must pertain to a valid executable statement.

    OPEN(14,FILE='input.dat',ERR=10, STATUS='OLD', RECL=iexp, &
            ACCESS='DIRECT',ACTION='READ')

Here a file is opened for input only on unit 14. The file is directly accessed and (clearly) already exists.

Return to corresponding overview page gif


next up previous contents
Next: READ Statement Up: Input / Output Previous: Input / Output

©University of Liverpool, 1997
Wed May 28 20:20:27 BST 1997
Not for commercial use.