Jump to content United States-English
HP.com Home Products and Services Support and Drivers Solutions How to Buy
» Contact HP
More options
HP.com home
HP Fortran 90 Programmer's Reference: HP Fortran 90 Programmer's Reference > Chapter 10 HP Fortran 90 statements

INQUIRE

» 

Technical documentation

Complete book in PDF
» Feedback
Content starts here

 » Table of Contents

 » Glossary

Returns information about file properties.

Syntax

The syntax of the INQUIRE statement has two forms:

  • Inquiry by output list:

    INQUIRE ( IOLENGTH= integer-variable) output-list
  • Inquiry by unit or file:

    INQUIRE (io-specifier-list)
integer-variable

is the length of the unformatted record that would result from writing output-list to a direct-access file. The value returned in integer-variable can be used with the RECL= specifier in an OPEN statement to specify the length of each record in an unformatted direct-access file that will hold the data in output-list.

output-list

is a comma-separated list of data items, similar to what would be included with the WRITE or PRINT statement. The data items can include variables and implied-DO lists (see “Implied-DO loop”).

io-specifier-list

is a list of comma-separated I/O specifiers. As noted in the following descriptions, most of the specifiers return information about the specified unit or file. io-specifier-list must include either the UNIT= or FILE= specifier, but not both. The following paragraphs describe all the I/O specifiers that can appear in io-specifier-list:

[UNIT=]unit

specifies the unit connected to an external file. unit must be an integer expression that evaluates to a number greater than 0. If the optional keyword UNIT= is omitted, unit must be the first item in io-specifier-list. If unit appears in io-specifier-list, the FILE= specifier must not be used.

ACCESS=character

returns the following values, indicating the method of access:

'SEQUENTIAL'

File is connected for sequential access.

'DIRECT'File is connected for direct access.
'UNDEFINED'File is not connected.

ACTION=character-variable

returns the following values, indicating the direction of the transfer:

'READ'File is connected for reading only.
'WRITE'File is connected for writing only.
'READWRITE'File is connected for reading and writing.
'UNDEFINED'File is not connected.

BLANK=character-variable

returns the type of blank control that is in effect. For information about blank control, see the BLANK= specifier for the OPEN statement. The values returned by the BLANK= specifier are:

'NULL'Null blank control is in effect.
'ZERO'Zero blank control is in effect.
'UNDEFINED'File is not connected for formatted I/O.

DELIM=character-variable

returns the following values, indicating the character to use (if any) to delimit character values in list-directed and namelist formatting:

'APOSTROPHE'An apostrophe is used as the delimiter.
'QUOTE'The double quotation mark is used as the delimiter.
'NONE'There is no delimiting character.
'UNDEFINED'

File is not connected for formatted I/O.

DIRECT=character-variable

returns the following values, indicating whether or not the file is connected for direct access:

'YES'File is connected for direct access.
'NO'

File is not connected for direct access.

'UNKNOWN'It cannot be determined whether or not file is connected for direct access.

ERR=stmt-label

specifies the label of the executable statement to which control passes if an error occurs during statement execution.

EXIST=logical-variable

returns the following values, indicating whether or not the file or unit exists:

'TRUE'File exists or unit is connected.
'FALSE'File does not exist or unit is not connected.

FILE=character-expression

specifies the name of a file for inquiry. The file does not have to be connected or even exist. If the FILE= specifier appears in io-specifier-list, the UNIT= specifier must not be used.

FORM=character-variable

returns the following values, indicating whether the file is connected for formatted or unformatted I/O:

'FORMATTED'File is connected for formatted I/O.
'UNFORMATTED'File is connected for unformatted I/O.
'UNDEFINED'File is not connected.

FORMATTED=character-variable

returns the following values, indicating whether or not the file is connected for formatted I/O:

'YES'File is connected for formatted I/O.
'NO'File is not connected for formatted I/O.
'UNKNOWN'It cannot be determined whether or not file is connected for formatted I/O.

IOSTAT=integer-variable

returns the I/O status after the statement executes. If the statement successfully executes, integer-variable is set to zero. If an error occurs, it is set to a positive integer that indicates which error occurred..

NAME=character-variable

returns the name of file connected to the specified unit. If the file has no name or is not connected, NAME= returns the string UNDEFINED.

NAMED=logical-variable

returns the following values, indicating whether or not the file has a name:

'TRUE'File has a name.
'FALSE'File does not have a name.

NEXTREC=integer-variable

returns the number of the next record to be read or written in a file connected for direct access. The value is the last record read or written +1. A value of 1 indicates that no records have been processed. If the file is not connected or it is a device file or its status cannot be determined, integer-variable is undefined.

NUMBER=integer-variable

