function unew=clean(u);
%function unew=clean(u);
%                           linear interpolation to fill isolated points 
%                           with NaN
%                           badseg is an index array of groups of bad pts.
bad=find(u==NaN);
if length(bad)>0
  badpoints=length(bad)
  if bad(1)==1 
        bad(1)=[];
  end
  if length(bad)>0
     if bad(length(bad))==length(u) 
         bad(length(bad))=[];
      end

      u(bad)=(u(bad-1)+u(bad+1))/2;
   end
end
unew=u;
