Intel® Fortran Compiler 16.0 User and Reference Guide
The INQUIRE statement returns information about a file and has the following forms:
Inquiry by unit
Inquiry by file name
Inquiry by output item list
Inquiry by directory
An inquiry by unit is usually done for an opened (connected) file. An inquiry by unit causes the Intel® Fortran RTL to check whether the specified unit is connected or not. One of the following occurs, depending on whether the unit is connected or not:
If the unit is connected:
The EXIST and OPENED specifier variables indicate a true value.
The pathname and file name are returned in the NAME specifier variable (if the file is named).
Other information requested on the previously connected file is returned.
Default values are usually returned for the INQUIRE specifiers also associated with the OPEN statement.
The RECL value unit for connected formatted files is always 1-byte units. For unformatted files, the RECL unit is 4-byte units, unless you specify the -assume byterecl option to request 1-byte units.
If the unit is not connected:
The OPENED specifier indicates a false value.
The unit NUMBER specifier variable is returned as a value of -1.
Any other information returned will be undefined or default values for the various specifiers.
For example, the following INQUIRE statement shows whether unit 3 has a file connected (OPENED specifier) in logical variable I_OPENED, the name (case-sensitive) in character variable I_NAME, and whether the file is opened for READ, WRITE, or READWRITE access in character variable I_ACTION:
INQUIRE (3, OPENED=I_OPENED, NAME=I_NAME, ACTION=I_ACTION)
An inquiry by name causes the Intel Fortran RTL to scan its list of open files for a matching file name. One of the following occurs, depending on whether a match occurs or not:
If a match occurs:
The EXIST and OPENED specifier variables indicate a true value.
The pathname and file name are returned in the NAME specifier variable.
The UNIT number is returned in the NUMBER specifier variable.
Other information requested on the previously connected file is returned.
Default values are usually returned for the INQUIRE specifiers also associated with the OPEN statement.
The RECL value unit for connected formatted files is always 1-byte units. For unformatted files, the RECL unit is 4-byte units, unless you specify the -assume byterecl option to request 1-byte units.
If no match occurs:
The OPENED specifier variable indicates a false value.
The unit NUMBER specifier variable is returned as a value of -1.
The EXIST specifier variable indicates (true or false) whether the named file exists on the device or not.
If the file does exist, the NAME specifier variable contains the pathname and file name.
Any other information returned will be default values for the various specifiers, based on any information specified when calling INQUIRE.
The following INQUIRE statement returns whether the file named log_file is connected in logical variable I_OPEN, whether the file exists in logical variable I_EXIST, and the unit number in integer variable I_NUMBER:
INQUIRE (FILE='log_file', OPENED=I_OPEN, EXIST=I_EXIST, NUMBER=I_NUMBER)
Unlike inquiry by unit or inquiry by name, inquiry by output item list does not attempt to access any external file. It returns the length of a record for a list of variables that would be used for unformatted WRITE, READ, and REWRITE statements. The following INQUIRE statement returns the maximum record length of the variable list in variable I_RECLENGTH. This variable is then used to specify the RECL value in the OPEN statement:
INQUIRE (IOLENGTH=I_RECLENGTH) A, B, H OPEN (FILE='test.dat', FORM='UNFORMATTED', RECL=I_RECLENGTH, UNIT=9)
For an unformatted file, the IOLENGTH value is returned using 4-byte units, unless you specify the -assume byterecl option to request 1-byte units.
An inquiry by directory verifies that a directory exists.
If the directory exists:
The EXIST specifier variable indicates a true value.
The full directory pathname is returned in the DIRSPEC specifier variable.
If the directory does not exist:
The EXIST specified variable indicates a false value.
The value of the DIRSPEC specifier variable is unchanged.
For example, the following INQUIRE statement returns the full directory pathname:
LOGICAL ::L_EXISTS CHARACTER (255)::C_DIRSPEC INQUIRE (DIRECTORY=".", DIRSPEC=C_DIRSPEC, EXIST=L_EXISTS)
The following INQUIRE statement verifies that a directory does not exist:
INQUIRE (DIRECTORY="I-DO-NOT-EXIST", EXIST=L_EXISTS)