%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


%
% Load model results
%

runid = 'EN323_FC.03'
tstart =[123.0];

PTHFILE=['../fcast_archives/FCAST_1.1B1/',runid,'/CRUISE_Q4.1/DRIFTERS']

[gridname,ndrog,ndts,tsec,pth]=read_pth(PTHFILE,4);

b=loadgrid('../MESH/bank150');
[la,lo]=xy2ll(b.x,b.y);
b.x=lo;b.y=la;

[gridname,ndrog,ndts,tsec,pth]=read_pth(PTHFILE,4);
%Convert to lo/la
[la,lo]=xy2ll(pth(:,1),pth(:,2));
pth(:,1)=lo;pth(:,2)=la;

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';

figure
hb=plotbnd(b);
axis('tight')
set(hb,'LineWidth',2)

hold on

for idr=1:ndrog
  hp = plot(xdr(:,idr),ydr(:,idr),'b-');
end

title([runid,' Drifter Trajectories'])
hc=lcontour(b,'z',[30 45 60 75 90 120]);
grid

hold off

%
% Individual drifter plot
%

idrog=13;

titlestr=([runid,' drifter no. ',num2str(idrog)]);

lons=pth(idrog:ndrog:length(pth),1);
lats=pth(idrog:ndrog:length(pth),2);
timesec=pth(idrog:ndrog:length(pth),4);
idx=find(diff(lons)~=0);
istart=[idx(1)];
idx=istart:length(lons);
lons=lons(idx);
lats=lats(idx);
timesec=timesec(idx)-timesec(idx(1));

figure
hb=plotbnd(b);
axis('tight')
set(hb,'LineWidth',2)
hc=lcontour(b,'z',[30 45 60 75 90 120]);
set(hc,'LineWidth',.25)
h=plotdrog(pth(:,1),pth(:,2),ndrog,{idrog},{idrog});
set(h,'Color','g','Marker','s','MarkerSize',8,'LineStyle','none')
h=plotdrog(pth(:,1),pth(:,2),ndrog,{ndts},{idrog});
set(h,'Color','r','Marker','.','MarkerSize',18,'LineStyle','none')
h=plotdrog(pth(:,1),pth(:,2),ndrog,1,{idrog});
set(h,'Color','k')
title(titlestr,'FontSize',17)
set(gcf,'Number','off')
% axis([-67.538 -67.2328  40.951  41.199])

%     JD SHIFT   UCT SHIFT TO EDT
%   |     |
%         \/     \/
%        yr  m d      h  m    s
% DJM
% add 1 to tstart to make gmt 0.5  Jan 1, 1999
% subtract 4 hrs to convert from UTC to EST (local time)
dates=datenum(1999,1,tstart+1,-4,0,timesec);
mtrack(lons,lats,dates,'ticks',60,'times',60*4,'dates',12,'color','k',...
'fontsize',11,'fontweight','bold','FontName','helvetica','LineWidth',2);

grid
