outm_netcdf.F:154:48:
135 | status=nf_def_var(ncid,'longitude',nf_real,1,nlon1id,nlongit1id)
| 2
......
154 | status=nf_def_var(ncid,'temp',nf_double,3,dim1pass,
| 1
Error: Rank mismatch between actual argument at (1) and actual argument at (2) (scalar and rank-1)
以上是程序出错的部分,154:48位置的参数是dim1pass,dim1pass定义代码如下:
dim1pass(1)=nlon1id
dim1pass(2)=nlat1id
dim1pass(3)=ndep1id
nlon1id定义如下:
integer nlon1id,nlongit1id,ndep1id,nlat1id,nlatit1id,ndepth1id
integer nrecsid,ioffsetid
nf_def_var定义如下:
integer nf_def_var
! (integer ncid,
! character(*) name,
! integer datatype,
! integer ndims,
! integer dimids(1),
! integer varid)
external nf_def_var
我也遇到了类似的问题,作为Fortran小白的我,看了好多资料,敲了n多次代码,终于搞定了。希望我的方法可以解决你的问题。
你可以尝试下以下两种方法:
方法1. 使用gfortan编译时,加入-fallow-argument-mismatch 参数解决 Rank mismath 编译错误。 如下:gfortran -g -fallow-argument-mismatch ReadAndWriteNC.f90 -I/usr/local/include -L/usr/local/bin -lnetcdf -o test
方法2. 在你的代码中进行修改。使用 dim1pass(1) 替换 135 行中 status=nf_def_var(ncid,'longitude',nf_real,1,nlon1id,nlongit1id) 的nlon1id。同理使用dim1pass(2) 替换nlat1id;dim1pass(3)替换ndep1id等
造成这种问题出现的原因,可能与F77和F90参数传递时的要求不一样有关。低版本的编译器中对参数要求较低,但在高版本的编译器中,你传递的参数类型不一致时编译器会报错。我自己理解的,不对之处,希望大神批评指正!