Hi Gennadi,
I think this is fixed in the latest version of the ncdf package, which you
can access by going to CRAN, then 'packages', then 'ncdf', and
clicking on
'URL'. Or here is a direct link:
http://cirrus.ucsd.edu/~pierce/ncdf
Give that a try and let me know if you still have a problem,
--Dave
Gennadi Lessin wrote:> I am trying to create a NetCDF file with bathymetry (a matrix) and then to
> add a grid type (an integer) as variables.
> This is the relevant part of the code:
>
> library(ncdf)
> wfile="my_file.nc"
> msv=-10
> grdtp=2
>
> # Dimensions
> d1=dim.def.ncdf("lon","degrees",as.double(lon))
> d2=dim.def.ncdf("lat","degrees",as.double(lat))
>
> # Variables
>
bathymetry=var.def.ncdf("bathymetry","m",list(d1,d2),msv,longname="Bathymetry")
>
> ncw=create.ncdf(writefile,list(bathymetry,loncp,latcp,dlonp,dlatp))
> put.var.ncdf(ncw,bathymetry,bat_matrix)
>
> close.ncdf(ncw)
>
> # Here I am trying to add another variable which should have a value of
> grdtp
>
> ncw_old=open.ncdf(wfile,write=TRUE)
> d3=dim.def.ncdf("grid_type",'',1:1,create_dimvar=FALSE)
>
grid_t=var.def.ncdf("grid_type","type",d3,1.e30,longname="Grid
Type")
> ncw_new=var.add.ncdf(ncw_old,grid_t)
>
> Here I stop because R gives an error message:
>
> Error in var.add.ncdf(ncw_old, grid_t) :
> Error in create.ncdf, defining var!
>
> Any ideas of what am I doing wrong?
> Thank you!
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
>
-------------------------------------------------------------------
David W. Pierce
Division of Climate, Atmospheric Science, and Physical Oceanography
Scripps Institution of Oceanography
(858) 534-8276 (voice) / (858) 534-8561 (fax) dpierce at ucsd.edu