我创建了一个fortran 90程序,我在linux机器上使用并使用gfortran编译。它在gfortran的linux机器上工作正常,但提供了错误
error 327 - In the INTERFACE to SECANTMETHOD (from MODULE SECMETH), the ninth dummy argument (F) was of type REAL(KIND=2) FUNCTION, whereas the actual argument is of type REAL(KIND=2)
使用Plato编译器(FTN95)时。有谁知道我需要如何更改我的代码才能在柏拉图中工作?我试着读一下这个错误,并且有一些提到指针,但是从我尝试的那些不起作用。我已经找到了一些解决方法,但是它们使得子程序不能再接受任何函数作为参数 - 这几乎是无用的。任何帮助将不胜感激。我的代码如下。
!--! A module to define a real number precision.
module types
integer, parameter :: dp=selected_real_kind(15)
end module types
module secFuncs
contains
function colebrookWhite(T)
use types
real(dp) :: colebrookWhite
real(dp), intent(in) :: T
colebrookwhite=25-T**2
return
end function colebrookWhite
end module secFuncs
module secMeth
contains
subroutine secantMethod(xolder,xold,xnew,epsi1,epsi2,maxit,exitFlag,numit,f)
use types
use secFuncs
implicit none
interface
function f(T)
use types
real(dp) :: f
real(dp), intent(in) :: T
end function f
end interface
real(dp), intent(in) :: epsi1, epsi2
real(dp), intent(inout) :: xolder, xold
real(dp), intent(out) :: xnew
integer, intent(in) :: maxit
integer, intent(out) :: numit, exitFlag
real(dp) :: fxold, fxolder, fxnew
integer :: i
fxolder = f(xolder)
fxold = f(xold)
i = 0
do
i = i + 1
xnew = xold - fxold*(xold-xolder)/(fxold-fxolder)
fxnew = f(xnew)
if (i == maxit) then
exitFlag = 1
numit = i
return
else if (abs(fxnew) < epsi1) then
exitFlag = 2
numit = i
return
else if (abs(xnew - xold) < epsi2) then
exitFlag = 3
numit = i
return
end if
xolder = xold
xold = xnew
fxolder = fxold
fxold = fxnew
end do
end subroutine secantMethod
end module secMeth
program secantRoots
use types
use secMeth
use secFuncs
implicit none
real(dp) :: x1, x2, xfinal, epsi1, epsi2
integer :: ioerror, maxit, numit, exitFlag
do
write(*,'(A)',advance="no")"Please enter two initial root estimates, 2epsi's, and maxit: "
read(*,*,iostat=ioerror) x1, x2, epsi1, epsi2, maxit
if (ioerror /= 0) then
write(*,*)"Invalid input."
else
exit
end if
end do
call secantMethod(x1,x2,xfinal,epsi1,epsi2,maxit,exitFlag,numit,colebrookWhite)
if (exitFlag == 1) then
write(*,*)"The maximum number of iterations was reached."
else if (exitFlag == 2) then
write(*,'(a,f5.3,a,i3,a)')"The root is ", xfinal, ", which was reached in ", numit, " iterations."
else if (exitFlag == 3) then
write(*,'(a,i3,a)')"There is slow or no progress at ", numit, " iterations."
end if
end program secantRoots
答案 0 :(得分:2)
当前gfortran在secantMethod
过程的调用中检测到错误,其中您有括号,但没有参数列表,遵循colebrookWhite
函数名称。
如果要将函数作为参数传递(与评估函数的结果相反),这是您要在此处执行的操作,则不要使用带括号对的函数名称。
call secantMethod(x1,x2,xfinal,epsi1,epsi2,maxit,exitFlag,numit,colebrookWhite )
! ^
答案 1 :(得分:0)
我最终只是从Plato切换到Geany IDE(我实际上更喜欢Geany WAY,因为我已经使用了几个小时),使用Geany设置gfortran,并且代码适用于该设置。我猜测我得到Plato错误的原因是它的编译器实际上是一个fortran95编译器,而gfortran是一个fortran90编译器。花了一段时间让一切工作,但是一旦我为gfortran下载mingw-w64并将路径用户(非系统)环境变量设置到正确的位置,一切都很好。我仍然有兴趣看看是否有办法让代码与FTN95编译器一起工作,但最后我还是坚持使用gfortran和Geany。