
% plottrajdisp - user mouse-clicks to define a box;
%	identify all drifters which passed through
% 	the box, and plot their subsequent history.

%plot(1,1,'.k','markersize',1);
%overlay;
%mapaxis([min(lon) max(lon) min(lat) max(lat)]);

disp('mouse-click twice to define a box')
[ibox,jbox]=ginput(2);

q=find(lon>min(ibox) & lon<max(ibox) & ...
	lat>min(jbox) & lat<max(jbox));
ID=unique(id(q));

plot(1,1,'.k','markersize',1);
hold on;
for i=1:length(ID);
  q=find(id==ID(i));
  lon2=lon(q);lat2=lat(q);
  del=(lon2-mean(ibox)).^2+(lat2-mean(jbox)).^2;
  del=find(del==min(del));
  % only plot if history is greater than one week
  if (length(del:4:length(lon2))>7)
    plot(lon2(del),lat2(del),'ok','markersize',4);
    plot(lon2(del:4:length(lon2)), ...
	lat2(del:4:length(lat2)));
    plot(last(lon2),last(lat2),'.k','markersize',8);
if id(q)==20348 keyboard; end;
  end;
end;
hold off;
overlay;
set(gca,'dataaspectratio',[1 1 1])

clear ibox jbox q ID lon2 lat2 del i
