% Monthly Sed erosion plots

savefigs=1

%% Load
Mpath='F:\check_outs\tudelft\vlugtenburg'
%Mpath='C:\Madeschipper\check_out\OpenEarthRawData\tudelft\vlugtenburg\scripts\Matthieu'

load([Mpath '\AllVbeachsurveys.mat'])
load([Mpath '\datesandpairs.mat'])

load('cmap_totalSedEro.mat')

%% sed/Eros between first and last surveys
for i_date=2:length(Vsurvey)
    Vsurvey(i_date).SedEro.transects=Vsurvey(i_date).transects.elevation-Vsurvey(1).transects.elevation;
   
    figure(21)
    set(gcf,'PaperPosition',[0  0  40 20])
    set(gcf,'Position',[1          31        1680         944])
    bw=30;
    % survey line
    plot([Vsurvey(i_date).transects.y(1) Vsurvey(i_date).transects.y(1)] ,[0  1200],':k')
    hold all
    for i_t=2:22
        plot([Vsurvey(i_date).transects.y(i_t) Vsurvey(i_date).transects.y(i_t)] ,[0  1200],':k')
    end
    
    for i_t=1:22
        x=Vsurvey(i_date).transects.cr_sh    ;
        y=[Vsurvey(i_date).transects.y(i_t)-bw Vsurvey(i_date).transects.y(i_t)+bw]  ;
        sedero=[Vsurvey(i_date).SedEro.transects(:,i_t) Vsurvey(i_date).SedEro.transects(:,i_t)];
        %pcolor(y,x,sedero)
        eval(['pk=pcolor(y,x,sedero)'])
    end
    shading interp
    axis equal
    
    x=Vsurvey(1).transects.cr_sh    ;
    y=[Vsurvey(1).transects.y]  ;
    z=[Vsurvey(1).transects.elevation(:,:) ];
    [C1,h1] = contour(y,x,z,[-9:2:5],'--k');
    clabel(C1,h1,'LabelSpacing',72,'FontSize',10,'Color','k','Rotation',0) ;
    
    x=Vsurvey(i_date).transects.cr_sh    ;
    y=[Vsurvey(i_date).transects.y]  ;
    z=[Vsurvey(i_date).transects.elevation(:,:) ];
    [C2,h2] = contour(y,x,z,[-9:2:5],'-m');
    clabel(C2,h2,'LabelSpacing',72,'FontSize',10,'Color','m','Rotation',0) ;
    
    
    hold on
    
    set(gca,'Xtick',[flipud(Vsurvey(i_date).transects.y)])
    set(gca,'Xticklabel',num2str([flipud(Vsurvey(i_date).transects.y)],'%4.0f'))
    
    
    
    
    %set(gca, 'XDir', 'reverse')
    xlim([-50 1800])
    xlabel('Alongshore distance [m]')
    
    ylim([0 1200])
    ylabel('Cross shore distance [m]')
    
    caxis([-2.5 2.5])
%     ca=colormap(jet)
%     ca(29:35,:)=1
%     colormap(ca)
colormap(cmap)

colorbar
    
    
    set(gca,'position',[0.1300    0.1100    0.7750    0.8150])
    legend([pk h1  h2], 'sed (r) /eros (b) [m]',[ 'contour ' Vsurvey(1).date([4:6 1:3 7:10])],[ 'contour ' Vsurvey(i_date).date([4:6 1:3 7:10])] )
    title([ 'Sed Erosion survey  ' Vsurvey(i_date).date([1:3 7:10]) ' - ' Vsurvey(1).date([1:3 7:10]) ' , based on the transects'])
    
    
    x0=30;           y0=1050;  theta0 =-131.65534968173412+90;
    h=100; w=100 ;
    [x_ds3,y_ds3]=northarrow(h,w,x0,y0,theta0);
    
    set(gcf,'renderer','zbuffer')
    hold off
    
    if savefigs==1
        filename=[ 'Cumulative Sed Erosion till survey ' Vsurvey(i_date).date([7:10]) '_' Vsurvey(i_date).date([1:2]) '_' Vsurvey(i_date).date([4:5]) ]
        print ([ Mpath '\scripts\Matthieu\SedErosion\images\' filename '.jpg'],'-djpeg')
    end
end