[ncl-talk] appending to an existing netcdf file with an unlimited time dimension

Wei Huang whuang at univ-wea.com
Wed Aug 26 07:15:45 MDT 2015


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] On Behalf Of Matthew Fearon
Sent: Wednesday, August 26, 2015 1:51 AM
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/148c4752/attachment.html 


More information about the ncl-talk mailing list