I have the following question regarding the use of an optional argument. Let's say I have the following procedure aaadefined in the modulem_aaa
MODULE m_aaa
SUBROUTINE aaa(a, b)
INTEGER :: a
INTEGER, OPTIONAL :: b
END SUBROUTINE
END MODULE
I now have a second procedure that uses the module m_aaa. Is it possible to pass an optional argument like this
SUBROUTINE bbb(c, d)
USE m_aaa
INTEGER :: c
INTEGER, OPTIONAL :: d
CALL aaa(c,d)
END SUBROUTINE
or you need to check for the optional argument d as follows:
! Variant 2:
SUBROUTINE bbb(c, d)
USE m_aaa
INTEGER :: c
INTEGER, OPTIONAL :: d
IF (PRESENT(d)) THEN
CALL aaa(c,d)
ELSE
CALL aaa(c)
ENDIF
END SUBROUTINE
Thank you for your help.
source
share