function [out]=my_smooth(in);
% my_smooth.m - smooth CTD spikes

out=in;

npts = 25;
jj=1;

for ii = 1:length(in)-npts
  ind = [jj:jj+npts];
  mm=mean(in(ind));
  ss=std(in(ind));
  aa=find(in(ind) > mm+4*ss | in(ind) < mm-4*ss);
  if ~isempty(aa)
    subplot(2,1,1)
    plot(1:length(in),in,ind,in(ind))
    keyboard
    % fix by hand using this
    if 0
      % three points (ahead):
      new=interp1([1 5],[in(ind(end-3)) in(ind(end)+2)],[2 3 4])
      out(ind(end-1):ind(end)+1) = new;
      % (one behind three ahead):
      new=interp1([1 5],[in(ind(end-1)) in(ind(end)+3)],[2 3 4])
      out(ind(end):ind(end)+2) = new;
      % (one behind two ahead):
      new=interp1([1 4],[in(ind(end-1)) in(ind(end)+2)],[2 3 ])
      out(ind(end):ind(end)+1) = new;
      % (one behind five ahead):
      new=interp1([1 7],[in(ind(end-1)) in(ind(end)+5)],[2:6])
      out(ind(end-1):ind(end)+3) = new;
      % (one behind six ahead):
      new=interp1([1 8],[in(ind(end-1)) in(ind(end)+6)],[2:7])
      out(ind(end-1):ind(end)+4) = new;
      % (two behind one ahead):
      new=interp1([1 5],[in(ind(end-2)) in(ind(end)+1)],[2:4])
      out(ind(end-1):ind(end)+1) = new;
      % (two behind three ahead):
      new=interp1([1 6],[in(ind(end-2)) in(ind(end)+3)],[2:5])
      out(ind(end-1):ind(end)+2) = new;
      % one point (end -1):
      new=interp1([1 3],[in(ind(end-3)) in(ind(end)-1)],[2])
      out(ind(end-2)) = new;
      % one up and one down (behind):
      new=interp1([1 4],[in(ind(1)-2) in(ind(2))],[2 3])
      out(ind(1)-1:ind(1)) = new;
      % two behind and two ahead (beginning):
      new=interp1([1 5],[in(ind(1)-2) in(ind(3))],[2 3 4])
      out(ind(1)-1:ind(2)) = new;
      % right in the middle (all of em)
      new=interp1([1 25],[in(ind(1)) in(ind(end))],[2:24])
      out(ind(2:24)) = new;     
      % single up
      new=interp1([1 3],[in(ind(end)-1) in(ind(end)+1)],[2])
      out(ind(end)) = new;
      % single up(back)
      new=interp1([1 3],[in(ind(end)-2) in(ind(end))],[2])
      out(ind(end-1)) = new;
     % one up and one down (ahead):
      new=interp1([1 4],[in(ind(end-1)) in(ind(end)+2)],[2 3])
      out(ind(end):ind(end)+1) = new;
 
      subplot(2,1,2)     
      plot(1:length(in),out,ind,out(ind))
      
      in=out;
      
    end
  end
  jj=jj+1
end
