Skip to content

Instantly share code, notes, and snippets.

@ivan-pi
Created November 24, 2021 22:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ivan-pi/ef5025b802e352d61ff5ecd1db9ecb95 to your computer and use it in GitHub Desktop.
Save ivan-pi/ef5025b802e352d61ff5ecd1db9ecb95 to your computer and use it in GitHub Desktop.
fypp macros for dealing with Fortran optional arguments
#! 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