%% Timestack profile
clear
Mpath='F:\check_outs\tudelft\vlugtenburg\'

% make timestacks of the profiles

savefigs=0; %Toggle 

load([Mpath 'AllVbeachsurveys.mat'])


%% Timestack profile
%for i_transect=1:22;
i_transect=5;
% for i_date=1:length(Vsurvey)
% %timestack(i_date,:)=mean([ Vsurvey(i_date).transects.elevation(:,i_transect) Vsurvey(i_date).transects.elevation(:,i_transect+1)]' );
% timestack(i_date,:)=([ Vsurvey(i_date).transects.elevation(:,i_transect)]' );
% x=Vsurvey(i_date).transects.cr_sh(:)    ;
% date(i_date)=Vsurvey(i_date).matlabdate;
% end


for i_date=1:3:length(Vsurvey)-2
%timestack(i_date,:)=mean([ Vsurvey(i_date).transects.elevation(:,i_transect) Vsurvey(i_date).transects.elevation(:,i_transect+1)]' );
timestack(i_date,:)=mean([ Vsurvey(i_date).transects.elevation(:,i_transect) Vsurvey(i_date+1).transects.elevation(:,i_transect) Vsurvey(i_date+2).transects.elevation(:,i_transect) ]' );
x=Vsurvey(i_date).transects.cr_sh(:)    ;
date(i_date)=Vsurvey(i_date+1).matlabdate;
end

 %%% Timestack profile

figure(12)
 set(gcf,'PaperPosition',[0  0  40 20])
 set(gcf,'Position',[100          231        600         300])

% cmap=colormap(winter(length(Vsurvey)));
 
 cmap=colormap(winter(length(date)));
 
 
 plot(x,timestack(1,:)*0,':b')
hold all
for i_date=1:length(date); [1:11 14:26 28:length(Vsurvey)]
plot(x,timestack(i_date,:),'color',cmap(i_date,:), 'linewidth', 2)
end

plot([0 0],[4 5.5],'-k','linewidth', 3)

plot([0 1200 ],[7 7],'k','linewidth', 1)

plot([1200 1200 ],[-9.5 7.5],':k','linewidth', 1)
h=2;
w=80;
x_ds=[0 0 -.20 0 .20 0]*h;
y_ds=[0 1 .60 .60 .60 1]*w;
 
plot(y_ds+1200-w,x_ds+7,'k','linewidth', 1)
plot(-y_ds+0+w,x_ds+7,'k','linewidth', 1)

set(gca,'xdir','reverse')

plot([205 1300],[0 0],'b')
plot([-220 205],[0 0],':b')

xlim([-220 1300])
grid on

set(gca,'xtick',[-200:200:1200])
set(gca,'ytick',[-9:3:12])

shading flat
%xlim([-240 380])



% legend('elevation [m]','Total wave power between surveys','mean daily wave power','max daily wave power')
% title([ 'Profile evelation timestack, profile ' num2str(i_transect)])

hold off

%% Dune closeup


figure(13)
 set(gcf,'PaperPosition',[0  0  40 20])
 set(gcf,'Position',[100          231        600         300])

% cmap=colormap(winter(length(Vsurvey)));
 
 cmap=colormap(winter(length(date)));
 
 
 plot(x,timestack(1,:)*0,':b')
hold all
for i_date=1:length(date); [1:11 14:26 28:length(Vsurvey)]
plot(x,timestack(i_date,:),'color',cmap(i_date,:), 'linewidth', 2)
end

plot([0 0],[4 5.5],'-k','linewidth', 3)

set(gca,'xdir','reverse')

plot([205 1300],[0 0],'b')
plot([-220 205],[0 0],':b')

xlim([-200 50])
grid on

set(gca,'xtick',[-200:50:1200])
set(gca,'ytick',[-0:2:12])

shading flat
%xlim([-240 380])



% legend('elevation [m]','Total wave power between surveys','mean daily wave power','max daily wave power')
% title([ 'Profile evelation timestack, profile ' num2str(i_transect)])

hold off


%% closure end closeup


figure(13)
 set(gcf,'PaperPosition',[0  0  40 20])
 set(gcf,'Position',[100          231        600         300])

% cmap=colormap(winter(length(Vsurvey)));
 
 cmap=colormap(winter(length(date)));
 
 
 plot(x,timestack(1,:)*0,':b')
hold all
for i_date=1:length(date); %[1:11 14:26 28:length(Vsurvey)]
plot(x,timestack(i_date,:),'color',cmap(i_date,:), 'linewidth', 2)
end

plot([0 0],[4 5.5],'-k','linewidth', 3)

set(gca,'xdir','reverse')

plot([205 1300],[0 0],'b')
plot([-220 205],[0 0],':b')

xlim([600 1300])
ylim([-10 -6])
grid on

set(gca,'xtick',[-200:50:1300])
set(gca,'ytick',[-10:1:12])

shading flat
%xlim([-240 380])



% legend('elevation [m]','Total wave power between surveys','mean daily wave power','max daily wave power')
% title([ 'Profile evelation timestack, profile ' num2str(i_transect)])

hold off


