Created
December 3, 2014 20:03
-
-
Save nicolasbock/6a498f20486f29284ac3 to your computer and use it in GitHub Desktop.
Enclosing functions in Fortran
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
project( enclosing-functions Fortran ) | |
add_executable( test | |
test.F90 | |
func.F90 | |
) |
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
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 |
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
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