Visible to Intel only — GUID: GUID-EF9A6DF9-DB27-4A2B-B195-D133FD16DFCF
Visible to Intel only — GUID: GUID-EF9A6DF9-DB27-4A2B-B195-D133FD16DFCF
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. |
The result is a scalar of type default logical. The result is .TRUE. if a is present; otherwise, the result is .FALSE..
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