The INQUIRE statement obtains information about the properties of a named file or the connection to a particular unit.
There are three forms of the INQUIRE statement:
>>-INQUIRE--+-(--inquiry_list--)-----------------------+------->< '-(--IOLENGTH--=--iol--)--output_item_list-'
char_variable is a character variable that returns the value:
is a file specifier. It specifies the name of the file about which the inquire-by-file form of the statement is inquiring. char_expr is a scalar character expression whose value, when any trailing blanks are removed, is a valid Linux operating system file name. The named file does not have to exist, nor does it have to be associated with a unit.
Coding the IOSTAT= specifier suppresses error messages.
indicates where the next record can be read or written on a file connected for direct access. nr is an integer variable that is assigned the value n + 1, where n is the record number of the last record read or written on the file connected for direct access. If the file is connected but no records were read or written since the connection, nr is assigned the value 1. If the file is not connected for direct access or if the position of the file cannot be determined because of a previous error, nr becomes undefined.
Because record numbers can be greater than 2**31-1, you may choose to make the scalar variable specified with the NEXTREC= specifier of type INTEGER(8). This could be accomplished in many ways, two examples include:
If the file has been repositioned to its initial point since it was opened, pos is assigned the value REWIND. If the file has been repositioned just before its endfile record since it was opened (or, if there is no endfile record, at its terminal point), pos is assigned the value APPEND. If both of the above are true and the file is empty, pos is assigned the value APPEND. If the file is positioned after the endfile record, pos is assigned the value ASIS.
indicates the value of the record length of a file connected for direct access, or the value of the maximum record length of a file connected for sequential access.
rcl is an integer variable that is assigned the value of the record length.
If the file is connected for formatted input/output, the length is the number of characters for all records that contain character data. If the file is connected for unformatted input/output, the length is the number of bytes of data. If there is no connection, rcl becomes undefined.
If the file is connected for stream access, rcl becomes undefined.
char_variable is a scalar character variable. If char_variable is assigned the value BOTH, then both synchronous and asynchronous data transfer are permitted. If char_variable is assigned the value SYNCH, then only synchronous data transfer is permitted. If char_variable is assigned the value UNKNOWN, then the processor is unable to determine the permissible transfer methods for this file.
An INQUIRE statement can be executed before, while, or after a file is associated with a unit. Any values assigned as the result of an INQUIRE statement are values that are current at the time the statement is executed.
If the unit or file is connected, the values returned for the ACCESS=, SEQUENTIAL=, STREAM=, DIRECT=, ACTION=, READ=, WRITE=, READWRITE=, FORM=, FORMATTED=, UNFORMATTED=, BLANK=, DELIM=, PAD=, RECL=, POSITION=, NEXTREC=, NUMBER=, NAME= and NAMED= specifiers are properties of the connection, and not of that file. Note that the EXIST= and OPENED= specifiers return true in these situations.
If a unit or file is not connected or does not exist, the ACCESS=, ACTION=, FORM=, BLANK=, DELIM=, POSITION= specifiers return the value UNDEFINED, the DIRECT=, SEQUENTIAL=, STREAM=, FORMATTED=, UNFORMATTED=, READ=, WRITE= and READWRITE= specifiers return the value UNKNOWN, the RECL= and NEXTREC= specifier variables are not defined, the PAD= specifier returns the value YES, and the OPENED specifier returns the value false. The value returned by the SIZE= specifier is -1.
If a unit or file does not exist, the EXIST= and NAMED= specifiers return the value false, the NUMBER= specifier returns the value -1, and the NAME= specifier variable is not defined.
If a unit or file exists but is not connected, the EXIST= specifier returns the value true. For the inquire-by-unit form of the statement, the NAMED= specifier returns the value false, the NUMBER= specifier returns the unit number, and the NAME= specifier variable is undefined. For the inquire-by-file form of the statement, the NAMED= specifier returns the value true, the NUMBER= specifier returns -1, and the NAME= specifier returns the file name.
The same variable name must not be specified for more than one specifier in the same INQUIRE statement, and must not be associated with any other variable in the list of specifiers.
SUBROUTINE SUB(N) CHARACTER(N) A(5) INQUIRE (IOLENGTH=IOL) A(1) ! Inquire by output list OPEN (7,RECL=IOL)
·
·
·
END SUBROUTINE