The following provides a detailed list of the OPEN specifier keywords:
u is an integer expression or an asterisk (*) that specifies the unit number. u is required. If u is first in the parameter list, then UNIT= can be omitted.
fin is a character expression or * naming the file to open. An OPEN statement need not specify a file name. If the file name is not specified, a default name is created.
Reopen
If you open a unit that is already open without specifying a file name (or with the previous file name), FORTRAN thinks you are reopening the file to change parameters. The file position is not changed. The only parameters you are allowed to change are BLANK (NULL or ZERO) and FORM (FORMATTED or PRINT). To change any other parameters, you must close, then reopen the file.
Switch Files
If you open a unit that is already open, but you specify a different file name, it is as if you closed with the old file name before the open.
Switch Units
If you open a file that is already open, but you specify a different unit, that is an error. This error is not detected by the ERR= option, however, and the program does not terminate abnormally.
Scratch
If a file is opened with STATUS='SCRATCH', a temporary file is created and opened. See STATUS=sta.
The ACCESS=acc clause is optional. acc is a character expression. Possible values are: APPEND, DIRECT, or SEQUENTIAL. The default is SEQUENTIAL.
If ACCESS='APPEND': SEQUENTIAL and FILEOPT='EOF' are assumed. This is for opening a file to append records to an existing sequential-access file. Only WRITE operations are allowed. This is an extension and can be applied only to disk files. @
If ACCESS='DIRECT': RECL must also be given, since all I/O transfers are done in multiples of fixed-size records.
Only directly accessible files are allowed; thus, tty, pipes, and magnetic tape are not allowed. If you build a file as sequential, then you cannot access it as direct.
If FORM is not specified, unformatted transfer is assumed.
If FORM='UNFORMATTED', the size of each transfer depends upon the data transferred.
If ACCESS='SEQUENTIAL', RECL is ignored. @ The FORTRAN 77 Standard prohibits RECL for sequential access.
No padding of records is done.
If you build a file as direct, then you cannot access it as sequential.
Files do not have to be randomly accessible, in the sense that tty, pipes, and tapes can be used. For tapes, we recommend the TOPEN() routines because they are more reliable.
If FORM is not , formatted transfer is assumed.
If FORM='FORMATTED', each record is terminated with a newline (\n) character; that is, each record actually has one extra character.
If FORM='PRINT', the file acts like a FORM='FORMATTED' file, except for interpretation of the column-1 characters on the output (blank = single space, 0 = double space, 1 = form feed, and + = no advance).
If FORM='UNFORMATTED', each record is preceded and terminated with an INTEGER*4 count, making each record 8 characters longer than normal. This convention is not shared with other languages, so it is useful only for communicating between FORTRAN programs.
The FORM=fm clause is optional. fm is a character expression. Possible values are 'FORMATTED', 'UNFORMATTED', or 'PRINT'. @ The default is 'FORMATTED'.
This option interacts with ACCESS.
'PRINT' makes it a print file.
The RECL=rl clause is required if ACCESS='DIRECT' and ignored otherwise.
rl is an integer expression for the length in characters of each record of a file. rl must be positive.
If the record length is unknown, you can use RECL=1; see "Direct Access I/O" for more information.
If -xl[d] is not set, rl is number of characters, and record length is rl.
If -xl[d] is set, rl is number of words, and record length is rl*4. @
There are more details in the ACCESS='SEQUENTIAL' section, above.
Each WRITE defines one record and each READ reads one record (unread characters are flushed).
The default buffer size for tape is 64K characters. For tapes, we recommend the TOPEN() routines because they are more reliable.
The ERR=s clause is optional. s is a statement label of a statement to branch to if an error occurs during execution of the OPEN statement.
The IOSTAT=ios clause is optional. ios is an integer variable that receives the error status from an OPEN. After the execution of the OPEN, if no error condition exists, then ios is zero; otherwise, it is some positive number.
If you want to avoid aborting the program when an error occurs on an OPEN, include ERR=s or IOSTAT=ios.
The BLANK=blnk clause is optional, and is for formatted input only. The blnk is a character expression that indicates how blanks are treated. Possible values are 'ZERO' and 'NULL'.
'ZERO'--Blanks are treated as zeroes.
'NULL'--Blanks are ignored during numeric conversion. This is the default.
The STATUS=sta clause is optional. sta is a character expression. Possible values are: 'OLD', 'NEW', 'UNKNOWN', or 'SCRATCH'.
'OLD'-- The file already exists (nonexistence is an error). For example: STATUS='OLD'.
'NEW' -- The file doesn't exist (existence is an error). If 'FILE=name' is not specified, then a file named 'fort.n' is opened, where n is the specified logical unit.
'UNKNOWN' -- Existence is unknown. This is the default.
'SCRATCH' -- For a file opened with STATUS='SCRATCH', a temporary file with a name of the form tmp.FAAAxnnnnn is opened. Any other STATUS specifier without an associated file name results in opening a file named 'fort.n', where n is the specified logical unit number. By default, a scratch file is deleted when closed or during normal termination. If the program aborts, then the file may not be deleted. To prevent deletion, CLOSE with STATUS='KEEP'.
The FORTRAN 77 Standard prohibits opening a named file as scratch: if OPEN has a FILE=name option, then it cannot have a STATUS='SCRATCH' option. This FORTRAN extends the standard by allowing opening named files as scratch. @ Such files are normally deleted when closed or at normal termination.
TMPDIR: FORTRAN programs normally put scratch files in the current working directory. If the TMPDIR environment variable is set to a writable directory, then the program puts scratch files there. @
The FILEOPT=fopt clause is optional. fopt is a character expression. Possible values are 'NOPAD', 'BUFFER=n', and 'EOF'.
'NOPAD'--Do not extend records with blanks if you read past the end-of-record (formatted input only). That is, a short record causes an abort with an error message, rather than just filling with trailing blanks and continuing.
'BUFFER=n'-- This suboption is for disks. For tapes, we recommend the TOPEN() routines because they are more reliable. It sets the size in bytes of the I/O buffer to use. For writes, larger buffers yield faster I/O. For good performance, make the buffer a multiple of the largest record size. This size can be larger than the actual physical memory, and probably the best performance is obtained by making the record size equal to the entire file size. Larger buffer sizes can cause extra paging.
'EOF'--Opens a file at end-of-file rather than at the beginning (useful for appending data to file), for example, FILEOPT='EOF'. Unlike ACCESS='APPEND', in this case, both READ and BACKSPACE are allowed.
The file is opened read-only.
This specifier denotes file permissions. Possible values are: READ, WRITE, and READWRITE.
If act is READ, it specifies that the file is opened read-only.
If act is WRITE, it specifies that the file is opened write-only. You cannot execute a BACKSPACE statement on a write-only file.
If act is READWRITE, it specifies that the file is opened with both read and write permissions.