next up previous contents index
Next: READ and WRITE Statements Up: Input/Output Facilities Previous: CLOSE Statement

INQUIRE Statement

 

The INQUIRE statement can be used in two slightly different forms:
INQUIRE(UNIT= integer-expression, inquire-list )
INQUIRE(FILE= em character-expression, inquire-list )
The first form, an inquire by unit, returns information about the unit and, if it is connected to a file, about the file as well. If it is not connected to a file then most of the arguments will be undefined or return a value of 'UNKNOWN' as appropriate.

The second form, inquire by file, can always be used to find out whether a named file exists, i.e. can be opened by a Fortran program. Any trailing blanks in the character expression are ignored, and the forms of file-name acceptable are, as in the OPEN statement, system-dependent. If the file exists and is connected to a unit then much more information can be obtained.

The inquire-list may contain any of the items below. Note that all of them (except for ERR=label) return information by assigning a value to a named variable (or array element). The normal rules of assignment statements apply, so that so that character items may have any reasonable length will return a value which is padded out with blanks to its declared length if necessary.

IOSTAT=integer-variable and ERR=label can both be used in the same way as in OPEN or CLOSE; note that they detect errors during the execution of the INQUIRE statement itself, and do not reflect the state of the file or unit which is the subject of the inquiry.
EXIST=logical-variable sets the variable (or array-element) to .TRUE. if the specified unit or file exists, or .FALSE. if it does not. A unit exists if it has a number in the permitted range. A file exists if it can be used in an OPEN statement. A file may appear not to exist merely because the operating system prevents its use, for example because a password is needed or because some other user has already opened it.

OPENED=logical-variable sets the variable to .TRUE. if the specified unit (or file) is currently connected to a file (or unit) in the program.

NUMBER=integer-variable returns the unit number of a file which is connected to the variable; otherwise it becomes undefined.

NAME=character-variable returns the file-name to the variable if the file has a name; if not it becomes undefined. In the case of an inquire by file the name may not be the same as that specified using FILE= (because a device-name or directory path may have been added) but the name returned will always be suitable for use in an OPEN statement.

ACCESS=character-variable returns the record access-method, either 'SEQUENTIAL' or 'DIRECT' if the file is connected; if it is not connected the variable becomes undefined.

SEQUENTIAL=character-variable returns 'YES' if the file can be opened for sequential access, 'NO' if it cannot, and 'UNKNOWN' otherwise.

DIRECT=character-variable returns 'YES' if the file can be opened for direct access, 'NO' if it cannot, and 'UNKNOWN' otherwise.

FORM=character-variable returns 'FORMATTED' if the file is connected for formatted access, 'UNFORMATTED' if it is connected for unformatted access, or becomes undefined if there is no connection.

FORMATTED=character-variable returns 'YES' if formatted access is permitted, 'NO' if it is not, or 'UNKNOWN' otherwise.

UNFORMATTED=character-variable returns 'YES' if unformatted access is permitted, 'NO' if it is not, or 'UNKNOWN' otherwise.

RECL=integer-variable returns the record length if the file is connected for direct-access but becomes undefined otherwise. Note that the units are characters for formatted files, but are system-dependent for unformatted files.

NEXTREC=integer-variable returns a number which is one higher than the last record read or written if the file is connected for direct access. If it is connected for direct access but no records have been transferred, the variable returns one. If the file is not connected for direct access the variable becomes undefined.

BLANK=character-variable returns 'NULL' or 'BLANK' if the file is connected for formatted access according to the way embedded and trailing blanks are to be treated. In other cases it becomes undefined.

next up previous contents index
Next: READ and WRITE Statements Up: Input/Output Facilities Previous: CLOSE Statement
Helen Rowlands
8/27/1998