我正在尝试编写一个有两个参数的子程序(用于最小化):
x任意长度的数组f获取该长度数组并返回标量的函数示例模块:
module foo
contains
subroutine solve(x, f)
real, dimension(:), intent(inout) :: x
interface
real pure function f(y)
import x
real, dimension(size(x)), intent(in) :: y
end function
end interface
print *, x
print *, f(x)
end subroutine
end module
Run Code Online (Sandbox Code Playgroud)
和测试程序:
use foo
real, dimension(2) :: x = [1.0, 2.0]
call solve(x, g)
contains
real pure function g(y)
real, dimension(2), intent(in) :: y
g = sum(y)
end function
end
Run Code Online (Sandbox Code Playgroud)
gfortran失败了:
call solve(x, g)
1
Error: Interface …Run Code Online (Sandbox Code Playgroud)