Dear List, does anybody has experience with the RNetCDF package? I manage to open a connection and copy data from a ncdf file but would need a way to automatically retrieve variable names (ideally all of them from one file) and units from the file. Any ideas? Jannis
Hi Jannis, although I don't know how you'd do that with RNetCDF, with the ncdf package it's pretty easy: ncid = open.ncdf( 'file.nc' ) nvars = ncid$nvars for( ivar in 1:nvars ) print(paste("var number",ivar,"is named", ncid$var[[ivar]]$name, "and has units", ncid$var[[ivar]]$units )) Regards, --Dave Jannis wrote:> Dear List, > > > does anybody has experience with the RNetCDF package? I manage to open a > connection and copy data from a ncdf file but would need a way to > automatically retrieve variable names (ideally all of them from one file) > and units from the file. > > > Any ideas? > Jannis > > > > ______________________________________________ > 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
There are a number of functions in the package to inquire about the file contents. See library(help = RNetCDF). For example: library(RNetCDF) nc <- open.nc("file.nc") var.inq.nc(nc, 0) $id [1] 0 $name [1] "longitude_U" $type [1] "NC_DOUBLE" $ndims [1] 1 $dimids [1] 1 $natts [1] 0 You can then read from the file with something like this: obj0 <- var.inq.nc(nc, 0) dat <- var.get.nc(nc, obj0$name, start = ...) Going with ncdf or ncdf4 package is probably better ( I just happen to be more familiar with RNetCDF.) Cheers, Mike. On Thu, Jan 13, 2011 at 9:00 AM, Jannis <bt_jannis at yahoo.de> wrote:> Dear List, > > > does anybody has experience with the RNetCDF package? I manage to open a connection and copy data from a ncdf file but would need a way to automatically retrieve variable names (ideally all of them from one file) and units from the file. > > > Any ideas? > Jannis > > > > ______________________________________________ > 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. >-- Michael Sumner Institute for Marine and Antarctic Studies, University of Tasmania Hobart, Australia e-mail: mdsumner at gmail.com