The INQUIRE statement returns information about a unit or file.
INQUIRE([UNIT =] u, slist)
You can determine such things about a file as whether it exists, is opened, or is connected for sequential I/O. That is, files have such attributes as name, existence (or nonexistence), and the ability to be connected in certain ways (FORMATTED, UNFORMATTED, SEQUENTIAL, or DIRECT).
Inquire either by unit or by file, but not by both in the same statement.
In this system environment, the only way to discover what permissions you have for a file is to use the ACCESS(3F) function. The INQUIRE statement does not determine permissions.
The following table summarizes the INQUIRE specifiers:
Table 4-1 INQUIRE Specifiers Summary
Form: SPECIFIER = Variable |
||
---|---|---|
SPECIFIER |
Value of Variable |
Data Type of Variable |
ACCESS |
'DIRECT' 'SEQUENTIAL' |
CHARACTER |
BLANK |
'NULL' 'ZERO' |
CHARACTER |
DIRECT * |
'YES' 'NO' 'UNKNOWN' |
CHARACTER |
ERR |
Statement number |
INTEGER |
EXIST |
.TRUE. .FALSE. |
LOGICAL |
FORM |
'FORMATTED' 'UNFORMATTED' |
CHARACTER |
FORMATTED * |
'YES' 'NO' 'UNKNOWN' |
CHARACTER |
IOSTAT |
Error number |
INTEGER |
NAME |
Name of the file |
CHARACTER |
NAMED |
.TRUE. .FALSE. |
LOGICAL |
NEXTREC |
Next record number |
INTEGER |
NUMBER * |
Unit number |
INTEGER |
OPENED |
.TRUE. .FALSE. |
LOGICAL |
RECL |
Record length |
INTEGER |
SEQUENTIAL * |
'YES' 'NO' 'UNKNOWN' |
CHARACTER |
UNFORMATTED * |
'YES' 'NO' 'UNKNOWN' |
CHARACTER |
* indicates non-standard for inquire-by-unit, but accepted by f77. indicates non-standard for inquire-by-file, but accepted by f77.
Also:
If a file is scratch, then NAMED and NUMBER are not returned.
If there is no file with the specified name, then these variables are not returned: DIRECT, FORMATTED, NAME, NAMED, SEQUENTIAL, and UNFORMATTED.
If OPENED=.FALSE., then these variables are not returned: ACCESS, BLANK, FORM, NEXTREC, and RECL.
If no file is connected to the specified unit, then these variables are not returned: ACCESS, BLANK, DIRECT, FORM, FORMATTED, NAME, NAMED, NEXTREC, NUMBER, RECL, SEQUENTIAL, and UNFORMATTED.
If ACCESS='SEQUENTIAL', then these variables are not returned: RECL and NEXTREC.
If FORM='UNFORMATTED', then BLANK is not returned.
The following provides a detailed list of the INQUIRE specifier keywords:
acc is a character variable that is assigned the value 'SEQUENTIAL' if the connection is for sequential I/O and 'DIRECT' if the connection is for direct I/O. The value is undefined if there is no connection.
blnk is a character variable that is assigned the value 'NULL' if null blank control is in effect for the file connected for formatted I/O, and 'ZERO' if blanks are being converted to zeros and the file is connected for formatted I/O.
dir is a character variable that is assigned the value 'YES' if the file could be connected for direct I/O, 'NO' if the file could not be connected for direct I/O, and 'UNKNOWN' if the system can't tell.
s is a statement label of a statement to branch to if an error occurs during the execution of the INQUIRE statement.
ex is a logical variable that is set to .TRUE. if the file or unit exists, and .FALSE. otherwise. If the file is a link, INQUIRE always returns .TRUE., even if the linked file does not exist.
n is a character expression or * with the name of the file. Trailing blanks in the file name are ignored. If the file name is all blanks, that means the current directory. The file need not be connected to a unit in the current program.
fm is a character variable which is assigned the value 'FORMATTED' if the file is connected for formatted I/O and 'UNFORMATTED' if the file is connected for unformatted I/O.
fmt is a character variable that is assigned the value 'YES' if the file could be connected for formatted I/O, 'NO' if the file could not be connected for formatted I/O, and 'UNKNOWN' if the system cannot tell.
ios is as in the OPEN statement.
fn is a character variable that is assigned the name of the file connected to the unit. If you do an inquire-by-unit, the name parameter is undefined, unless both the values of the OPENED and NAMED variables are both true. If you do an inquire by file, the name parameter is returned, even though the FORTRAN 77 Standard leaves it undefined.
nmd is a logical variable that is assigned .TRUE. if the file has a name, .FALSE. otherwise.
nr is an integer variable that is assigned one plus the number of the last record read from a file connected for direct access. If the file is not connect, -1 is returned in nr.
num is an integer variable that is set to the number of the unit connected to the file, if any. If no file is connected, num is set to -1.
od is a logical variable that is set to .TRUE. if the file is connected to a unit or the unit is connected to a file, and .FALSE. otherwise.
rcl is an integer variable that is assigned the record length of the records in the file if the file is connected for direct access. f77 does not adjust the rcl returned by INQUIRE. The OPEN statement does such an adjustment if the -xl[d] option is set. See "Details of Features That Require -xl[d]" for an explanation of -xl[d]. If no file is connected, rcl is set to -1.
seq is a character variable that is assigned the value 'YES' if the file could be connected for sequential I/O, 'NO' if the file could not be connected for sequential I/O, and 'UNKNOWN' if the system can't tell.
unf is a character variable that is assigned the value 'YES' if the file could be connected for unformatted I/O, 'NO' if the file could not be connected for unformatted I/O, and 'UNKNOWN' if the system cannot tell.
u is an integer expression or * with the value of the unit. Exactly one of FILE or UNIT must be used.
LOGICAL OK INQUIRE( UNIT=3, OPENED=OK ) IF ( OK ) CALL GETSTD ( 3, STDS )
LOGICAL THERE INQUIRE( FILE='.profile', EXIST=THERE ) IF ( THERE ) CALL GETPROFILE( FC, PROFILE )
Example 3: More than one answer, omitting the UNIT=:
CHARACTER FN*32 LOGICAL HASNAME, OK INQUIRE ( 3, OPENED=OK, NAMED=HASNAME, NAME=FN ) IF ( OK .AND. HASNAME ) PRINT *, 'Filename="', FN, '"'