<Separate Module Procedures Example Program 1>
Module separate_mp_example_mod
Integer,Parameter :: wp = Selected_Real_Kind(10)
Interface
Module Real(wp) Function myfun(x)
Real(wp),Intent(In) :: x
End Function
End Interface
Contains
Real(wp) Module Function myfun(x)
Real(wp),Intent(In) :: x
myfun = (x+1)*(x-1)*(x+4)
End Function
End Module
Program test
Use separate_mp_example_mod
Print 1,myfun(-0.5_wp),myfun(0.5_wp),myfun(1.5_wp)
1 Format(3F10.4)
End Program
■ Execution Results
-2.6250 -3.3750 6.8750
<Separate Module Procedures Example Program 2>
Module separate_mp_example_mod2
Interface
Module Recursive Real Function f(x,y) Result(res)
Real,Intent(In) :: x,y
End Function
End Interface
Contains
Module Procedure f
If (y>x) Then
res = f(x,-Abs(y))
Else
res = x**2 - y**3
End If
End Procedure
End Module
Program test
Use separate_mp_example_mod2
Print 1,f(1.5,2.5),f(2.5,1.5),f(1.5,1.5)
1 Format(3F10.4)
End Program
■ Execution Results
17.8750 2.8750 -1.1250