我想端口一段代碼的Fortran 77到Fortran 90的,我有關於Fortran 77中追趕排名不匹配參數等級不匹配的沒有報告
這是一個問題在Fortran 90的
program test
use my_module
real ml_time
call gettimes(cdfid,ml_time,ml_ntimes)
代碼在調用子例程,這是通過可變如何定義
module my_module
use netcdf
subroutine gettimes(cdfid,times,ntimes)
real times(*)
call check(nf90_inq_dimid(cdfid,'time', timid))
call check(nf90_inquire_dimension(cdfid, timid, len = ntimes))
call check(nf90_inq_varid(cdfid,'time',timid))
call check(nf90_get_var(cdfid,timid,times(1:ntimes)))
end subroutine gettimes
在Fortran 77的(.f文件)和gfortran 5.4爲什麼這個無會產生編譯錯誤?
將代碼移植到Fortran 90時出現相同的代碼會產生排名不匹配的編譯錯誤。
這是在Fortran 77的Fortran 90中
add2p.f90:191:22:
call gettimes(cdfid,ml_time,ml_ntimes)
1
Error: Rank mismatch in argument ‘times’ at (1) (rank-1 and scalar)
錯誤這是代碼是如何組織的
program test
real ml_time
call gettimes(cdfid,ml_time,ml_ntimes)
在另一個文件xyz.f
subroutine gettimes(cdfid,times,ntimes,ierr)
include "netcdf.inc"
integer ierr,i
real times(*)
integer didtim,ntimes
integer cdfid,idtime
do 10 i=1,ntimes
call ncvgt1(cdfid,idtime,i,times(i)) ! get times
10 continue
end
當然我擺脫了錯誤,使他們相同的排名,但我想知道爲什麼在Fortran 77中沒有報告編譯器錯誤。
請顯示在Fortran 90中生成的錯誤以及一些合理的*完整*代碼示例[mcve]。 –
整個結構是需要的,不僅僅是子程序,看到我的答案爲什麼。 –
@VladimirF - 我做出了可接受的更改嗎? – gansub