function s=get_side(modindex,xy)

% function s=get_side(modindex,xy)
%
% This function is used in conjunction with FD3.  It is called to determine
% on which side of the module FD3MODULES(1,modindex) a user has clicked.  'Xy'
% is the [x, y] coordinate of the click.  This function returns s=1 if the
% click is on the right, s=2, if the click is on the top, s=3 if the click is
% on the left, and s=4 if the click is on the bottom.
%
% ACP

% Last update:  July 11, 1993
% Author:       Adrian C. Penisson

global FD3MODULES

% get angle formed by 'xy' with center

theta=atan2(xy(1,2)-FD3MODULES(5,modindex),xy(1,1)-FD3MODULES(4,modindex));

% Adjust angle so:  0<angle<2pi

if theta<0
   theta=2*pi+theta;
end

% Pick sides

if FD3MODULES(11,modindex)>=theta & theta>FD3MODULES(10,modindex)
   s=2;
elseif FD3MODULES(12,modindex)>=theta & theta>FD3MODULES(11,modindex)
   s=3;
elseif FD3MODULES(13,modindex)>=theta & theta>FD3MODULES(12,modindex)
   s=4;
else
   s=1;
end
