I have the following question concerning the usage of optional argument. Let's say I have the following routine aaa
defined in module m_aaa
MODULE m_aaa
SUBROUTINE aaa(a, b)
INTEGER :: a
INTEGER, OPTIONAL :: b
END SUBROUTINE
END MODULE
now I have a second routine that uses the module m_aaa
. Is it possible to pass the optional argument like this
! Variant 1:
SUBROUTINE bbb(c, d)
USE m_aaa
INTEGER :: c
INTEGER, OPTIONAL :: d
CALL aaa(c,d)
END SUBROUTINE
or is it necessary to check the presence of the optional argument d like this:
! 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
Thanks for your help.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…