Inquiry Intrinsic Function (Generic): Returns whether or not an optional dummy argument is present (has an associated actual argument).
Syntax
Results:
The result is a scalar of type default logical. The result is .TRUE. if a is present; otherwise, the result is .FALSE..
Compatibility
CONSOLE STANDARD GRAPHICS QUICKWIN GRAPHICS WINDOWS DLL LIB
See Also: OPTIONAL
Examples
Consider the following:
SUBROUTINE CHECK (X, Y)
REAL X, Z
REAL, OPTIONAL :: Y
...
IF (PRESENT (Y)) THEN
Z = Y
ELSE
Z = X * 2
END IF
END
...
CALL CHECK (15.0, 12.0) ! Causes B to be set to 12.0
CALL CHECK (15.0) ! Causes B 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