我正在使用cdi(气候数据接口,https://code.zmaw.de/projects/cdi/wiki)来创建netcdf文件。我在文档中做了一个例子来编写一个netcdf文件,它运行正常。但是当第一次使用cdi时,它不会创建时间轴。 见代码:
! Now, we create the output file.
! We first create the grid.
gridID = gridCreate(y3D%GridType, NLons * NLats)
CALL gridDefXsize(gridID, NLons)
CALL gridDefYsize(gridID, NLats)
CALL gridDefXvals(gridID, y3D%Lons)
CALL gridDefYvals(gridID, y3D%Lats)
! Now, the z axis to be attached to the variable when created (there is one z axis per variable).
zaxisID = zaxisCreate(y3D%ZAxisType, 1) ! We only support predictands with one level. 1 creates a surface level.
! Now create the variable list
vlistID = vlistCreate()
! And define the variables in the variable list
Prevision = vlistDefVar(vlistID, gridID, zaxisID, TIME_VARIABLE)
! Now define the variable names
CALL vlistDefVarName(vlistID, Prevision , "Prevision")
! Now the time axis and attach it to the variable list.
taxisID = taxisCreate(TAXIS_RELATIVE) !ABSOLUTE)
write (*,*) "taxisID: ", taxisID
CALL taxisDefRDate(taxisID, 19000101)
CALL vlistDefTaxis(vlistID, taxisID)
! Now create the file
streamID = streamOpenWrite(char(ResultsFile), OutType)
if ( streamID < 0 ) then
write (*,*) "ERROR while attempting to create the file ", char(ResultsFile), " to store the results."
write (*,*) cdiStringError(streamID)
stop
end if
! Assign the variable list to the dataset
CALL streamDefVlist(streamID, vlistID)
! Now we have to loop over the time steps to store the data.
DO tsID = 0, NDates - 1
! Set the verification date
write (*,*) "Date ", ar_DatesPredicted(tsID+1)
CALL taxisDefVdate(taxisID, ar_DatesPredicted(tsID+1))
! Set the verification time to 12:00:00
CALL taxisDefVtime(taxisID, 120000)
! Define the time step
status = streamDefTimestep(streamID, tsID)
write (*,*) "Number of records of the time step: ", status
! Write values of each variable
CALL streamWriteVar(streamID, Prevision, ar_y_2DPrev(tsID+1, c_predictands)%Values, NMiss)
END DO
! Close the output stream
CALL streamClose(streamID)
! Destroy the objects
CALL vlistDestroy(vlistID)
CALL taxisDestroy(taxisID)
CALL zaxisDestroy(zaxisID)
CALL gridDestroy(gridID)
答案 0 :(得分:0)
解决:
这个问题的原因是我安装了两个版本的cdi库。 一个是使用系统包管理器安装的,另一个是在我的主目录中手动安装的。 我链接第一个构建一些对象,并与另一个链接以构建其他对象。 一旦在任何地方使用相同版本,问题就会消失。
所以这是一般规则:不要混合同一个库的不同版本来链接。
感谢所有试图帮助我的人。