10.6 OPEN Statement

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] . . . )
par
Is a keyword specification taking one of the following forms:
keywd
keywd = val
keywd
Is any of the following keywords (listed in categories based on function):
val
Is a value that is valid for the keyword. Table 10-1 lists these values.

Table 10-1 OPEN Statement Keyword Values on Tru64 UNIX Systems

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  Error transfer label   
FILE
NAME
 
File pathname (file name)   fort.n[2] 
FORM  'FORMATTED'
'UNFORMATTED'  
Format type  Depends on ACCESS keyword 
IOSTAT  I/O status   
MAXREC   e  Direct access record limit   
ORGANIZATION   'SEQUENTIAL'
'RELATIVE'
 
File structure   'SEQUENTIAL'  
READONLY   -  Write protection   
RECL
RECORDSIZE
 
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  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'.
[2] n is the unit number
[3] The default differs under certain conditions (see Section 10.6.21).

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.


Note
You can use the INQUIRE statement to get file attributes of existing files. For more information, see Section 10.5.

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)

Examples

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.


Previous Page Next Page Table of Contents