Created
February 6, 2017 09:18
-
-
Save cbcoutinho/cbe24f170af9f6229c0e916d10f9e988 to your computer and use it in GitHub Desktop.
A simple Fortran file with submodules, a generic interface, and module procedures
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 example_mod | |
use iso_fortran_env, only: wp=>real64 | |
implicit none | |
private | |
public :: fun | |
interface fun | |
module function fun1(x) result(y) | |
real(wp), intent(in) :: x | |
real(wp) :: y | |
end function fun1 | |
module function fun2(x, y) result(z) | |
real(wp), intent(in) :: x, y | |
real(wp) :: z | |
end function fun2 | |
end interface | |
end module example_mod | |
submodule (example_mod) example_smod1 | |
use iso_fortran_env, only: wp=>real64 | |
implicit none | |
contains | |
module procedure fun1 | |
y = 2.d0 * x | |
return | |
end procedure fun1 | |
end submodule example_smod1 | |
submodule (example_mod) example_smod2 | |
use iso_fortran_env, only: wp=>real64 | |
implicit none | |
contains | |
function fun2(x, y) result(z) | |
real(wp), intent(in) :: x, y | |
real(wp) :: z | |
z = 2.d0 * x + y | |
return | |
end function fun2 | |
end submodule example_smod2 | |
program main | |
use example_mod, only: fun | |
use iso_fortran_env, only: wp=>real64 | |
implicit none | |
print*, fun(2.d0) | |
print*, fun(2.d0, 3.d0) | |
end program main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment