ncfile = 'p:\1002266-xbeach\coastal_curvature\simulations\00000000\xbeach\run26\radius01900\xboutput.nc';

%% load data
ue = nc_varget(ncfile, 'ue_mean');
ve = nc_varget(ncfile, 've_mean');
ee = nc_varget(ncfile, 'ee', [90 0 0 105], [1 -1 -1 1]);
% ee = nc_varget(ncfile, 'ee', [50 0 0 105], [1 -1 -1 1]);
alfa = 190:10:350;
xb = xb_read_output(ncfile, 'vars', {'DIMS'});
g = xb_stagger(xb);
phi = mean(g.alfaz,1);

%%
[X Y] = meshgrid(phi, alfa);
pcolor(X,Y,ee)
shading flat

%%
% phi_coast = mean(g.alfaz,1);
% PHI = zeros(size(ue(1,:,:)));
% PHI(1,:,:) = repmat(phi_coast',1,size(ue,3));
% t = repmat({PHI}, size(ue,1),1 );
% PHI = cat(1, t{:});
% ve_n = ve .* cos(PHI) + ue .* -sin(PHI);
% 
% [ve_n_max ix] = max(abs(ve_n), [], 3);
% 
% for i = 1:size(ix,1)
%     for j = 1:size(ix,2)
%         ve_n_max(i,j) = ve_n(i,j,ix(i,j));
%     end
% end
% 
% ue_s = ve .* sin(PHI) + ue .* cos(PHI);
% 
% ue_s_min = min(ue_s, [], 3);

%% x and y velocities
figure; pcolor(ue); shading flat; colorbar
figure; pcolor(ve); shading flat; colorbar

%% alongshore velocity
figure; pcolor(ve.*repmat(cos(phi_coast),size(ue,1),1) + ue.*repmat(-sin(phi_coast),size(ue,1),1)); shading flat; colorbar

%% cross-shore velocity
figure; pcolor(ve.*repmat(sin(phi_coast),size(ue,1),1)...); shading flat; colorbar
...figure; pcolor(...
+ue.*repmat(cos(phi_coast),size(ue,1),1)); shading flat; colorbar

%% cross-shore profiles @ various angles
ncfile = result(1).ncfile;
xb = xb_read_output(ncfile, 'vars', {'DIMS'});
g = xb_stagger(xb);
phi = -rad2deg(mean(g.alfaz,1));
a = -50:10:0;
p = round(interp1(phi, 1:311, a));
yid = linspace(max(p) - (length(p)-1) * max(diff(p)), max(p), length(p));
p = phi(yid);
zb = nc_varget(ncfile, 'zb', [0 yid(1)-1 0], [-1 length(yid) -1], [1 unique(diff(yid)) 1]);
dsz = g.dsz(:,yid);
dsz(1,:) = 0;
s = cumsum(dsz, 1);
figure;
plot(s(:,end), squeeze(zb(1,end,:))', ':', 'displayname', 'Initial profile');
hold on
ph = plot(s, squeeze(zb(end,:,:))');
for ip = 1:length(p)
    set(ph(ip), 'displayname', sprintf('%.0f degrees', p(ip)));
end
lh = legend('show');
set(lh,...
    'location', 'NorthWest')