function attr=nj_attget(uri,var) % NJ_ATTGET get attributes for NetCDF file, NetCDF URL or OpenDAP URL % Usage: attr=nj_attget(file,var); % where: ncfile = local file name or a URL % var = variable % % [attr]= nj_attget(uri); % Returns only 'global' attributes associated with the netcdf % file. % [attr]=nj_attget(uri,'temp'); % get attributes for % variable 'temp', as well as global attributes associated with % the nc file. % attr.var = variable attributes % attr.global = global attributes % % % skbhate@ngi.msstate.edu % % import the NetCDF-Java methods import msstate.cstm.data.JDataset import msstate.cstm.data.grid.JGeoGridDataset if nargin < 1 disp('Check input arguments!') help nj_attget return end try % open CF-compliant NetCDF File as a Common Data Model (CDM) "Grid Dataset" GridData = JDataset(uri); %associated geo grid gds = GridData.getGridDataset(); switch nargin case 1 globalattr=gds.getGlobalAttributes().toArray(); attr = globalattr; case 2 GeoGridData = JGeoGridDataset(gds,var); globalattr = gds.getGlobalAttributes().toArray(); varattr = GeoGridData.getGeoGrid.getAttributes().toArray(); % variable attributes attr.global = globalattr; attr.var = varattr; otherwise, error('MATLAB:cf_attget:Nargin',... 'Incorrect number of arguments'); end %cleanup GridData.close(); catch %gets the last error generated err = lasterror(); disp(err.message); end