%%
id = desb_illustration_id;

%% cross-shore zone boundaries
jarkusnc = fullfile(fileparts(which(mfilename)), '..', 'data', 'jarkus_volumes.nc');
csb = nc_varget(jarkusnc, 'cross_shore_boundary',...
    [find(ismember(nc_varget(jarkusnc, 'id'), id))-1 0], [1 -1])';

%% duros+ results
durosnc = fullfile(fileparts(which(mfilename)), '..', 'simulations', sprintf('%08i', id), 'durosplus', 'run00', sprintf('%08i_pp.nc', id));

x = nc_varget(durosnc, 'cross_shore');
z = nc_varget(durosnc, 'altitude');

postid = z(:,1,:) ~= z(:,2,:);
postid = squeeze(postid | postid(:,:,[2:end end]) | postid(:,:,[1 1:end-1]));

zpre = squeeze(z(:,1,:));
zpost = squeeze(z(:,2,:));
zpost(~postid) = NaN;

preh = plot(x, zpre);
set(preh, 'color', [.7 .7 .7], 'DisplayName', 'Initial profiles')
set(preh(1:end-1), 'HandleVisibility', 'off')
hold on
posth = plot(x, zpost);
set(posth, 'color', [0 0 0], 'DisplayName', 'DUROS+ erosion profiles')
set(posth(1:end-1), 'HandleVisibility', 'off')


title(sprintf('transect %i', id))
xlabel('cross-shore coordinate [m]')
ylabel('Altitude [m] w.r.t. NAP')

zh = vline(csb(2:end-1), ':k');
set(zh, 'DisplayName', 'Zone boundaries')
set(zh(end), 'HandleVisibility', 'on')

xtext = mean([csb(1:end-1); csb(2:end)]);
% ytext = mean([interp1(x, min(zpre), xtext); repmat(min(get(gca, 'YLim')), 1,length(xtext))]);
ytext = repmat(min(zpre(:)), 1, length(xtext));
% textcell = {'landward zone' 'erosion zone', 'sedimentation zone', 'seaward zone'};
textcell = cellstr(sprintf('%i', 1:length(xtext))')';
for i = 1:length(csb)-1
    text(xtext(i), ytext(i), textcell{i},...
        'HorizontalAlignment', 'center',...
        'VerticalAlignment', 'middle');
end

legend show

%%
figureStyle(@styleThesis)
tightenfigure
[fpath fname] = fileparts(which(mfilename));
figurepath = fullfile(fpath, '..', 'figures');
set(gcf, 'tag', '$HeadURL$ $Revision$')
print(gcf, '-depsc2', fullfile(figurepath, [fname '.eps']))
if ispc
    saveas(gcf, fullfile(figurepath, [fname '.emf']))
end
saveas(gcf, fullfile(figurepath, [fname '.fig']))