我正在尝试编写一个计算h = g(f(x))的简单Fortran代码。 x是长度= 2的向量。
module m1
implicit none
contains
function f(x)
implicit none
real::f(2),x(2)
f(1)=x(1)-x(2)
f(2)=exp(x(1))-x(2)**2
end function f
function g(ff)
implicit none
real::g(2),x1(2),ffreslt(2)
interface
function ff(x)
implicit none
real::x(2),ff(2)
end function ff
end interface
ffreslt=ff(x1)
g(1)=1-ffreslt(1)
g(2)=2*ffreslt(1)**2-3*ffreslt(2)+4.2
end function g
end module m1
program hgf
use m1
implicit none
real::x1(2),h(2)
x1 = (/0.55,2.47/)
h = g(f(x1))
write(*,*) h
end program hgf
但是,我收到此错误消息:
h = g(f(x1))
1
Error: Actual parameter 'ff' at <1> is not a PROCEDURE
我错过了什么吗?谢谢。
答案 0 :(得分:5)
在对g()的调用中,你没有传递函数f(),而是调用函数f()的值为x1的结果。
检查此Notes on converting from F77 to F90并查看第24页第3.2.7节。
另请在procedures as arguments上查看此问题。