readnetcdf.m
author A.M. Thurnherr <ant@ldeo.columbia.edu>
Mon, 12 Oct 2009 22:13:35 -0400
changeset 0 40938dd7a1f1
permissions -rw-r--r--
created with ANTS 4.0

function prof = readnetcdf(filename)

% Usage: prof = readnetcdf(filename)
%
% Read variables from a netCDF file.

ncid = netcdf.open(filename, 'NOWRITE');

% get variables
[ndims,nvars,natts,unlimdimid] = netcdf.inq(ncid);

for varid=0:nvars-1
	[varname,xtype,dimids,nvaratts] = netcdf.inqVar(ncid,varid);
	cmd = sprintf('prof.%s = netcdf.getVar(ncid,varid);',varname);
	eval(cmd);
end

gattvarid = netcdf.getConstant('NC_GLOBAL');
for gattid=0:natts-1
	attname = netcdf.inqAttName(ncid,gattvarid,gattid);
	cmd = sprintf('prof.%s = netcdf.getAtt(ncid,gattvarid,''%s'');',attname,attname);
	eval(cmd);
end

netcdf.close(ncid)