Determine whether an optional argument is present. If it is not present, you may only pass it as an optional argument to another procedure or pass it as an argument to PRESENT.
Result Type and Attributes
Default logical scalar.
The result is .TRUE. if the actual argument is present (that is, if it was passed to the current procedure in the specified dummy argument), and .FALSE. otherwise.
SUBROUTINE SUB (X, Y) REAL, OPTIONAL :: Y IF (PRESENT (Y)) THEN ! In this section, we can use y like any other variable. X = X + Y PRINT *, SQRT(Y) ELSE ! In this section, we cannot define or reference y. X = X + 5 ! We can pass it to another procedure, but only if ! sub2 declares the corresponding argument as optional. CALL SUB2 (Z, Y) ENDIF END SUBROUTINE SUB