function dd= nx1ref(data,  nx1_names, nxm_names, refbins)
% dd= getref(data,  nx1_names, nxm_names, refbins)
% make a structure with Nx1 vectors 
% nx1_names is a cellarray with the list of  Nx1 fields from data
% nxm_names is a cellarray with the list of  NxM fields from data, and
%      refbins is the reference layer to use

dd.bins = refbins;

for ii=1:length(nx1_names)
   fname = nx1_names{ii};
   tempdata = getfield(data, fname);
   dd = setfield(dd, fname, tempdata');
end

for ii=1:length(nxm_names)
   fname = nxm_names{ii};
   tempdata = getfield(data, fname);

   if (length(refbins) > 1)
      refdata = mstdgap(tempdata(refbins,:));
   else
      refdata = tempdata(refbins,:);
   end
   dd = setfield(dd, fname, refdata');
end
