Intel® Fortran Compiler 16.0 User and Reference Guide

PRESENT

Inquiry Intrinsic Function (Generic): Returns whether or not an optional dummy argument is present, that is, whether it has an associated actual argument.

result = PRESENT (a)

a

(Input) Must be an argument of the current procedure and must have the OPTIONAL attribute. An explicit interface for the current procedure must be visible to its caller; for more information, see Procedure Interfaces.

Results

The result is a scalar of type default logical. The result is .TRUE. if a is present; otherwise, the result is .FALSE..

Example

Consider the following:

MODULE MYMOD
CONTAINS
SUBROUTINE CHECK (X, Y)
  REAL X, Z
  REAL, OPTIONAL :: Y
  ...
  IF (PRESENT (Y)) THEN
    Z = Y
  ELSE
     Z = X * 2
  END IF
END SUBROUTINE CHECK
END MODULE MYMOD
...
USE MYMOD
CALL CHECK (15.0, 12.0) ! Causes Z to be set to 12.0
CALL CHECK (15.0) ! Causes Z to be set to 30.0

The following shows another example:

 CALL who( 1, 2 ) ! prints "A present" "B present"
 CALL who( 1 ) ! prints "A present"
 CALL who( b = 2 ) ! prints "B present"
 CALL who( ) ! prints nothing
 CONTAINS
   SUBROUTINE who( a, b )
     INTEGER(4), OPTIONAL :: a, b
     IF (PRESENT(a)) PRINT *,'A present'
     IF (PRESENT(b)) PRINT *,'B present'
   END SUBROUTINE who
 END

See Also