INQUIRE

Statement: Returns information on the status of specified properties of a file or logical unit. It takes one of the following forms:

Syntax

Inquiring by File:

INQUIRE (FILE=name [, ERR=label] [, IOSTAT=i-var] [, DEFAULTFILE=def], slist)

Inquiring by Unit:

INQUIRE ([UNIT=]io-unit [, ERR=label] [, IOSTAT=i-var] slist)

Inquiring by Output List:

INQUIRE (IOLENGTH=len) out-item-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.

slist
Is one or more of the following inquiry specifiers (each specifier can appear only once):

ACCESS DELIM NAMED READWRITE
ACTION DIRECT NEXTREC RECL
BINARY EXIST NUMBER RECORDTYPE
BLANK FORM OPENED SEQUENTIAL
BLOCKSIZE FORMATTED ORGANIZATION SHARE
BUFFERED IOFOCUS PAD UNFORMATTED
CARRIAGECONTROL MODE POSITION WRITE
CONVERT NAME READ

def
Is a scalar default character expression specifying a default file pathname string. (For more information, see the DEFAULTFILE specifier.


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
(Output) 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
(Output) Is a list of one or more output items (see I/O Lists).

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