%% Simple example show the Volumetric changes in wet area
clear 
close all

Mpath='F:\check_outs\tudelft\vlugtenburg\scripts\Matthieu'

% make timestacks of the profiles

savefigs=0; %Toggle 

load([Mpath '\MakeTopo\AllVbeachsurveys.mat'])
%%
load([Mpath '\waveheightanalysis\Pperiod.mat'])

%% Timestack profile
%for i_transect=1:22;


b_off=1150;
b_on=00;
b_b=-6.5;
b_up=3;

for i_transect=1:22;
for i_date=1:length(Vsurvey)
timestack(i_date,:)=Vsurvey(i_date).transects.elevation(:,i_transect)';
x=Vsurvey(i_date).transects.cr_sh(:)    ;
date(i_date)=Vsurvey(i_date).matlabdate;
Vol(i_date,i_transect) =jarkus_getVolume(x,timestack(i_date,:), b_up, b_b,b_on,b_off);
if i_date >= 2
VolChange(i_date,i_transect) =Vol(i_date,i_transect)-Vol(i_date-1,i_transect);
RelVol(i_date,i_transect) =Vol(i_date,i_transect)-Vol(1,i_transect);
end
end
end

%% show validity of boundaries
if 1
figure(22)
subplot(211)
plot(x,timestack)
vline([b_off b_on],'b')
 hline([b_b b_up],'b')
xlim([0 1200])
ylim([-10 5])
grid on
ylabel('elevation [m]')

subplot(212)
plot(x,nanstd(timestack))
xlim([0 1200])
grid on
ylabel('std profiles [m]')
xlabel('cross shore [m]')
end


%% show single profile
i_transect=7;
figure(21)
plot(date,RelVol(:,i_transect),'.-')
hold all
plot(date,VolChange(:,i_transect),'.-')
datetick('x',3,'keeplimits')
ylabel('Volume [m3/m]')
xlabel('month, 2009 to 2011')
grid on
hold off

%%
figure(21)
plot(date,RelVol(:,i_transect),'.-')
hold all
plot(date,VolChange(:,i_transect),'.-')
datetick('x',3,'keeplimits')
ylabel('Volume [m3/m]')
xlabel('month, 2009 to 2011')
stem( Pperiod(2:end,3), Pperiod(2:end,1)/10^8)
stem( Pperiod(2:end,3), Pperiod(2:end,4)/10^8)
stem( Pperiod(2:end,3), Pperiod(2:end,5)/10^8,'m')
grid on
hold off
%%
figure(218)

hold all
for i_transect=2:21;
scatter(Pperiod(:,5),VolChange(:,i_transect)) 
end
ylabel('Volume [m3/m]')
xlabel('Wave power')
grid on


scatter(Pperiod(:,5), nanmean(VolChange(:,2:21),2),'*k')
hold off
%% show all profiles
figure(231)
 plot(date,RelVol(:,2:end-1))
 datetick('x',3,'keeplimits')
 xlabel('month, 2009 to 2011')
 grid on

figure(23)
 pcolor(date,1:22,RelVol')
 datetick('x',3,'keeplimits')
legend('Volume [m3/m]')
 xlabel('month, 2009 to 2011')
 caxis([-80 80])
 grid on


