我在Fortan 90中遇到了这个错误:
虚拟过程'dfpmin'中的接口不匹配(1):参数n的维1中的形状不匹配
我的主要代码以:
开头program main
real(8), allocatable :: theta(:)
real(8), allocatable :: grad(:)
real(8), allocatable :: mat(:,:)
real(8), allocatable :: thetagrad(:)
以及稍后在代码中,向量theta
被分配为维度ntheta
allocate(theta(ntheta))
end program main
另一方面,子程序以
开始SUBROUTINE dfpmin(theta,n,gtol,func)
IMPLICIT NONE
REAL(8), INTENT(IN) :: gtol
INTEGER, INTENT(IN) :: n ! number of elements in the parameter vector
REAL(8), INTENT(INOUT) :: theta(n) ! parameter vector over which you which to maximize
INTERFACE ! This lets the subroutine know that func is not a variable, it is a function
REAL(8) FUNCTION func(theta,n) ! This is not the likelihood itself, it just let the program know
IMPLICIT NONE
INTEGER, INTENT(IN) :: n
REAL(8), INTENT(IN) :: theta(n)
END FUNCTION func
END INTERFACE
END SUBROUTINE DFPMIN
然后我反复出现这个尺寸误差。我试图在子例程中更改为dimension(:)
,但它不起作用。
你有什么建议吗?