rundir = 'p:\1002266-xbeach\coastal_curvature\simulations\00000000\xbeach\run26\';
% rundir = 'd:\heijer\sources\dune_erosion_coastline_curvature\simulations\00000000\xbeach\run26\';

calcdirs = dir(fullfile(rundir, 'radius01*'));
% calcdirs = calcdirs([1]);

%%
for iradii = 1:length(calcdirs)
    ncfile = fullfile(rundir, calcdirs(iradii).name, 'xboutput.nc');
%      nc_varget(ncfile, 'zb', [0 0 109], [1 1 1])
    
    [phi Ero Sed Svsg_cs ccg_cs zs zs_mean u_mean v_mean] = decc_analyse(ncfile);
    
    result(iradii).phi = phi;
    result(iradii).Ero = Ero;
    result(iradii).Sed = Sed;
    result(iradii).Svsg_cs = Svsg_cs;
    result(iradii).ccg_cs = ccg_cs;
    result(iradii).zs = zs;
    result(iradii).zs_mean = zs_mean;
    result(iradii).u_mean = u_mean;
    result(iradii).v_mean = v_mean;
end

legtxt = {calcdirs.name};
col = 'rgbkmc';

%%

figure;


subplot(5,1,1)
for iradii = 1:length(calcdirs)
    plot(result(iradii).phi, -result(iradii).Ero, col(iradii))
    hold on
end
xlabel('angle between shore normal and incident wave direction [degrees]')
ylabel('Erosion [m^3/m]')
legend(legtxt)

subplot(5,1,2)
for iradii = 1:length(calcdirs)
    plot(result(iradii).phi, result(iradii).Sed, col(iradii))
    hold on
end
xlabel('angle between shore normal and incident wave direction [degrees]')
ylabel('Accretion [m^3/m]')

subplot(5,1,3)
for iradii = 1:length(calcdirs)
    plot(result(iradii).phi, result(iradii).Sed + result(iradii).Ero, col(iradii))
    hold on
end
xlabel('angle between shore normal and incident wave direction [degrees]')
ylabel('Accretion - Erosion [m^3/m]')

subplot(5,1,4)
for iradii = 1:length(calcdirs)
    plot(result(iradii).phi, result(iradii).Svsg_cs, col(iradii))
    hold on
end
xlabel('angle between shore normal and incident wave direction [degrees]')
ylabel('Integrated Svsg [m^3/s]')

subplot(5,1,5)
for iradii = 1:length(calcdirs)
    plot(result(iradii).phi, result(iradii).ccg_cs*2650, col(iradii))
    hold on
end
xlabel('angle between shore normal and incident wave direction [degrees]')
ylabel('Mean ccg kg/m^3')

%%
figure
for iradii = 1:length(calcdirs)
    yid = 1;%round(size(result(iradii).zs,2)/2);
    plot(result(iradii).zs(:, yid), col(iradii))
    hold on
end
xlabel('angle between shore normal and incident wave direction [degrees]')
ylabel('zs')
legend(legtxt)

%%
figure
for iradii = 1:length(calcdirs)
    plot(result(iradii).phi, result(iradii).zs_mean, col(iradii))
    hold on
end
xlabel('angle between shore normal and incident wave direction [degrees]')
ylabel('zs mean @ offshore boundary')
legend(legtxt)

%%
figure
for iradii = 1:length(calcdirs)
    plot(result(iradii).phi, result(iradii).u_mean, col(iradii))
    hold on
end
xlabel('angle between shore normal and incident wave direction [degrees]')
ylabel('u mean @ offshore boundary')
legend(legtxt)

%%
figure
for iradii = 1:length(calcdirs)
    plot(result(iradii).phi, result(iradii).v_mean, col(iradii))
    hold on
end
xlabel('angle between shore normal and incident wave direction [degrees]')
ylabel('v mean @ offshore boundary')
legend(legtxt)