%% 1D Dam Break Dry Bed Model Analyser
% Tim Leijnse
% Made for 1D Dam break dry bed test to analyse the desired SFINCS and XBeach runs

function analyze_this_1Ddrybed(info, dirs)

%% Reading water levels
ncFileName_sb   = fullfile(dirs.output, '1D_dry_bed_surfbeat', 'xboutput.nc');
ncFileName_nonh = fullfile(dirs.output, '1D_dry_bed_nonh', 'xboutput.nc');

dx      = nc_attget(ncFileName_sb, '_parameters', 'dx');
t_end   = nc_attget(ncFileName_sb, '_parameters', 'tstop');
dtout   = nc_attget(ncFileName_sb, '_parameters', 'tintg');

%XBSB
xbsbzs = nc_varget(ncFileName_sb, 'zs');
zs_sb = squeeze(xbsbzs(:,:,:));
zs_sb(isnan(zs_sb))=0;
zs_sb_end = zs_sb(end,:);

%XBNH
xbnhzs = nc_varget(ncFileName_nonh, 'zs');
zs_nh = squeeze(xbnhzs(:,:,:));
zs_nh(isnan(zs_nh))=0;
zs_nh_end = zs_nh(end,:);

%% Plotting figures
%analytical solution for plotting

[x_analytical,h_analytical] = analytical_1Ddrybed(dx, t_end, dtout);

%figure
fh1 = figure('units','pixels','position',[0 0 1920 1080]);
plot(x_analytical, h_analytical,'k','DisplayName','Analytical Solution','LineWidth',2);
hold on
plot(x_analytical, zs_sb_end, 'r', 'DisplayName','XBSB','LineStyle','-','LineWidth',2);
hold on
plot(x_analytical, zs_nh_end, 'b', 'DisplayName','XBNH','LineStyle','-','LineWidth',2);
hold on

title('1D Dam Break Dry Bed Test','fontsize',18);
xlabel('x(m)','fontsize',18);
ylabel('z(m)','fontsize',18);
axis([0 100 0 1.1]);
legend('show');
hold off

xb_write_plot(fh1, dirs.output, '01_DamBreak1Ddrybed');