[ncl-talk] appending to an existing netcdf file with an unlimited time dimension
Matthew Fearon
Matthew.Fearon at dri.edu
Wed Aug 26 01:58:44 MDT 2015
I solved this by using an expected dimsize for time but keeping dimunlim=True, and now I can data incrementally up until time dimsize is reached. But I'm not sure if this the best approach.
; create with unlimited time
nt=3000 ; expected size, but can add incrementally until that point
outncdf = addfile(_outpath+varname+".nc" ,"c")
dimNames = (/"time","south_north","west_east"/)
dimSizes = (/ nt, ny, nx /)
dimUnlim = (/ True, False, False /)
filedimdef(outncdf,dimNames,dimSizes,dimUnlim)
filevardef(outncdf, "DateTime", "integer", getvardims(datetime))
filevarattdef(outncdf, "DateTime", datetime)
filevardef(outncdf, varname, "float", dimNames)
filevarattdef(outncdf, varname, var)
outncdf->DateTime=(/datetime/)
outncdf->$varname$=(/var/)
; first 10 timesteps above were added with create, now add 10 more with write
outncdf = addfile(_outpath+varname+".nc" ,"w")
tcount=10
ntstep=20
outncdf->DateTime(time|tcount:(tcount+ntstep)-1)=(/datetime/)
outncdf->$varname$(time|tcount:(tcount+ntstep)-1,south_north|:,west_east|:)=(/var/)
________________________________
From: ncl-talk-bounces at ucar.edu [ncl-talk-bounces at ucar.edu] on behalf of Matthew Fearon [Matthew.Fearon at dri.edu]
Sent: Tuesday, August 25, 2015 11:51 PM
To: ncl-talk at ucar.edu
Subject: [ncl-talk] appending to an existing netcdf file with an unlimited time dimension
Dear NCL users:
I have been able to append to an existing netcdf file before easily with an unlimited time dimension. However, something has changed as my old scripts no longer work. I have tried so many combinations unsuccessfully. This seems more difficult than it needs to be. So I create the netcdf file with (time, lat, lon) with time unlimited, add variables -- this works fine. However, if I want to append an additional time step or several at once -- no dice. Below is a snip of my code. Note the if condition is the initial create, and else condition is the append which fails.
thanks for the help,
Matt
if (it.eq.0) then
outncdf = addfile(_outpath+varname+".nc" ,"c")
dimNames = (/"time","south_north","west_east"/)
dimSizes = (/ -1, ny, nx /)
dimUnlim = (/ True, False, False /)
filedimdef(outncdf,dimNames,dimSizes,dimUnlim)
filevardef(outncdf, "DateTime", "integer", getvardims(datetime))
filevarattdef(outncdf, "DateTime", datetime)
filevardef(outncdf, varname, "float", dimNames)
filevarattdef(outncdf, varname, var)
filevardef(outncdf, "lat", "float", getvardims(latm2d))
filevarattdef(outncdf, "lat", latm2d)
filevardef(outncdf, "lon", "float", getvardims(lonm2d))
filevarattdef(outncdf, "lon", lonm2d)
outncdf->DateTime=(/datetime/)
outncdf->$varname$=(/var/)
outncdf->lat=(/latm2d/)
outncdf->lon=(/lonm2d/)
else
outncdf = addfile(_outpath+varname+".nc" ,"w")
outncdf->time(tcount:) = datetime
;outncdf->DateTime(time|tcount:)=(/datetime/)
;outncdf->$varname$(time|tcount:,south_north|:,west_east|:)=(/var/)
outncdf->DateTime(tcount:)=(/datetime/)
outncdf->$varname$(tcount:,:,:)=(/var/)
end if
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20150826/4f4cd58f/attachment.html
More information about the ncl-talk
mailing list