function adj_lbl(strindex)

% function adj_lbl(strindex)
%
% This function is used in conjunction with FD3.  This function adjusts the
% label on the stream designated by FD3STREAMS(:,strindex) so that it is in
% the proper position.   Stream labels are always placed on the stream
% segments designated by the second-to-last and last xdata/ydata points.
% 'Strindex' may be a single stream index or a list of stream indices.  See
% also 'make_lbl'.
%
% ACP

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

global FD3SCALE FD3STREAMS

for i=strindex

   % Get xdata/ydata

   xdata=get(FD3STREAMS(1,i),'Xdata');
   ydata=get(FD3STREAMS(1,i),'Ydata');

   len=length(xdata);

   % Calculate angle of last stream section

   dy=ydata(len-1)-ydata(len);
   dx=xdata(len-1)-xdata(len);

   theta=atan2(dy,dx);

   % Use that angle to find position of label

   if (theta>0 & theta<(pi/2)) | (theta>(-pi) & theta<(-pi/2))
      x=mean(xdata([len len-1]))-abs(sin(theta)*.6*FD3SCALE);
   else
      x=mean(xdata([len len-1]))+abs(sin(theta)*.6*FD3SCALE);
   end

   y=mean(ydata([len len-1]))+abs(cos(theta)*.6*FD3SCALE);

   % Set new position

   set(FD3STREAMS(2,i),'Position',[x y 0]);

end
