Statement: Returns information on the status of specified properties of a file or logical unit. It takes one of the following forms:
Syntax
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.
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.
Rules and Behavior
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 keyword 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.
Compatibility
CONSOLE STANDARD GRAPHICS QUICKWIN GRAPHICS WINDOWS DLL LIB
See Also: INQUIRE Statement, OPEN
Examples
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 following shows another example:
! This program prompts for the name of a data file.
! The INQUIRE statement then determines whether
! the file exists. If it does not, the program
! prompts for another file name.
CHARACTER*12 fname
LOGICAL exists
! Get the name of a file:
100 WRITE (*, '(1X, A\)') 'Enter the file name: '
READ (*, '(A)') fname
! INQUIRE about file's existence:
INQUIRE (FILE = fname, EXIST = exists)
IF (.NOT. exists) THEN
WRITE (*,'(2A/)') ' >> Cannot find file ', fname
GOTO 100
END IF
END