% This script is hard-wired for J Manning's
% Apr EL9904 c1 drifter deployment.

% Load and convert all data to projection coords.
b=loadgrid('MESH/bank150');
[la,lo]=xy2ll(b.x,b.y);
b.x=lo;b.y=la;

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

P=read_pth(PTHFILE,4); %****BOB The last column of the .pth
% matrix is the time in seconds
% from the start of the drogue run.
% this becomes timesec below

%Convert to lo/la
[la,lo]=xy2ll(P.pth(:,1),P.pth(:,2));
P.pth(:,1)=lo;P.pth(:,2)=la;

tstart =[ %****BOB DROG3DDT does not know the
106 + 23/24 % absolute starting time, so we must
106 + 23/24 % set it here in GMT for the datenum
107 + 4/24 % function call below
107 + 16/24];

% loop over 4 drogues

%****BOB the times in the title are EDT!!!
titlestr{1}=['PSQ4 #89; Rel. Time 1900EDT 17 April, 1999, 35m'];
titlestr{2}=['PSQ4 #34; Rel. Time 1910EDT 17 April, 1999, 13m'];
titlestr{3}=['PSQ4 #36; Rel. Time 0000EDT 18 April, 1999, 35m'];
titlestr{4}=['PSQ4 #93(*); Rel. Time 1300EDT 18 April, 1999, 13m'];

%****BOB These numbers were J.M.'s real tracking numbers
drognum=[89 34 36 93];

% each drogue is plotted separately because mtrack doesn't handle multiple
% tracks
for idrog=1:4
% extract lon,lat info (really x,y) for each drogue
lons=P.pth(idrog:P.ndrog:length(P.pth),1);
lats=P.pth(idrog:P.ndrog:length(P.pth),2);
timesec=P.pth(idrog:P.ndrog:length(P.pth),4);

%****BOB Recall that the drogues may
% have been held fixed while the model
% ran forward until the drogue release
% time. Here, we are looking for the
% place in the .pth data where the
% drogues actually start to move.
% That location in the file is drogue-specific.
%
idx=find(diff(lons)~=0); % index of first different time.
istart=[idx(1)];
idx=istart:length(lons);
lons=lons(idx);
lats=lats(idx);
timesec=timesec(idx)-timesec(idx(1));

figure % new fig per drogue
hb=plotbnd(b);
set(hb,'LineWidth',2)
hc=lcontour(b,'z',[30 45 60 75 90 120]);
set(hc,'LineWidth',.25)
h=plotdrog(P.pth(:,1),P.pth(:,2),P.ndrog,{idrog},{idrog});
set(h,'Color','g','Marker','s','MarkerSize',8,'LineStyle','none')
h=plotdrog(P.pth(:,1),P.pth(:,2),P.ndrog,{P.ndts},{idrog});
set(h,'Color','r','Marker','.','MarkerSize',18,'LineStyle','none')
h=plotdrog(P.pth(:,1),P.pth(:,2),P.ndrog,1,{idrog});
set(h,'Color','k')
title(titlestr{idrog},'FontSize',17)
set(gcf,'Number','off')
set(gcf,'Name',['PSQ4 #' int2str(drognum(idrog))])

% JD SHIFT UCT SHIFT TO EDT
% | |
% \/ \/
% yr m d h m s
dates=datenum(1999,1,tstart(idrog)+1,-4,0,timesec);
mtrack(lons,lats,dates,'ticks',60,'times',60*3,'dates',12,'color','k',...
'fontsize',11,'fontweight','bold','FontName','helvetica','LineWidth',2);

end