% plottraj - plot all drifter trajectories
% loaded into memory.

plotdeply=0;    % set to 1 to include deployment locations
bigvel=.5;  % "fast" speeds (m/s)
if (plotdeply)  % black and white for fast/slow
    slowcol=[.6 .6 .6]; % color of "slow" trajectories
    fastcol=[0 0 0]; % color of "fast" trajectories
else % color for fast/slow
    slowcol=[.7 .7 1];
    fastcol=[1 0 0];
end;

subs=2; % subsample trajectories at this time step (days)

deltt=median(diff(t(1:1000)));
vel=sqrt(u.^2+v.^2);
q=find(vel>=bigvel);
id(q)=id(q)+.01;

q=find(diff(id) | abs(diff(lon))>10 | diff(t)>10);
q=[0;q;length(id)];
plot(lon(1),lat(1),'.k','markersize',1);
overlay;
hold on;
% plot trajectories
for i=2:length(q);
    a=q(i-1)+1:q(i);
    if (deltt<subs)
        ind=1:round(subs/deltt):length(a);
    else
        ind=1:length(a);
    end;
    mvel=nanmean(vel(a));
    if (mvel<bigvel | isnan(mvel))
        col=slowcol;
    else
        col=fastcol;
    end;
    plot(lon(a(ind)),lat(a(ind)),'color',col);
end;
if (plotdeply)
    plotdeploy
end;
hold off;

q=find(vel>=bigvel);
id(q)=id(q)-.01;

clear q a i deltt plotdeply ans subs vel bigvel
clear slowcol fastcol col mvel
