Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there a way to return list of variables in netcdf? #181

Open
alex-s-gardner opened this issue Aug 2, 2023 · 1 comment
Open

Is there a way to return list of variables in netcdf? #181

alex-s-gardner opened this issue Aug 2, 2023 · 1 comment

Comments

@alex-s-gardner
Copy link

I have a netcdf file and I want to programmatically determine the list of variables contained in the file. The only utility I could identify is NetCDF.info but it just prints a bunch of info to screen.

@meggart
Copy link
Member

meggart commented Aug 4, 2023

The NcFile type returned by NetCDF.open contains a dict holding paris of variable names and NcVar diskarrays. You can extract the variable names as follow:

nc = NetCDF.open(p)
varnames = keys(nc.vars)

This will include all variables including dimension variables. Also, if you want to make sure the NetCDF file gets immediately closed after the query and not only when gc is triggered you can use the do-syntax. So the following would return all variable names that are not a dimension name at the same time and make sure the file is immediately closed again.

NetCDF.open(p) do nc
    setdiff(keys(nc.vars),keys(nc.dim))
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants