The OPEN statement can be used to connect an existing external file to a unit, create an external file that is preconnected, create an external file and connect it to a unit, or change certain specifiers of a connection between an external file and a unit.
SEQUENTIAL is the default, for which RECL= is optional
char_expr is a scalar character expression whose value is either YES or NO. YES specifies that asynchronous data transfer statements are permitted for this connection. NO specifies that asynchronous data transfer statements are not permitted for this connection. The value specified will be in the set of transfer methods permitted for the file. If this specifier is omitted, the default value is NO.
Preconnected units are connected with an ASYNCH= value of NO.
The ASYNCH= value of an implicitly connected unit is determined by the first data transfer statement performed on the unit. If the first statement performs an asynchronous data transfer and the file being implicitly connected permits asynchronous data transfers, the ASYNCH= value is YES. Otherwise, the ASYNCH= value is NO.
is a file specifier that specifies the name of the file to be connected to the specified unit.
char_expr is a scalar character expression whose value, when any trailing blanks are removed, is a valid Linux operating system file name. If the file specifier is omitted and is required, the unit becomes implicitly connected (by default) to fort.u, where u is the unit specified with any leading zeros removed. Use the UNIT_VARS run-time option to allow alternative files names to be used for files that are implicitly connected.
If the -qxlf77 compiler option specifies the noblankpad suboption and the file is being connected for formatted direct input/output, the default value is NO when the PAD= specifier is omitted.
In such cases, the default value for the POSITION= specifier is APPEND at the time the WRITE statement is executed.
specifies the length of each record in a file being connected for direct access or the maximum length of a record in a file being connected for sequential access. integer_expr is an integer expression whose value must be positive. This specifier must be present when a file is being connected for direct access. For formatted input/output, the length is the number of characters for all records that contain character data. For unformatted input/output, the length is the number of bytes required for the internal form of the data. The length of an unformatted sequential record does not count the four-byte fields surrounding the data.
If RECL= is omitted when a file is being connected for sequential access in 32-bit, the length is 2**31-1, minus the record terminator. For a formatted sequential file in 32-bit, the default record length is 2**31-2. For an unformatted file that can be accessed in 32-bit, the default record length is 2**31-9.
For a file that cannot be accessed randomly in 32-bit, the default length is 2**15 (32,768).
If RECL= is omitted when a file is being connected for sequential access in 64-bit, the length is 2**63-1, minus the record terminator. For a formatted sequential file in 64-bit, the default record length is 2**63-2 For an unformatted file in 64-bit, the default record length is 2**63-17 when the UWIDTH run-time option is set to 64.
UNKNOWN is the default.
If a unit is connected to a file that exists, an OPEN statement for that unit can be performed. If the FILE= specifier is not included in the OPEN statement, the file to be connected to the unit is the same as the file to which the unit is connected.
If the file to be connected to the unit is not the same as the file to which the unit is connected, the effect is as if a CLOSE statement without a STATUS= specifier had been executed for the unit immediately prior to the execution of the OPEN statement.
If the file to be connected to the unit is the same as the file to which the unit is connected, only the BLANK=, DELIM=, PAD=, ERR=, and IOSTAT= specifiers can have a value different from the one currently in effect. Execution of the OPEN statement causes any new value for the BLANK=, DELIM= or PAD= specifiers to be in effect, but does not cause any change in any of the unspecified specifiers or the position of the file. Any ERR= and IOSTAT= specifiers from OPEN statements previously executed have no effect on the current OPEN statement. If you specify the STATUS= specifier it must have the value OLD. To specify the same file as the one currently connected to the unit, you can specify the same file name, omit the FILE= specifier, or specify a file symbolically linked to the same file.
If a file is connected to a unit, an OPEN statement on that file and a different unit cannot be performed.
If the STATUS= specifier has the value OLD, NEW or REPLACE, the FILE= specifier is optional.
Unit 0 cannot be specified to connect to a file other than the preconnected file, the standard error device, although you can change the values for the BLANK=, DELIM= and PAD= specifiers.
If the ERR= and IOSTAT= specifiers are set and an error is encountered, transfer is made to the statement specified by the ERR= specifier and a positive integer value is assigned to ios.
If IOSTAT= and ERR= are not specified,
! Open a new file with name fname CHARACTER*20 FNAME FNAME = 'INPUT.DAT' OPEN(UNIT=8,FILE=FNAME,STATUS='NEW',FORM='FORMATTED') OPEN (4,FILE="myfile") OPEN (4,FILE="myfile", PAD="NO") ! Changing PAD= value to NO ! Connects unit 2 to a tape device for unformatted, sequential ! write-only access: OPEN (2, FILE="/dev/rmt0",ACTION="WRITE",POSITION="REWIND", & & FORM="UNFORMATTED",ACCESS="SEQUENTIAL",RECL=32767)