【发布时间】:2017-09-28 06:41:50
【问题描述】:
您好,我已尝试在下面创建一个最小、完整且可验证的示例示例代码,以强调我收到的一条错误消息。错误是“(1) 处的参数 'func0' 中的类型不匹配;将 REAL(4) 传递给 COMPLEX(4)。
我在代码中指出了来自 (1) 的错误消息的位置。当我尝试在另一个子例程中调用一个子例程时会发生这种情况。
我最初尝试在 Sub2 中添加隐式 none,但随后我收到一条错误消息,提示 func0,func1 没有隐式类型。
我试着按照这篇文章的逻辑:How to call and use a subroutine inside another subroutine in fortran?
Module Sample
integer :: n,m
contains
subroutine Sub1(func0,func1)
implicit none
complex, dimension(-10:10, -10:10), intent(inout) :: func0,func1
complex, dimension(-10:10, -10:10) :: Deriv0,Deriv1
do while (100 > 0.000001)
Deriv0 = Deriv(func0)
Deriv1 = Deriv(func1)
end do
end subroutine Sub1
subroutine Sub2(func3)
!implicit none : if this line is not commented out, I still get error messages saying func0,func1 do not have implicit types
real,dimension(0:20), intent(inout) :: Func3
call Sub1(func0,func1) !error message from here, this is line (1)
end subroutine Sub2
function Deriv(func)
implicit none
complex, dimension(-10:10, -10:10) :: func, Deriv
do n=-9,9
do m=-9,9
Deriv(n,m) = func(n+1,m)-2*func(n,m)
end do
end do
end function Deriv
End Module Sample
如何解决此错误?谢谢。
【问题讨论】:
标签: fortran subroutine