returns the unit number that is connected to the specified file. If no unit is connected to the named file, integer-variable is undefined.

OPENED=logical-variable

returns the following values, indicating whether or not the file has been opened (that is, is connected):

'TRUE'File is connected.
'FALSE'File is not connected.

PAD=character-variable

returns a value indicating whether or not input records are padded with blanks. For more information about padding, see the PAD= specifier for the OPEN statement. The return values are:

'YES'File or unit is connected with PAD='YES' in OPEN statement.
'NO'File or unit is connected with PAD='NO' in OPEN statement.

POSITION=character-variable

returns the following values, indicating the file position:

'REWIND'File is connected with its position at the start of the first record.
'APPEND'File is connected with its position at the end-of-file record.
'ASIS'File is connected without changing its position.
'UNDEFINED'File is not connected or is connected for direct access.

READ=character-variable

returns the following values, indicating whether or not reading is an allowed action for the file:

'YES'Reading is allowed for file.
'NO'Reading is not allowed for file.
'UNKNOWN'It cannot be determined whether or not reading is allowed for file.

READWRITE=character-variable

returns the following values, indicating whether or not reading and writing are allowed actions for the file:

'YES'Both reading and writing are allowed for file.
'NO'Reading and writing are not both allowed for file.
'UNKNOWN'It cannot be determined whether or not reading and writing are both allowed for file.

RECL=integer-variable

returns the record length of the specified unit or file, measured in bytes. The file must be a direct-access file. If the file is not a direct-access file or does not exist, integer-variable is undefined.

SEQUENTIAL=character-variable

returns the following values, indicating whether or not the file is connected for direct access:

'YES'File is connected for sequential access.
'NO'File is not connected for sequential access.
'UNKNOWN'It cannot be determined whether or not file is connected for sequential access.

UNFORMATTED=character-variable

returns the following values, indicating whether or not the file is connected for formatted I/O:

'YES'File is connected for unformatted I/O.
'NO'File is not connected for unformatted I/O.
'UNKNOWN'It cannot be determined whether or not file is connected for unformatted I/O.

WRITE=character-variable

returns the following values, indicating whether or not writing is an allowed action for the file:

'YES'Writing is allowed for file.
'NO'Writing is not allowed for file.
'UNKNOWN'It cannot be determined whether or not writing is allowed for file.

Description

The INQUIRE statement returns selected properties of a specified file or unit number. (It is illegal to include both the UNIT= specifier and the FILE= specifier in the same INQUIRE statement.) Inquiring by unit number should be used on connected files; inquiring by filename is typically used on unconnected files.

In addition, the INQUIRE statement can also be used to determine the record length of a new or existing file. That is, you can use INQUIRE to obtain the record length before creating the file and then use the return value as the argument to the RECL= specifier in an OPEN statement.

Examples

The following examples illustrate different uses of the INQUIRE statement.

Inquiry by file

The INQUIRE statement in this example returns the following information about the file named my_file:

  • The EXIST= specifier determines if the file is connected.

  • The DIRECT= specifier determines if it is connected for direct access.

  • The READWRITE= specifier determines if it can be read and written.

LOGICAL :: exist
CHARACTER(LEN=9) :: dir_acc, rw_sts
INQUIRE (FILE="my_file", EXIST=exist, &
DIRECT=dir_acc, READWRITE=rw_sts)

Inquiry by unit

The following INQUIRE statement returns the following information about the file connected to the unit in u_num:

  • The OPENED= specifier determines if the file is connected to u_num.

  • The NAMED= specifier determines if it is a named file or a scratch file.

  • The NAME= specifier returns its name.

LOGICAL :: opened, named
INTEGER :: u_num
CHARACTER(LEN=80) :: fname
...
INQUIRE (UNIT=u_num, NAMED=named, OPENED=opened, NAME=fname)

Inquiry by output list

When using the OPEN statement to create a direct-access file, you must specify the record length for the file with the RECL= specifier. Previous to Fortran 90, you had to resort to a nonportable strategy to determine record length. The Fortran 90 INQUIRE statement provides a portable solution: use the INQUIRE statement to inquire by output list, and specify the return value from the INQUIRE statement as the argument to the OPEN statement. The following is an example:

INTEGER :: rec_len, ios

INQUIRE (IOLENGTH=rec_len) x, y, i, j
OPEN (UNIT=32, FILE="new_file", IOSTAT=ios, &
ACCESS="DIRECT", RECL=rec_len)

Related statements

OPEN

Related concepts

For information about I/O concepts, see Chapter 8 “I/O and file handling”.

Printable version
Privacy statement Using this site means you accept its terms Feedback to webmaster
© Hewlett-Packard Development Company, L.P.