function [nstruct] = structtrunc(ostruct,indx)
% 
% truncate ALL fields that are not singletons, based on indx
%
fno=fieldnames(ostruct);
lenv=ones(length(fno),1);
for i=1:length(fno),
  eval(['lenv(' num2str(i) ')= length(ostruct.' fno{i} ');' ])
end

nstruct=[];
for i=1:length(fno)
    field_name=fno{i};
    if lenv(i) > 1,
       cmd=['nstruct.' field_name ' =  ostruct.' field_name '(indx);'];
      % disp(['structtrunc; cmd ' cmd]);
       eval(cmd);
    else
       % disp([ 'skipping ' fno{i}])
       cmd=['nstruct.' field_name ' =  ostruct.' field_name ';'];
      % disp(['structtrunc; cmd ' cmd]);
       eval(cmd);
    end
end
