% Spdfil.m    speed filter
% (Really spdfilnf.m, but consistency on CD required)

%set global variables
  %global lat lon emat trandist deltapos bottom xint yint
 global lat lon emat trandist deltapos bottom xint yint depthint mindepth maxdepth left step ic tflag mflag moc filename

dither=100; %gps diter of 100 m
reprate=1; % acoustic data acquisition interval in seconds
speed = 10;   % ships speed in knots along transect
spdthresh=(speed*1852/3600)*reprate+dither;
deltapos=zeros(size(trandist));
deltapos(2:length(trandist))=trandist(2:length(trandist))-trandist(1:length(trandist)-1);
for nn=1:length(trandist);
   if deltapos(nn)~= nan
      if deltapos(nn) > spdthresh
         pointer=nn;
         if deltapos(nn-1)~=nan
            lat(pointer)=lat(pointer-1);
            lon(pointer)=lon(pointer-1);
         end
      end
   end
end
%length(lat)
%length(lon)
%pause
clear dither reprate speed spdthresh pointer
