%
function drifters3(nint,t_start)
% draw 3d drifter position 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%  NINT is time sampling interval,
%  which means each nint time step will be drown  
%  t_start - starting day of the run (JD)
%  HANDWORK: 1)set path (line 33); 2)title (line 77),
%  3)axis (line 70). 
%  how to call (example): call as: DRIFTERS3(3,120)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% DEFINE ERROR STRINGS
err1=['Not enough input arguments; need parameters "init" & "t_start"'];
err2=['Too many input arguments;'];
err3=['Not enough input arguments; need 2 parameters: "init" & "t_start"'];
       
% check arguments
if nargin ==0 
   error(err1);
elseif nargin >2
   error(err2);
elseif nargin==1
   error(err3);
end
% load grid  
   bn=loadgrid('bank150');
% create a new grid structure (geographycal coordinate)   
   bb=bn;
   [bb.y,bb.x]=xy2ll(bb.x,bb.y);
   gridname='bank150';
% set path
   PTHFILE=['/whoinet/putnam/p2/globec/fcast_archives/FCAST_1.1B1/EN323_clim.06/CRUISE_Q4.1/DRIFTERS'];
% load data from PTH file
   [gridname,ndrog,ndts,tsec,pth]=read_pth(PTHFILE,4);
   size(pth);
   ndts=ans(1)/ndrog;
   xdr=pth(:,1);
   xdr=reshape(xdr,ndrog,ndts);
   xdr=xdr';

   ydr=pth(:,2);
   ydr=reshape(ydr,ndrog,ndts);
   ydr=ydr';
   zdr=pth(:,3);
   zdr=reshape(zdr,ndrog,ndts);
   zdr=zdr';

   tdr=pth(:,4);
   tdr=reshape(tdr,ndrog,ndts);
   tdr=tdr';
% convert data to geographycal coordinates
   [y,x]=xy2ll(xdr,ydr);
   clear pth
   clear xdr
   clf
% set limits for drifter depth (or, can do it manually) 
   minz=min(zdr(:));
   maxz=max(zdr(:));

drawnow
% find  time  when drifters started to move
   ff=find(ydr(:,1)~=ydr(1,1));
   s=ff(1)-1;
% do frames
   for k=[s:nint:ndts] 

hp = plot3(x(k,:),y(k,:),zdr(k,:),'.b','Markersize',15);
hold on 
axis([-68 -67. 40.8 41.6 minz maxz]);
tt=t_start+(tdr(k,1))/86400;
hx=xlabel('Longitude','FontWeight','bold','FontSize',12);
set(hx,'rotation',17);
hy=ylabel('Latitude','FontWeight','bold','FontSize',12);
set(hy,'rotation',-28);
hz=zlabel('Depth, m','FontWeight','bold','FontSize',12);
title('FC run EN323 FC17/CRUISE Q4.3','FontWeight','bold','FontSize',14);
hz=text(-66.8,41.3,-5,['time=' num2str(tt) ' ']); 
hold off
grid on 
 set(hz,'color','b','Fontsize',14,'Fontweight','bold');  
j=sprintf('pth%i', k ); 
eval(['print ' j '.ppm -dppm']);
delete(hp); 
delete(hz); 
end
return
%        written by
%        Valery K. Kosnyrev
%        WHOI
