The OPEN statement connects an existing file to a logical unit or creates a new file and connects it to a logical unit. It can also specify file attributes that control file creation and subsequent processing. The OPEN statement takes the following form:
OPEN (par[, par] . . . )
keywd keywd = val
DEFAULTFILE | Default file pathname |
DISPOSE | File existence status after CLOSE |
FILE or NAME | File pathname (file name) |
STATUS or TYPE | File existence status at OPEN |
UNIT | Logical unit number to be used |
ACCESS | Fortran access method to be used |
ORGANIZATION | Logical file structure |
READONLY | Write protection |
BLANK | Blank interpretation for numeric input |
BLOCKSIZE | Physical block size |
CARRIAGECONTROL | Terminal control type |
CONVERT | Numeric format for unformatted data |
FORM | Type of Fortran record formatting |
RECL or RECORDSIZE | Logical record length |
RECORDTYPE | Logical record format |
ASSOCIATEVARIABLE | The next record number value |
MAXREC | Maximum direct access record number |
BUFFERCOUNT | Number of I/O buffers to be used |
ERR | Statement to which control is transferred if an error occurs during execution of the OPEN statement |
IOSTAT | Status value that indicates whether an error condition exists |
USEROPEN | User program option to provide additional OPEN capability |
Keyword | Values | Function | Default |
---|---|---|---|
ACCESS | 'SEQUENTIAL'
'DIRECT' 'APPEND' |
Access mode | 'SEQUENTIAL' |
ASSOCIATEVARIABLE | asv | Next direct access record | |
BLANK | 'NULL'
'ZERO' | Interpretation of blanks | 'NULL' |
BLOCKSIZE | e | Physical block size | Filesystem default |
BUFFERCOUNT | e | Number of I/O buffers | One |
CARRIAGECONTROL |
'FORTRAN'
'LIST' 'NONE' | Print control |
'LIST' [1]
(formatted)
'NONE' (unformatted) |
CONVERT | 'LITTLE_ENDIAN'
'BIG_ENDIAN' 'CRAY' 'FDX' 'FGX' 'IBM' 'VAXG' 'VAXD' 'NATIVE' |
Numeric format specification | 'NATIVE' |
DEFAULTFILE | c1 | Default file pathname | Current working directory |
DISPOSE
DISP | 'KEEP' or 'SAVE'
'DELETE' 'PRINT' 'PRINT/DELETE' 'SUBMIT' 'SUBMIT/DELETE' |
File disposition at close | 'KEEP' |
ERR | s | Error transfer label | |
FILE
NAME | c | File pathname (file name) | fort.n[2] |
FORM | 'FORMATTED'
'UNFORMATTED' | Format type | Depends on ACCESS keyword |
IOSTAT | v | I/O status | |
MAXREC | e | Direct access record limit | |
ORGANIZATION | 'SEQUENTIAL'
'RELATIVE' |
File structure | 'SEQUENTIAL' |
READONLY | - | Write protection | |
RECL
RECORDSIZE | e | Record length | Depends on record type and file organization |
RECORDTYPE | 'FIXED'
'VARIABLE' 'SEGMENTED' 'STREAM' 'STREAM_CR' 'STREAM_LF' |
Record structure | Depends on ACCESS and FORM keywords |
STATUS
TYPE | 'OLD'
'NEW' 'SCRATCH' 'UNKNOWN' | File status at open | 'UNKNOWN' [3] |
UNIT | e | Logical unit number | |
USEROPEN | p | User program option | |
[1] If you specify compiler option
VMS, and the unit is connected to a terminal, the default is
'FORTRAN'.
| |||
Key to Values
asv: An integer variable c : A character scalar reference, numeric scalar memory reference, or numeric array name reference c1 : A character expression e : A numeric expression p : An external function s : A statement label v : An integer scalar memory reference |
If an OPEN statement is executed for a unit that is already open, and the file pathname is different from that of the current open file, the previously opened file is closed and the new file is opened. If the file pathname is the same for both files, the new value of the BLANK= specifier is in effect, but the position of the file is unaffected.
Specifying OPEN Statement Keywords
Keyword specifications can appear in any order. In most cases, they are optional. Default values apply in their absence. If the logical unit specifier is the first parameter in the list, the UNIT keyword is optional.
You can specify character values at run time by substituting a general character expression for a keyword value in the OPEN statement. The character value can contain trailing spaces but not leading or embedded spaces; for example:
CHARACTER*6 FINAL /' '/ . . . IF (exp) FINAL = 'DELETE' OPEN (UNIT=1, STATUS='NEW', DISP=FINAL)
The following statement creates a new sequential formatted file on unit 1 with the default file name fort.1:
OPEN (UNIT=1, STATUS='NEW', ERR=100)
The following statement creates a file on raw magnetic tape:
OPEN (UNIT=I, FILE='/dev/rmt8', 1 STATUS='NEW', ERR=14, RECL=1024)
The following statement opens the file (created in the previous example) for input:
OPEN (UNIT=I, FILE='/dev/rmt8', READONLY, 1 STATUS='OLD', RECL=1024)
The following sections provide specific information about OPEN statement keywords. As used in these sections, a numeric expression can be any integer or real expression. The value of the expression is converted to integer data type before it is used in the OPEN statement.