function [nstruct] = structtruncnosings(ostruct)
% truncate ALL fields to shortest field
% don't acall this if there are singletons!!!!


fno=fieldnames(ostruct);
lenv=ones(length(fno),1);
for i=1:length(fno),
  eval(['lenv(' num2str(i) ')= length(ostruct.' fno{i} ');' ])
end
lenv2=lenv;
lenv2(find(lenv == 1))= max(lenv);
minlen=min(lenv2);
nstruct=[];
for i=1:length(fno)
    field_name=fno{i};
    if lenv(i) > 1,
       cmd=['nstruct.' field_name ' =  ostruct.' field_name '(1:' num2str(minlen) ');'];
      % 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
