function [theta,r]=direction(u,v);

%function [theta,r]=thetar(u,v);

%       converts to polar coords, with theta first

%        compass direction, clockwise from north, expecting (E,N)

if nargin==1

   v=imag(u);

   u=real(u);

end

im=sqrt(-1);

u=u+im*v;

r=abs(u);

if u==0;
  if v>0;
    theta=90;
  else;
    theta=-90
  end;
else;
  theta=90-imag(log(u))*180/pi;

end;
a=find(theta<0);

if length(a)>0

theta(a)=theta(a)+360*ones(1,length(a));

end

