Inquire

Statement Type:

This is an executable statement.

Statement Purpose:

The inquire statement is used to check on the status of different files.

Required Form:

inquire ( inquiry list)

Required Inquiry List Elements:

The inquiry list must contain one of the following:

FILE=

This is followed either by a quoted string or character variable containing the name of the file, for which information is needed.

or

UNIT=

This is followed by an integer variable or constant specifying the unit number for which information is needed.

Optional Inquiry List Elements:

There are other specifies that can go along with the INQUIRE statement. Most have uses that are beyond what a beginning programer has need for. Listed below are three more specifiers that may be useful for the beginner. However if additional information is required about some of the other specifiers, please consult a manual on the Fortran Standard.

EXIST=

After this specifier goes a logical variable. The program will then assign a value of true to the variable if the file does indeed exist and a value of false if it doesn't.

RECL=

The number that gets returned when this specifier is used is the record length of a file connected for direct access, or the maximum record length for a file connected as sequential access.

ACCESS=

This returns the access type or the kind of file you are inquiring about. The three character strings that can be returned are SEQUENTIAL, DIRECT, or UNDEFINED. These character strings are then stored in a character variable that is placed after the equals sign.

Examples:

To check on the existence of a file:
		inquire (file="data.in",exist=log1)
This by itself won't help much as the program won't tell you anything if the file doesn't exist. So, do the following to find out:
		if (log1==.false.) then
		   Print *, 'File data.in does not exist!'
		   stop
              endif

Related Topics and Lectures

open statement

close statement

logical variables

relational operators

if statement

lecture twenty two

Up one level / Home


Written by Jason Wehr : jcw142@psu.edu and Maintained by John Mahaffy : jhm@cac.psu.edu