function data=s_htank(xy,yt,xl)

% function data=s_htank(xy,yt,xl)
%
% This function is used in conjuction with FD3.  If the function is called
% with three arguments, 'xy' is the vector containing the [x, y] coordinate
% of the center, 'yt' is the y coordinate of the top of the tank, and 'xl' is
% the x coordinate of the leftmost point on the tank.  If the function is
% called with one argument 'xy', 'xy' will represent the [x, y] coordinate of
% the center of the tank the first time the function is called, the [x, y]
% coordinate of a point on the top of the tank the second time the function
% is called, and the [x, y] coordinate of a point on the left side of the tank
% the third time the function is called.  The former method of sending
% information to s_htank is employed during the load process while the
% latter method is employed when an FD3 user creates a horizontal tank by
% clicking on the window three times.  See 'user_def' for a complete
% explanation of the information contained in 'data'.
%
% ACP

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

global FD3FUNCLEVEL FD3LASTPOS FD3MESSAGE FD3AXES

if nargin==1

   if FD3FUNCLEVEL==0

      str='Point and|click on the|top of the|tank.';
      FD3MESSAGE=di_mssg(str);
      FD3LASTPOS=[xy(1,1) xy(1,2)];   
      FD3FUNCLEVEL=1;

      return

   elseif FD3FUNCLEVEL==1

      str='Point and|click on the|left of the|tank.';
      FD3MESSAGE=di_mssg(str);
      FD3LASTPOS=[FD3LASTPOS;[xy(1,1) xy(1,2)]];   
      FD3FUNCLEVEL=2;

      return

   elseif FD3FUNCLEVEL==2

      x=FD3LASTPOS(1,1);
      y=FD3LASTPOS(1,2);
      yt=FD3LASTPOS(2,2);
      xl=xy(1,1);

   end

elseif nargin>1

   x=xy(1,1);
   y=xy(1,2);

end

r=abs(yt-y);
c1=xl+r+i*y;
c2=2*x-real(c1)+i*y;
npts=20;

data1=arc(c1,r,npts,pi/2,1.5*pi);
data2=arc(c2,r,npts,-pi/2,pi/2);

data=[data1 data2 c1+r*i];

axes(FD3AXES(3))

h=line(real(data),imag(data));

theta1=atan2(r,x-xl);
theta2=atan2(r,xl-x);
theta3=2*pi-theta2;
theta4=2*pi-theta1;

FD3FUNCLEVEL=0;
FD3LASTPOS=[];

data=[h 0 0 x y 3 yt xl 0 theta1 theta2 theta3 theta4 1 1];
