submodule を使った場合(案)
まだ何がいいかよく分かりません。
julia 言語のプログラムが軽めに見えるので、真似して end xxxx の xxxx を省略してみました。個人的には省略しない派閥なんですがw Fortran も軽くみえていいかも?
intel fortran v.19.1 beta だと end interface の interface と module procedure の module とそれに対応する interface の module が省略できません。この辺、文法理解があいまいですw
submodule の中身などは共通なので、非標準ですが include 文を使えばソースを単一化できると思います。
輸入時の名前の付け替えを用いていますが、輸出時に名前を付けかえれれば、もうちょっとすっきりします。Fortran では出来なかったと思うけど、記憶が曖昧です。あとで文法をもう一度チェックしたいです。
module mods
integer, parameter :: ks = kind(1.0e0)
integer, parameter, private :: kn = ks
interface
module real(kn) function f(x) result(res)
import
real(kn), intent(in) :: x
end
end interface
end
submodule (mods) mod
contains
module procedure f
res = x
end
end
module modd
integer, parameter :: kd = kind(1.0d0)
integer, parameter, private :: kn = kd
interface
module real(kn) function f(x) result(res)
import
real(kn), intent(in) :: x
end
end interface
end
submodule (modd) mod
contains
module procedure f
res = x
end
end
module modq
integer, parameter :: kq = kind(1.0q0)
integer, parameter, private :: kn = kq
interface
module real(kn) function f(x) result(res)
import
real(kn), intent(in) :: x
end
end interface
end
submodule (modq) mod
contains
module procedure f
res = x
end
end
module mod
use mods, only : fun_s => f
use modd, only : fun_d => f
use modq, only : fun_q => f
implicit none
interface fun
procedure :: fun_s, fun_d, fun_q
end interface
end
program test
use mod
implicit none
print *, fun(2.0e0)
print *, fun(2.0d0)
print *, fun(2.0q0)
end
実行結果
2.000000
2.00000000000000
2.00000000000000000000000000000000