function [xdata,ydata]=ext_str(xy,flag)

% function [xdata,ydata]=ext_str(xy,flag)
%
% This function is used in conjunction with FD3.  When the user is in manual
% horizontal/vertical stream creation mode, the 'xy' coordinate of each click
% after the first is fed to this program (the second click must not be on a
% module or auto_stream will be used).  'Flag' is 1 when the click is on a
% blank section of the window and 0 when it occurs on a module.  The behavior
% of the function is slightly different when the user clicks on a module
% because the stream has to end up touching the module.
%
% ACP

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

global FD3OBJECT FD3LASTPOS

% Get object's currect xdata and ydata

if length(FD3OBJECT)>0
   xdata=get(FD3OBJECT,'Xdata');
   ydata=get(FD3OBJECT,'Ydata');
else
   xdata=FD3LASTPOS(1,1);
   ydata=FD3LASTPOS(1,2);
end

len=length(xdata);

% Determine angle of point relative to last click

dx=xdata(len)-xy(1,1);
dy=ydata(len)-xy(1,2);

theta=atan2(abs(dy),abs(dx))/pi;

if abs(theta)<.75 & abs(theta)>.25

   % In this case, the new line is vertical

   if xdata(len)==xdata(len-1)
      xdata=xdata(1:len-1);
      ydata=ydata(1:len-1);
   end

   len=length(xdata);

   ydata=[ydata xy(1,2)];

   if flag
      % The click was on blank space
      xdata=[xdata xdata(len)];
   else
      % The click was another module
      xdata=[xdata(1:len-1) xy(1,1) xy(1,1)];
   end

else

   % In this case, the new line is horizontal

   if ydata(len)==ydata(len-1)
      xdata=xdata(1:len-1);
      ydata=ydata(1:len-1);
   end

   len=length(xdata);

   xdata=[xdata xy(1,1)];

   if flag
      % The click was on black space
      ydata=[ydata ydata(len)];
   else
      % The click was another module
      ydata=[ydata(1:len-1) xy(1,2) xy(1,2)];
   end

end
