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

Matthew Fearon Matthew.Fearon at dri.edu
Wed Aug 26 00:51:27 MDT 2015


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/2298402c/attachment.html 


More information about the ncl-talk mailing list