F90 allows a number of different files (streams) to be connected to the program for both reading and writing. Before being used by a program, a file must be connected to a logical unit (the F90 program operates with logical units, designated by positive numbers, usually between 1 and 100).
Connecting a file to a logical unit is done using an OPEN statement.
|OPEN (||UNIT= integer,||logical unit number|
|FILE= filename',||name of the file|
|STATUS='status',||'status' = 'OLD' looks for existing file|
|'NEW' creates the file, error if it already exists|
|'UNKNOWN' (is the default when status not specified)|
|(NEW if file exists)/(OLD if it doesn't)|
|'REPLACE' to override existing file|
|'SCRATCH' unnamed file, deleted at closing|
|FORM='mode',||'mode' = 'FORMATTED' or 'UNFORMATTED'|
|ACTION='action',||'READ' (only), 'WRITE' (only) or|
|'READWRITE' (default if ACTION missing)|
|POSITION='position'||when opening, position the file pointer at|
|the beginning 'REWIND', the end 'APPEND', where it is ASSIS (default)|
|ERR=label,||control is transferred to label if|
|error when opening the file|
|ACCESS='access'||'SEQUENTIAL', (line by line), or|
|'DIRECT' (access individual tagged records)|
|RECL=integer||record length for direct access.|
Note that not all the above arguments need to be explicitly given.
Some units are preconnected, i.e. they are available without explicitly opening them. For example, the default input is usually unit 5 (in some cases unit 1), and the default output is usually unit number 6 (sometimes 2).
To unattach an opened file from the corresponding unit number when we are done we use
close(unit=10,iostat=ierr)(this also inserts an end-of-file character when writting)