[ncl-talk] appending to an existing netcdf file with an unlimited time dimension
Wei Huang
whuang at univ-wea.com
Wed Aug 26 07:18:23 MDT 2015
Matt,
You may want to check: http://www.ncl.ucar.edu/Applications/write_nc4_1dUnlimited.shtml
Even it said for NC4, but with 1 unlimited dimensions, it should apply to NC3 as well.
Wei Huang
From: ncl-talk-bounces at ucar.edu [mailto:ncl-talk-bounces at ucar.edu] On Behalf Of Wei Huang
Sent: Wednesday, August 26, 2015 8:16 AM
To: Matthew Fearon; ncl-talk at ucar.edu
Subject: Re: [ncl-talk] appending to an existing netcdf file with an unlimited time dimension
Matt,
Try change you write:
outncdf->$varname$(tcount:,:,:)=(/var/)
to something with a fixed ending index, like:
outncdf->$varname$(tcount:tend,:,:)=(/var/)
As when you write data, it needs to know where to end,
As you have declared it unlimited.
Wei Huang
From: ncl-talk-bounces at ucar.edu<mailto:ncl-talk-bounces at ucar.edu> [mailto:ncl-talk-bounces at ucar.edu] On Behalf Of Matthew Fearon
Sent: Wednesday, August 26, 2015 1:51 AM
To: ncl-talk at ucar.edu<mailto: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/9a390081/attachment.html
More information about the ncl-talk
mailing list