I am writing a function in R to extract some air quality modelling data from netCDF files. I have the Package "ncdf" installed.
In order to allow other users or myself to choose what variables to extract from a netCDF file, I would like to extract the names of all variables in the file, so that I can present in a simple list rather than just print.ncdf()
the file to give too much information. Is there any way of doing it?
I tried unlist()
to the var
field of the ncdf object but it seemed that it returned the contents as well...
I googled and searched stack*overflow* but didn't seem to find an answer, so your help is very much appreciated.
Many thanks in advance.
If your ncdf object is called
nc
, then quite simply:With an example, using the dataset downloaded here, for instance (since you didn't provide with one):
It is now 2016. ncdf package is deprecated. Same code as SE user plannapus' answer is now:
A note from the documentation:
A note from the home page of the maintainer:
http://cirrus.ucsd.edu/~pierce/ncdf/