function [spd, dir] = uv2sd(u, v)
% uv2sd - take u,v velocity components and return speed and direction

% 2012/02/03 - changed to atand and removed private function to compute
% degrees from radians.

% D. Nowacki nowacki@uw.edu

spd = sqrt(u.^2 + v.^2);

dir = nan(size(u));


dir(u == 0 & v > 0) = 0;
dir(u > 0 & v > 0) = atand(u(u > 0 & v > 0)./v(u > 0 & v > 0));
dir(u > 0 & v == 0) = 90;
dir(u > 0 & v < 0) = atand(u(u > 0 & v < 0)./v(u > 0 & v < 0)) + 180;
dir(u == 0 & v < 0) = 180;
dir(u < 0 & v < 0) = atand(u(u < 0 & v < 0)./v(u < 0 & v < 0)) + 180;
dir(u < 0 & v == 0) = 270;
dir(u < 0 & v > 0) = atand(u(u < 0 & v > 0)./v(u < 0 & v > 0)) + 360;

end