The objective is that I want to output in NetCDF format a scalar variable, for example, total kinetic energy, time stamp, or surface pressure at a certain location, at each time step in a numerical model. The time step needs to be an unlimited dimension. I encountered similar issues described here, however, it does not fully solve my problem. The ifort compiler shows an error message says:
There is no matching specific function for this generic function reference. [NF90_PUT_VAR].
The code outputing time stamp and has the error mainly looks like
status = nf90_create(path = "history.nc", cmode = nf90_clobber,&
ncid = history_fileid)
status = nf90_def_dim(history_fileid, "time_step", nf90_unlimited, time_dimid)
status = nf90_def_var(history_fileid, "write_time", nf90_double, &
(/time_dimid/), t_varid)
status = nf90_enddef(history_fileid)
status = nf90_put_var(history_fileid, t_varid, time, start = framenum_netcdf, count = 1 )
The compile environment is ifort 11.1.073, netcdf 4.01, and hdf5/1.8.6.
There are two errors in the above code marked by red and green. The green error is documented in the link above and we begin with it. Basically, nf90_put_var is an overloaded function that looks like
interface nf90_put_var
module procedure nf90_put_var_text, &
nf90_put_var_OneByteInt, nf90_put_var_TwoByteInt, &
nf90_put_var_FourByteInt, nf90_put_var_EightByteInt, &
nf90_put_var_FourByteReal, nf90_put_var_EightByteReal
module procedure nf90_put_var_1D_text, &
nf90_put_var_1D_OneByteInt, nf90_put_var_1D_TwoByteInt, &
nf90_put_var_1D_FourByteInt, nf90_put_var_1D_EightByteInt, &
nf90_put_var_1D_FourByteReal, nf90_put_var_1D_EightByteReal
module procedure nf90_put_var_2D_text, &
nf90_put_var_2D_OneByteInt, nf90_put_var_2D_TwoByteInt, &
nf90_put_var_2D_FourByteInt, nf90_put_var_2D_EightByteInt, &
nf90_put_var_2D_FourByteReal, nf90_put_var_2D_EightByteReal
What we need is actually nf90_put_var_1D_EightByteReal
, and this function does not have an optional parameter count
. This is because there is no need for it as count
should always be 1 for a 1d array. The interface for nf90_put_var_1D_EightByteReal
is
function nf90_put_var_EightByteReal(ncid, varid, values, start)
integer, intent( in) :: ncid, varid
real (kind = EightByteReal), intent( in) :: values
integer, dimension(:), optional, intent( in) :: start
integer :: nf90_put_var_EightByteReal
integer, dimension(nf90_max_var_dims) :: localIndex integer :: counter
The other problem is more tricky and maybe compiler dependent as the link above does not encounter this problem. I still has the same error after eliminating count
. The problem is that start
is an array instead of a scalar. “Procedure calling in Fortran with explicit interfaces (which you get automatically when using module procedures) requires a TKR (type, kind, rank) match. As an array is a different type than a scalar, not to mention the rank mismatch, this is not allowed.” To solve the problem, the last line of code needs to be
status = nf90_put_var(history_fileid, t_varid, time, start = (/framenum_netcdf/) )