%% Plot Drifter Deployment
% syntax: plotdeployment('Driftersessionjune 11 morning.mat')

function plotdeployment(filename)


 load(filename) % load drifterdata

[XI,YI,ZI]=loadbathy; % load bathy 

for dep_nr=1:length(deployments);
    figure
    legendstr=[];
    hold all
    ndrifters=length(deployments(dep_nr,1).drifterdata);
    for drift_nr=1:ndrifters
        
        plot(deployments(dep_nr,1).drifterdata{drift_nr}(:,1),deployments(dep_nr,1).drifterdata{drift_nr}(:,2),'--.')
        legendstr=[legendstr ; num2str(deployments(dep_nr,1).raw.Blueloggers(drift_nr))];

    end
    legend(legendstr)
    axis equal
    ylabel('Y RD in m')
    xlabel('X RD in m')
    %% Clearly mark release point
    for drift_nr=1:ndrifters
        plot(deployments(dep_nr,1).drifterdata{drift_nr}(1,1),deployments(dep_nr,1).drifterdata{drift_nr}(1,2),'.k', 'markersize',15)
    end

    plotbathy(XI,YI,ZI)

    title(['Drifter session ' deployments(dep_nr,1).name ' deployment nr. ' num2str(dep_nr)])
end



function [XI,YI,ZI]=loadbathy

disp('loading bathy...');
A_2=load('XYZ_RD2009_06_09.mat');
B_2=load('XYZ_RD2009_06_11.mat');

XYZjet=A_2.XYZ_RD;
XYZloop=B_2.GPSdata_RD(:,1:3);

XYZ=[ XYZjet ; XYZloop];%

%%% select area of interest 
if 1
    ind=find (XYZ(:,3)< 1.5 & XYZ(:,3)>-3.2);
    XYZ=XYZ(ind,:);
end

gridsize=4;
[XI,YI] = meshgrid(min(XYZ(:,1)):gridsize:max(XYZ(:,1)), min(XYZ(:,2)):gridsize:max(XYZ(:,2)));
ZI = griddata(XYZ(:,1),XYZ(:,2),XYZ(:,3),XI,YI);

function plotbathy(XI,YI,ZI)

pcolor(XI,YI,ZI)

hold on;

[C,h] = contour(XI,YI,ZI,[-9:0.3:4],'--k');
clabel(C,h,'LabelSpacing',72,'FontSize',10,'Color','k','Rotation',0) ;


%
shading interp
axis auto
axis equal

colorbar

