function LOB=adi_array_lob(delx,dely)
%
% Compute LOB in degress East of North.
%
%
% COPYRIGHT (c) 2008
% 
% Applied Research Laboratories, The University of Texas at Austin
% (ARL:UT)
% All rights reserved.
% 
% This material may be reproduced by or for the U.S. Government
% only. This notice must appear in all copies of this file and its
% derivatives. Further distribution outside the U.S. Government is
% prohibited without the explicit written authorization from the
% Director of the Environmental Sciences Laboratory, ARL:UT.
% 
% THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
% EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO THE
% IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
% PURPOSE, OR NONINFRINGEMENT.
% 
% IN NO EVENT WILL ARL:UT BE LIABLE FOR ANY DAMAGES WHATSOEVER ARISING
% OUT OF THE USE OR INABILITY TO USE THIS SOFTWARE, EVEN IF ARL:UT HAS
% BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.

% VLA case:
if all(delx==delx(1)) & all(dely==dely(1)), LOB=90; return; end
%
warning off MATLAB:polyfit:RepeatedPointsOrRescale
P=polyfit(delx,dely,1);
warning on MATLAB:polyfit:RepeatedPointsOrRescale
LOB=90 - atan(P(1))*180/pi;
% Make sure LOB does not point in opposite direction since P(1) only gives slope:
dx=delx(end)-delx(1); dy=dely(end)-dely(1);
if dx~=0 | dy~=0, LOB0=atan2(dx,dy)*180/pi; else, LOB0=LOB; end
if abs(LOB0-LOB) > 90, LOB=LOB - 180*sign(LOB); end
