% Show variability in surveys
clear all
close all

%% load data

year = 2009;
month = 7:12;
k=1;

for i = 1:length(month)
    [cross_shore,altitude(k,:,:)] = combine_surveys(year,month(i));
    k=k+1;  
end

year = 2010;
month = 1:3;
for i = 1:length(month)
    [cross_shore,altitude(k,:,:)] = combine_surveys(year,month(i));
end

along_shore = nc_varget('vlugtenburg.nc','dist_alongshore');
[along_i cross_i] = meshgrid(along_shore,cross_shore);

%% plot random survey
if 1 
    figure
    %     temp = squeeze(altitude(1,:,:));
    
    [C,h]=contour(cross_i',along_i',squeeze(altitude(2,:,:))',[-8:-1 1 2 3 5]);
    clabel(C,h);%,'LabelSpacing',72)
    hold on
        [C,h]=contour(cross_i',along_i',squeeze(altitude(2,:,:))',[0 0],'linewidth',3);
    set(gca,'XDir','reverse')
    shading interp
    plot(cross_i, along_i, '-.','Color',[0.9 0.9 0.9])%,'linewidth',5)
    axis equal
    xlim([min(cross_shore)+300 max(cross_shore)-400])
    ylim([min(along_shore)-00 max(along_shore)+00])
    for k = 1:22;text(cross_shore(1)+200,along_shore(k),num2str(k),...
            'HorizontalAlignment','right');end
    title('Arbitrary survey in local axis system')
    xlabel('Cross shore [m]')
    ylabel('Along shore [m]')
end
%% plot differences
 if 1 
    figure
    subplot(1,2,2)
    diff = squeeze(altitude(end,:,:))-squeeze(altitude(1,:,:));
    %     temp = squeeze(altitude(1,:,:));
    pcolor(cross_i',along_i',diff');
    set(gca,'XDir','reverse')
    shading interp
    hold on
    plot(cross_i, along_i, '-.k')    
    axis equal
    xlim([min(cross_shore)-150 100])
    ylim([min(along_shore)-100 max(along_shore)+100])
    for k = 1:22;text(cross_shore(1)-80,along_shore(k),num2str(k),...
            'HorizontalAlignment','right');end
    title('random difference plot')
    xlabel('Cross shore [m]')
    ylabel('Along shore [m]')
    colorbar
    caxis([-1 1])
    
    subplot(1,2,1)
    pcolor(cross_i',along_i',squeeze(altitude(2,:,:))');
    set(gca,'XDir','reverse')
    shading interp
    hold on
    plot(cross_i, along_i, '-.k')    
    axis equal
    xlim([min(cross_shore)-150 100])
    ylim([min(along_shore)-100 max(along_shore)+100])
    for k = 1:22;text(cross_shore(1)-80,along_shore(k),num2str(k),...
            'HorizontalAlignment','right');end
    title('random survey plot')
    xlabel('Cross shore [m]')
    ylabel('Along shore [m]')
    colorbar
    caxis([-1 12])

    
end
%% asses variance
    
var_alt = squeeze(nanvar(altitude)); % let op hier worden de NANS weg gelaten
figure;
pcolor(cross_i',along_i',var_alt');
set(gca,'XDir','reverse')
caxis([0 0.5])
shading interp



