% JPM routine to contour CODAS residuals
% assumes:
% 1) user has run "runstick"
% 2) user is in that subdirectory (usually /stick)
% 3) user has specified infile = 'uw' output of adcpsect run
% 4) path setup for "atsee" routines

% load data
load uw
load uw_xy

% reformat long to negative
xyt(1,:)=xyt(1,:)-360;

% specify depth (1 for layer 1, 2 for layer 2...)
idep=2;
% convert complex data to u & v real
[v,u]=sd2uv(abs(r(:,idep)),angle(r(:,idep))/pi*180);

% set x, y, and z to feed to hsec
x=xyt(1,:)';
y=xyt(2,:)';

% rotate to get velocity relative to bathy
bangle=-45;
zz=rota([u' v'],bangle);

% contour along-isobath component
z=zz(:,1);

% delimit acceptable values now
id=find(abs(zz(:,1))<.2&abs(zz(:,2))<.2);
z=z(id);
x=x(id);
y=y(id);
uu=u(id);
vv=v(id);


hsec
vecplot2(x,y,uu,vv,.1,'m/s',mean(x),min(y),'r','r')

