我很難理解Fortran接口。在問題結尾處粘貼的測試代碼代碼在ifort < =版本15上編譯得很好,但在版本16和更高版本上會導致災難性編譯器錯誤。同樣gfortran(編譯時出現seg fault)。在G95,然而,編譯,出現以下錯誤在Fortran中不匹配的接口90
In file test.f90:79
call rk4(y, dydx, x, h, yout1, der, pars,*10)
1
Error: Interface of actual procedure does not match interface of dummy procedure at (1)
In file test.f90:81
call rk4(y, dydx, x, h/2.d0, yout2, der, pars,*10)
1
Error: Interface of actual procedure does not match interface of dummy procedure at (1)
In file test.f90:85
call rk4(yout2, dydx2, x+h/2.d0, h/2.d0, yout2, der, pars,*10)
1
Error: Interface of actual procedure does not match interface of dummy procedure at (1)
結束,但我不知道我做錯了......
module RK
implicit none
contains
SUBROUTINE rk4(y, dydx, x, h, yout, der, pars, *)
IMPLICIT NONE
integer, parameter :: dp=kind(1.d0)
REAL(dp), DIMENSION(:), INTENT(IN) :: y,dydx,pars
REAL(dp), INTENT(IN) :: x,h
REAL(dp), DIMENSION(:), INTENT(OUT) :: yout
REAL(dp) :: h6,hh,xh
REAL(dp), DIMENSION(size(y)) :: dym,dyt,yt
INTERFACE
SUBROUTINE der(x,y,dydx,pars,*)
IMPLICIT NONE
integer, parameter :: dp=kind(1.d0)
REAL(dp), INTENT(IN) :: x
REAL(dp), DIMENSION(:), INTENT(IN) :: pars
REAL(dp), DIMENSION(:), INTENT(IN) :: y
REAL(dp), DIMENSION(:), INTENT(OUT) :: dydx
END SUBROUTINE der
END INTERFACE
hh = h*0.5d0
h6 = h/6.d0
xh = x + hh
yt(:)=y(:)+hh*dydx(:)
call der(xh, yt, dyt, pars,*10)
yt(:)=y(:)+hh*dyt(:)
call der(xh, yt, dym, pars,*10)
yt(:)=y(:)+h*dym(:)
dym(:)=dyt(:)+dym(:)
call der(x+h, yt, dyt, pars,*10)
yout(:)=y(:)+h6*(dydx(:)+dyt(:)+2.d0*dym(:))
return
10 return 1
end subroutine
subroutine adaptive_RK4(y,dydx,x,h,yout2,yerr,der,pars,*)
implicit none
integer, parameter :: dp=kind(1.d0)
REAL (dp) :: h, x
REAL (dp), DIMENSION (:) :: y, dydx, yout2, yerr, pars
REAL (dp), DIMENSION (size(y)) :: dydx2, yout1
intent(in) :: y, dydx, x, h, pars
intent(out) :: yout2, yerr
INTERFACE
SUBROUTINE der(x,y,dydx,pars,*)
IMPLICIT NONE
integer, parameter :: dp=kind(1.d0)
REAL(dp), INTENT(IN) :: x
REAL(dp), DIMENSION(:), INTENT(IN) :: pars
REAL(dp), DIMENSION(:), INTENT(IN) :: y
REAL(dp), DIMENSION(:), INTENT(OUT) :: dydx
END SUBROUTINE der
END INTERFACE
call rk4(y, dydx, x, h, yout1, der, pars,*10)
call rk4(y, dydx, x, h/2.d0, yout2, der, pars,*10)
call der(x+h/2.d0, yout2, dydx2, pars,*10)
call rk4(yout2, dydx2, x+h/2.d0, h/2.d0, yout2, der, pars,*10)
yerr(:)=yout2(:)-yout1(:)
yout2(:)=(16.d0*yout2(:)-yout1(:))/15.d0
return
10 return 1
end subroutine
end module
module derivative
implicit none
contains
SUBROUTINE derr(x,y,dydx,pars,*)
IMPLICIT NONE
integer, parameter :: dp=kind(1.d0)
REAL(dp), INTENT(IN) :: x
REAL(dp), DIMENSION(:), INTENT(IN) :: pars
REAL(dp), DIMENSION(:), INTENT(IN) :: y
REAL(dp), DIMENSION(:), INTENT(OUT) :: dydx
dydx=(pars+y)*x
return
END SUBROUTINE derr
end module
program test
use rk
use derivative
implicit none
integer, parameter :: dp=kind(1.d0)
real(dp), dimension(2) :: y,pars,dydx, yout, yerr
real(dp) :: x
y=(/0.1d0,2.d0/)
pars=(/0.7d0,3.d0/)
x=2.1d0
call derr(x,y,dydx,pars,*10)
write(*,*) dydx
call adaptive_RK4(y,dydx,x,0.0001d0,yout,yerr,derr,pars,*10)
stop
10 write(*,*) "some error"
end program
歡迎光臨。務必採取歡迎[遊覽]。針對所有Fortran問題使用標籤[tag:fortran]。您可以爲特定於版本的問題添加特定的版本標籤,但請注意,Fortran 90是舊的和過時的版本,通常您不希望受限於此。 –
請使用一些縮進(每行開始處的空格)。你的代碼很難閱讀。我們看不到結構。 –
而OMG停止使用備用返回功能(https:// stackoverflow。com/questions/7835270/asterisks-in-fortran-syntax-in-argument-list-at-1)現在,這是一種下地獄,相信我們的方式。 –