FORTRAN 77 Language Reference

INQUIRE

The INQUIRE statement returns information about a unit or file.

INQUIRE([UNIT =] u, slist)

INQUIRE(FILE = fn, slist)

Parameter 

Description 

fn

Name of the file being queried  

u

Number of the file being queried  

slist

The specifiers list slist can include one or more of the following, in any order:

  • ERR = s

  • EXIST = ex

  • OPENED = od

  • NAMED = nmd

  • ACCESS = acc

  • SEQUENTIAL = seq

  • DIRECT = dir

  • FORM = fm

  • FORMATTED = fmt

  • UNFORMATTED = unf

  • NAME = fn

  • BLANK = blnk

  • IOSTAT = ios

  • NUMBER = num

  • RECL = rcl

  • NEXTREC = nr

Description

You can determine such things about a file as whether it exists, is opened, or is connected for sequential I/O. That is, files have such attributes as name, existence (or nonexistence), and the ability to be connected in certain ways (FORMATTED, UNFORMATTED, SEQUENTIAL, or DIRECT).

Inquire either by unit or by file, but not by both in the same statement.

In this system environment, the only way to discover what permissions you have for a file is to use the ACCESS(3F) function. The INQUIRE statement does not determine permissions.

The following table summarizes the INQUIRE specifiers:

Table 4-1 INQUIRE Specifiers Summary

Form: SPECIFIER = Variable 

SPECIFIER 

Value of Variable  

Data Type of Variable 

ACCESS

'DIRECT' 'SEQUENTIAL'

CHARACTER

BLANK

'NULL'

'ZERO'

CHARACTER

DIRECT *

'YES' 'NO' 'UNKNOWN'

CHARACTER

ERR

Statement number  

INTEGER

EXIST

.TRUE.

.FALSE.

LOGICAL

FORM

'FORMATTED' 'UNFORMATTED'

CHARACTER

FORMATTED *

'YES' 'NO' 'UNKNOWN'

CHARACTER

IOSTAT

Error number 

INTEGER

NAME

Name of the file 

CHARACTER

NAMED

.TRUE.

.FALSE.

LOGICAL

NEXTREC

Next record number 

INTEGER

NUMBER *

Unit number 

INTEGER

OPENED

.TRUE.

.FALSE.

LOGICAL

RECL

Record length 

INTEGER

SEQUENTIAL *

'YES' 'NO' 'UNKNOWN'

CHARACTER

UNFORMATTED *

'YES' 'NO' 'UNKNOWN'

CHARACTER

* indicates non-standard for inquire-by-unit, but accepted by f77. indicates non-standard for inquire-by-file, but accepted by f77.

Also:

INQUIRE Specifier Keywords

The following provides a detailed list of the INQUIRE specifier keywords:

ACCESS=acc

BLANK=blnk

DIRECT=dir

ERR=s

EXIST=ex

FILE=fn

FORM=fm

FORMATTED=fmt

IOSTAT=ios

NAME=fn

NAMED=nmd

NEXTREC=nr

NUMBER=num

OPENED=od

RECL=rcl

SEQUENTIAL=seq

UNFORMATTED=unf

UNIT=u

Examples

Example 1: Inquire by unit:


       LOGICAL OK 
       INQUIRE( UNIT=3, OPENED=OK ) 
       IF ( OK ) CALL GETSTD ( 3, STDS ) 

Example 2: Inquire by file:


       LOGICAL THERE 
       INQUIRE( FILE='.profile', EXIST=THERE ) 
       IF ( THERE ) CALL GETPROFILE( FC, PROFILE ) 

Example 3: More than one answer, omitting the UNIT=:


       CHARACTER FN*32 
       LOGICAL HASNAME, OK 
       INQUIRE ( 3, OPENED=OK, NAMED=HASNAME, NAME=FN ) 
       IF ( OK .AND. HASNAME ) PRINT *, 'Filename="', FN, '"'