Previous | Contents | Index |
This chapter contains information on the following file connection, inquiry, and positioning statements:
The BACKSPACE statement positions a sequential file at the beginning of the preceding record, making it available for subsequent I/O processing. It takes one of the following forms:
|
io-unit
Is an external unit specifier.label
Is the label of the branch target statement that receives control if an error occurs.i-var
Is a scalar integer variable that is defined as a positive integer if an error occurs and zero if no error occurs.
The I/O unit number must specify an open file on disk or magnetic tape.
A BACKSPACE statement must not be specified for a file that is open for direct, append, or keyed access, because record n is not available to the RMS I/O system.
If a file is already positioned at the beginning of a file, a BACKSPACE statement has no effect.
The following statement repositions the file connected to I/O unit 4 back to the preceding record:
BACKSPACE 4 |
Consider the following statement:
BACKSPACE (UNIT=9, IOSTAT=IOS, ERR=10) |
This statement positions the file connected to unit 9 back to the preceding record. If an error occurs, control is transferred to the statement labeled 10, and a positive integer is stored in variable IOS.
The CLOSE statement disconnects a file from a unit. It takes the following form:
|
io-unit
Is an external unit specifier.p
Is a scalar default character expression indicating the status of the file after it is closed. It has one of the following values:
' KEEP ' or ' SAVE ' Retains the file after the unit closes. ' DELETE ' Deletes the file after the unit closes. 1 ' PRINT ' 2 Submits the file to the line printer spooler, then retains it. ' PRINT/DELETE ' 2 Submits the file to the line printer spooler, then deletes it. ' SUBMIT ' Submits the file to the batch job queue, then retains it. ' SUBMIT/DELETE ' Submits the file to the batch job queue, then deletes it.
The default is ' DELETE ' for scratch files. For all other files, the default is ' KEEP ' .
The CLOSE statement specifiers can appear in any order. An I/O unit must be specified, but the UNIT specifier is optional if the unit specifier is the first item in the I/O control list.
The status specified in the CLOSE statement supersedes the status specified in the OPEN statement, except that a file opened as a scratch file cannot be saved, printed, or submitted, and a file opened for read-only access cannot be deleted.
If a CLOSE statement is specified for a unit that is not open, it has no effect.
Consider the following statement:
CLOSE (UNIT=J, STATUS='DELETE', ERR=99) |
This statement closes the file connected to unit J and deletes it. If an error occurs, control is transferred to the statement labeled 99.
Consider the following statement:
CLOSE (UNIT=1, STATUS='PRINT') |
This statement closes the file on unit 1 and submits it for printing.
The DELETE statement deletes a record from a relative or indexed organization file. It takes one of the following forms:
Keyed Access
|
Direct Access
|
io-unit
Is an external unit specifier.r
Is a scalar numeric expression indicating the record number to be deleted.label
Is the label of the branch target statement that receives control if an error occurs.i-var
Is a scalar integer variable that is defined as a positive integer if an error occurs and zero if no error occurs.
In files with keyed access, the DELETE statement deletes the current record. The current record is the last record that is accessed by a READ statement on the specified external unit.
In files with direct access, the DELETE statement deletes the direct access record specified by r. If REC=r is omitted, the current record is deleted. When the direct access record is deleted, any associated variable is set to the next record number.
The DELETE statement logically removes the appropriate record from the specified file by locating the record and marking it as a deleted record. It then frees the position formerly occupied by the deleted record so that a new record can be written into that position.
The following statement deletes the fifth record in the file connected to I/O unit 10:
DELETE (10, REC=5) |
In the next example, the current record is deleted from the file connected to I/O unit 11:
DELETE (11) |
For sequential files, the ENDFILE statement writes an end-of-file record to the file and positions the file after this record (the terminal point). For direct access files, the ENDFILE statement truncates the file after the current record.
An ENDFILE statement takes one of the following forms:
|
io-unit
Is an external unit specifier.label
Is the label of the branch target statement that receives control if an error occurs.i-var
Is a scalar integer variable that is defined as a positive integer if an error occurs and zero if no error occurs.
If the unit specified in the ENDFILE statement is not open, the default file is opened for unformatted output.
An end-of-file record can be written only to files with sequential
organization that are accessed as formatted-sequential or
unformatted-segmented sequential files.
An ENDFILE statement performed on a direct access file always truncates
the file.
An ENDFILE statement must not be issued for a file that is open for keyed access.
An end-of-file record written to a file on magnetic tape is not the same as a tape mark.
End-of-file records should not be written in files that are read by programs written in a language other than Fortran, because other languages do not support the embedded end-of-file concept.
The following statement writes an end-of-file record to I/O unit 2:
ENDFILE 2 |
Suppose the following statement is specified:
ENDFILE (UNIT=9, IOSTAT=IOS, ERR=10) |
An end-of-file record is written to the file connected to unit 9. If an error occurs, control is transferred to the statement labeled 10, and a positive integer is stored in variable IOS.
The INQUIRE statement returns information on the status of specified properties of a file or logical unit. It takes one of the following forms:
Inquiring by File
|
Inquiring by Unit
|
Inquiring by Output List
|
name
Is a scalar default character expression specifying the name of the file for inquiry.label
Is the label of the branch target statement that receives control if an error occurs.i-var
Is a scalar integer variable that is defined as a positive integer if an error occurs and zero if no error occurs.def
Is a scalar default character expression specifying a default file name specification string. (For more information on the DEFAULTFILE specifier, see the Section 12.6.10.)slist
Is one or more inquiry specifiers. Each specifier can appear only once. (The inquiry specifiers are described individually in the following sections.)io-unit
Is an external unit specifier.The unit does not have to exist, nor does it need to be connected to a file. If the unit is connected to a file, the inquiry encompasses both the connection and the file.
len
Is a scalar integer variable that is assigned a value corresponding to the length of an unformatted, direct-access record resulting from the use of the out-item-list in a WRITE statement.The value is suitable to use as a RECL specifier value in an OPEN statement that connects a file for unformatted, direct access.
The unit of the value is 4-byte longwords, by default. However, if you specify the compiler option /ASSUME=BYTERECL, the unit is bytes.
out-item-list
Is a list of one or more output items (see Section 10.2.2).
The control specifiers ([UNIT=]io-unit, ERR=label, and IOSTAT=i-var) and inquiry specifiers can appear anywhere within the parentheses following INQUIRE. However, if the UNIT specifier is omitted, the io-unit must appear first in the list.
An INQUIRE statement can be executed before, during, or after a file is connected to a unit. The specifier values returned are those that are current when the INQUIRE statement executes.
To get file characteristics, specify the INQUIRE statement after opening the file.
The following are examples of INQUIRE statements:
INQUIRE (FILE='FILE_B', EXIST=EXT) INQUIRE (4, FORM=FM, IOSTAT=IOS, ERR=20) INQUIRE (IOLENGTH=LEN) A, B |
In the last statement, you can use the length returned in LEN as the value for the RECL specifier in an OPEN statement that connects a file for unformatted direct access. If you have already specified a value for RECL, you can check LEN to verify that A and B are less than or equal to the record length you specified.
The ACCESS specifier asks how a file is connected. It takes the following form:
|
acc
Is a scalar default character variable that is assigned one of the following values:
' SEQUENTIAL ' If the file is connected for sequential access ' DIRECT ' If the file is connected for direct access ' KEYED ' If the file is connected for keyed access ' UNDEFINED ' If the file is not connected
The ACTION specifier asks which I/O operations are allowed for a file. It takes the following form:
|
act
Is a scalar default character variable that is assigned one of the following values:
' READ ' If the file is connected for input only ' WRITE ' If the file is connected for output only ' READWRITE ' If the file is connected for both input and output ' UNDEFINED ' If the file is not connected
The BLANK specifier asks what type of blank control is in effect for a file. It takes the following form:
|
blnk
Is a scalar default character variable that is assigned one of the following values:
' NULL ' If null blank control is in effect for the file ' ZERO ' If zero blank control is in effect for the file ' UNDEFINED ' If the file is not connected, or it is not connected for formatted data transfer
The BLOCKSIZE specifier asks about the I/O buffer size. It takes the following form:
|
bks
Is a scalar integer variable.
The bks is assigned the current size of the I/O buffer. If the unit or file is not connected, the value assigned is zero.
Previous | Next | Contents | Index |