function gb_plot_track(id,tstart,tstop,year)
% gb_plot_track(id,tstart,tstop,year) plots the tracks
% of drifters given in id for the time between tstart
% and tstop for the specified year with the daily 
% averaged wind stress added to the track.
% 4/2/01

% find number of drifters to be plotted
N=length(id);

%load data
load windstress9599
% filter and convert to 6-hr series like z
txy=subsamp(t,1,6);
txf=pl66tn(tx);
tyf=pl66tn(ty);
txf=subsamp(txf,1,6);
tyf=subsamp(tyf,1,6);
load gb10mallA

% convert to drifter days
tstart=yd2dd(tstart,year);
tstop=yd2dd(tstop,year);

% set up base map
clf
V=[-70 -65 39.75 43];
% V=[-68 -66 40.2 42.2]; % eventA
gbmapss2(V);
% mapax(30,0,30,0); % eventA
aspect5(41);
hold on

% start loop
for n=1:N
   
   % find specific drifter
   nn=find(z(:,8)==id(n));
   zz=z(nn,:);
   
   % find data inside map domain
   k=find_inside(zz,V);
   zz=zz(k,:);
   
   % find data for time window
   t=zz(:,1);
   err=0.005;
   I=find(tstart-err<=t & t<=tstop+err);
   t=zz(I,1);
   x=zz(I,2);x1=zz(max(I),2);
   y=zz(I,3);y1=zz(max(I),3);
   tmin=min(t);
   tmax=max(t);
   disp([tmin tmax])
   % plot drifter
   h=plot(x,y,'b',x1,y1,'r*');set(h,'linewidth',2);
   hold on

   % compute and plot daily wind stress
   K=find(tmin-err<=txy & txy<=tmax+err);
   txf=txf(K);
   tyf=tyf(K);
   txy=txy(K);
   % check time base
   % disp([min(t)   max(t);min(txy)  max(txy)])
      
   nn=[8:8:length(txy)-8]'; % 2-d average wind stress
   NN=length(nn);
   for jj=1:NN
      kk=nn(jj);
      xs1=x(kk);
      ys1=y(kk);
      KK=2;
      KXY=.755;
      nnn=[kk-4:1:kk+4]'; % 2-d average wind stress
      ys2=ys1+KK.*mean(tyf(nnn));
      xs2=xs1+KK.*mean(txf(nnn))./KXY;
      h=plot([xs1 xs2],[ys1 ys2],'k',xs1,ys1,'k.',xs2,ys2,'k*');set(h,'linewidth',1);
      hold on
   end
 
   % label drifter   
   text(x1,y1+.1,int2str(id(n)));
   % title([int2str(dd2yd(tstart)), ' - ',int2str(dd2yd(tstop))])
   title([dd2cd1(tstart),' - ',dd2cd1(tstop)])
   axis(V)
   hold on
   % plot wind stress scale
   xst1=-66.75;yst1=41.75;
   KK=2;
   KXY=.755;
   yst2=yst1;
   xst2=xst1+KK.*.2./KXY;
   h=plot([xst1 xst2],[yst1 yst2],'g',xst1,yst1,'g.',xst2,yst2,'g*');set(h,'linewidth',2);
   hold on
end


function cd=dd2cd1(dd)
% dd2cd(dd) converts drifter 
% day to calender day without year.
% 4/1/01
dd=dd(:);
gt=greg2(dd-1,1995);
y=int2str((gt(:,1)-1900));
m=int2str(gt(:,2));
d=int2str(gt(:,3));
cd=[m,'/',d];
  