function [varlist, gattrlist] = netcdf_listvars(file) % function [varlist, gattrlist] = netcdf_listvars(file) % % simple 'convenience' function to grab the list of variables % inside a NetCDF file. Returns a cell array of strings. % optionally, get a list of the global attribute names as the % second output. This will also be a cell array of strings. % % Note, this function is simple, so no error checking is done % ncID = netcdf.open(file, 'NC_NOWRITE'); [ndims, nvars, ngattrs] = netcdf.inq(ncID); varlist = cell(nvars,1); for n=1:nvars; varlist{n} = netcdf.inqVar(ncID, n-1); end if nargout == 2; gattrlist = cell(ngattrs,1); globalID = netcdf.getConstant('NC_GLOBAL'); for n=1:ngattrs; gattrlist{n} = ... netcdf.inqAttName(ncID, globalID, n-1); end end netcdf.close(ncID);