Lahey/Fujitsu Fortran

INQUIRE Statement

Description

The INQUIRE statement enables a program to make inquiries about a unit or file's existence, connection, access method or other properties.

Syntax

INQUIRE (inquire-specs) or INQUIRE (IOLENGTH=iolength) output-items

Where:

inquire-specs is a comma-separated list of

[UNIT =] external-file-unit FILE=file-name-expr IOSTAT=iostat ERR=label EXIST=exist OPENED=opened NUMBER=number NAMED=named NAME=name ACCESS=access SEQUENTIAL=sequential DIRECT=direct FORM=form FORMATTED=formatted UNFORMATTED=unformatted RECL=recl NEXTREC=nextrec BLANK=blank POSITION=position ACTION=action READ=read WRITE=write READWRITE=readwrite DELIM=delim PAD=pad FLEN=flen BLOCKSIZE=blocksize CONVERT =file-format CARRIAGECONTROL=carriagecontrol
`

external-file-unit is a scalar INTEGER expression that evaluates to the input/output unit number of an external file.

file-name-expr is a scalar CHARACTER expression that evaluates to the name of a file.

iostat is a scalar default INTEGER variable having a positive value if an error condition occurs, a negative value if an end-of-file or end-of-record condition occurs, and zero otherwise.

label is the statement label of the statement branched to if an error occurs.

exist is a scalar default LOGICAL variable having the value true if the file specified in the FILE= specifier exists or the input/output unit specified in the UNIT= specifier exists, and false otherwise.

opened is a scalar default LOGICAL variable having the value true if the file or input/output unit specified is connected, and false otherwise.

number is a scalar default INTEGER variable having the value of the input/output unit of the external file or -1 if the file is not connected or does not exist.

named is a scalar default LOGICAL variable having the value true if the file has a name and false otherwise.

name is a scalar default CHARACTER variable having the name of the file, if the file has a name, otherwise it becomes undefined.

access is a scalar default CHARACTER variable that evaluates to SEQUENTIAL if the file is connected for sequential access, DIRECT if the file is connected for direct access, TRANSPARENT for byte stream access, or UNDEFINED if the file is not connected.

sequential is a scalar CHARACTER variable having the value YES if sequential access is allowed for the file, NO if sequential access is not allowed, and UNKNOWN if the file is not connected or does not exist.

direct is a scalar CHARACTER variable having the value YES if direct access is allowed for the file, NO if direct access is not allowed, and UNKNOWN if the file is not connected or does not exist.

form is a scalar CHARACTER variable having the value FORMATTED if the file is connected for formatted input/output, UNFORMATTED if the file is connected for unformatted input/output, and UNDEFINED if there is no connection.

formatted is a scalar CHARACTER variable having the value YES if formatted is an allowed form for the file, NO if formatted is not allowed, and UNKNOWN if the file is not connected or does not exist.

unformatted is a scalar CHARACTER variable having the value YES if unformatted is an allowed form for the file, NO if unformatted is not allowed, and UNKNOWN if the file is not connected or does not exist.

recl is a scalar default INTEGER variable that evaluates to the record length in bytes for a file connected for direct access, or the maximum record length in bytes for a file connected for sequential access, or zero if the file is not connected or does not exist.

nextrec is a scalar default INTEGER variable having the value n+1, where n is the number of the last record read or written on the file connected for direct access. If the file has not been written to or read from since becoming connected, the value 1 is assigned. If the file is not connected for direct access, the value becomes zero.

blank is a scalar CHARACTER variable that evaluates to NULL if null blank control is in effect, ZERO if zero blank control is in effect, and UNDEFINED if the file is not connected for formatted input/output or does not exist.

position is a scalar CHARACTER variable that evaluates to REWIND if the newly opened sequential access file is positioned at its initial point; APPEND if it is positioned before the endfile record if one exists and at the file terminal point otherwise; ASIS if the position is after the endfile record; and UNDEFINED if the file is not connected or does not exist.

action is a scalar CHARACTER variable that evaluates to READ if the file is connected for input only, WRITE if the file is connected for output only, READWRITE if the file is connected for input and output, and UNDEFINED if the file is not connected or does not exist.

read is a scalar CHARACTER variable having the value YES if READ is an allowed action on the file, NO if READ is not an allowed action of the file, and UNKNOWN if the file is not connected or does not exist.

write is a scalar CHARACTER variable having the value YES if WRITE is an allowed action on the file, NO if WRITE is not an allowed action of the file, and UNKNOWN if the file is not connected or does not exist.

readwrite is a scalar CHARACTER variable having the value YES if READWRITE is an allowed action on the file, NO if READWRITE is not an allowed action of the file, and UNKNOWN if the file is not connected or does not exist.

delim is a scalar CHARACTER variable that evaluates to APOSTROPHE if the apostrophe is used to delimit character constants written with list-directed or namelist formatting, QUOTE if the quotation mark is used, NONE if neither quotation marks nor apostrophes is used, and UNDEFINED if the file is not connected or does not exist.

pad is a scalar CHARACTER variable that evaluates to YES if the formatted input record is padded with blanks or if the file is not connected or does not exist, and NO otherwise.

flen is a scalar default INTEGER variable having the length of the file in bytes.

blocksize is a scalar default INTEGER variable that evaluates to the size, in bytes, of the I/O buffer. This value may be internally adjusted to a record size boundary if the unit has been connected for direct access and therefore may no agree with the BLOCKSIZE specifier specified in an OPEN Statement. The value is zero if the file is not connected or does not exist.

file-format is a scalar CHARACTER variable that evaluates to BIG_ENDIAN if big endian conversion is in effect, LITTLE_ENDIAN if little endian conversion is in effect, IBM if IBM style conversion is in effect, and NATIVE if no conversion is in effect.

carriagecontrol is a scalar CHARACTER variable that evaluates to FORTRAN if the first character of a formatted sequential record is used for carriage control, and LIST otherwise.

iolength is a scalar default INTEGER variable having a value that would result from the use of output-items in an unformatted output statement. The value is used as a RECL= specifier in an OPEN statement that connects a file for unformatted direct access when there are input/output statements with the same list of output-items.

output-items is a comma-separated list of items used with iolength as explained immediately above.

Remarks

When the INQUIRE statement is executed for a file or unit that is not connected, information about that file or unit is limited to the existence of the file, and the connection status of the file or unit.

inquire-specs must contain one FILE= specifier or one UNIT= specifier, but not both, and at most one of each of the other specifiers.

In the inquire by unit form of the INQUIRE statement, if the optional characters UNIT= are omitted from the unit specifier, the unit specifier must be the first item in inquire-specs.

When a returned value of a specifier other than the NAME= specifier is of type CHARACTER and the processor is capable of representing letters in both upper and lower case, the value returned is in uppercase.

If an error condition occurs during execution of an INQUIRE statement, all of the inquiry specifier variables become undefined, except for the variable in the IOSTAT= specifier (if any).

Example

logical :: lopened,lexist integer :: this_unit=10 inquire (this_unit,opened=lopened) if(lopened) then write(*,*) " Unit ",this_unit," is open!" else write(*,*) " Unit ",this_unit," is not open!" end if inquire (file="inquire.f90",exist=lexist) if(lexist) then write(*,*) " The file 'inquire.f90' exists!" else write(*,*) " The file 'inquire.f90' does not exist!" end if