Skip to content

Instantly share code, notes, and snippets.

@cbcoutinho
Created February 6, 2017 09:18
Show Gist options
  • Save cbcoutinho/cbe24f170af9f6229c0e916d10f9e988 to your computer and use it in GitHub Desktop.
Save cbcoutinho/cbe24f170af9f6229c0e916d10f9e988 to your computer and use it in GitHub Desktop.
A simple Fortran file with submodules, a generic interface, and module procedures
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