Additional Arguments Fortran 90/95

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

! Variant 1:
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.

+4
source share
1 answer

There is no need to check for an optional dummy argument before passing it as an actual argument to another dummy type optional argument.

12.5.2.12 4 (/ 1539-1 ( 7 2010 ), Fortran 2008) , :

, , , , .

+6

All Articles