Created
November 24, 2021 22:27
-
-
Save ivan-pi/ef5025b802e352d61ff5ecd1db9ecb95 to your computer and use it in GitHub Desktop.
fypp macros for dealing with Fortran optional arguments
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! Can be used currently | |
#:def optval(lhs,opt,default) | |
${lhs}$ = ${default}$ | |
if (present(${opt}$)) ${lhs}$ = ${opt}$ | |
#:enddef | |
#! This is the F202X conditional expression syntax | |
#:def optval2(opt,default) | |
present(${opt}$)) ? ${opt}$ : ${default}$ | |
#:enddef | |
subroutine demo(left) | |
integer, intent(in), optional :: left | |
integer :: l | |
@:optval(l, left, 1) | |
l = @{optval2(left, 1)}@ ! result | |
end subroutine |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment