Skip to content

Instantly share code, notes, and snippets.

@nicolasbock
Created December 3, 2014 20:03
Show Gist options
  • Save nicolasbock/6a498f20486f29284ac3 to your computer and use it in GitHub Desktop.
Save nicolasbock/6a498f20486f29284ac3 to your computer and use it in GitHub Desktop.
Enclosing functions in Fortran
project( enclosing-functions Fortran )
add_executable( test
test.F90
func.F90
)
module func
implicit none
contains
logical function func_outer (a)
integer, intent(in) :: a
integer :: b
b = func_inner(1, a)
if(b > 10) then
func_outer = .true.
else
func_outer = .false.
endif
contains
integer function func_inner (a, b)
integer, intent(in) :: a, b
func_inner = a+b
end function func_inner
end function func_outer
end module func
program test
use func
logical :: func_result
func_result = func_outer(1)
if(func_result) then
write(*, *) ".true."
else
write(*, *) ".false."
endif
func_result = func_outer(10)
if(func_result) then
write(*, *) ".true."
else
write(*, *) ".false."
endif
end program test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment