
function [root] = rd_nc(fname);

root.info = ncinfo(fname);
for ii = 1:length(root.info.Variables)
	varname = root.info.Variables(ii).Name;
%	disp(sprintf('Reading %s',fullfile(fname,varname)));
	data = ncread(fname,['/' varname]);
	root.(varname) = data;
end

for ii = 1:length(root.info.Groups)
	group.name = root.info.Groups(ii).Name;
	group.info = ncinfo(fname,group.name);
	for vv = 1:length(group.info.Variables)
		varname = group.info.Variables(vv).Name;
%		disp(sprintf('Reading %s',fullfile(group.name,varname)));
		root.(group.name).(varname) = ncread(fname,['/' group.name '/' varname]);
	end
end


for ii = 1:length(root.info.Groups)
	if isfield(root.info.Groups(ii),'Groups')
		for jj = 1:length(root.info.Groups(ii).Groups)
			group.name = root.info.Groups(ii).Groups(jj).Name;
			group.info = ncinfo(fname,['/' root.info.Groups(ii).Name '/' group.name]);
			for vv = 1:length(group.info.Variables)
				varname = group.info.Variables(vv).Name;
%				disp(sprintf('Reading %s',fullfile(group.name,varname)));
				root.(root.info.Groups(ii).Name).(group.name).(varname) = ncread(fname,['/' root.info.Groups(ii).Name '/' group.name '/' varname]);
			end
		end
	end
end
