function handle = texts(xcor, ycor, zcor, textblk, s_script, s, coor)
%  TEXTS places a text object with a sub/super-script.
%  Text can be placed on the screen using screen coordinates,
%  or axes coordinates.
%
%  INPUTS:
%       xcor    =       X-coordinate                    (REQUIRED)
%       ycor    =       Y-coordinate                    (REQUIRED)
%       zcor    =       Z-coordinate                    (OPTIONAL)
%       textblk =       Main text block                 (REQUIRED)
%       s_script=       Sub/Super-scripted text block   (REQUIRED)
%       s       =       'sub' for subscripting          (REQUIRED)
%                       'sup' for superscripting
%       coor    =       'ax' for axes coordinates       (DEFAULT)
%                       'sc' for screen coordinates
%
%  It is not necessary to specify the Z-coordinate for 2-D plots
%  or screen coordinates.
%
%  EXAMPLES:
%
%       h = texts(1,2,3,'TEXT','1','sub')
%       h = texts(1,2,'TEXT','2','sup')
%       h = texts(.2,.5,'TEXT','3','sub','sc')
%       h = texts(5,7,'TEXT','4','sup','ax')

%  Written by John L. Galenski III  04/01/93

%  Some error checking and redeclaration of inputs.
if nargin < 5
        error('Need more inputs')
elseif nargin == 5
        s = s_script;
        s_script = textblk;
        textblk = zcor;
        coor = 'ax';
        zcor = 0;
elseif nargin == 6
        if isstr(zcor)
                coor = s;
                s = s_script;
                s_script = textblk;
                textblk = zcor;
                zcor = 0;
        else
                coor = 'ax';
        end
elseif nargin > 7
        error('Too many inputs')
end

if ~isstr(textblk) | ~isstr(s_script) | ~isstr(s) | ~isstr(coor)
        error('The 3rd, 4th, and 5th inputs must be strings')
end

if s == 'sub' | s == 'Sub'
        s = 'top';
elseif s == 'sup' | s == 'Sup'
        s = 'bot';
elseif s == 'super' | s == 'Super'
        s = 'bot';
else
        error('s is improperly defined.  Should be ''sub'' or ''sup''')
end

%  Place the main text block using either axes or screen coordinates.
if coor == 'ax'
        ht1 = text(xcor,ycor,zcor,textblk,'fontsize',14);
        set(ht1,'units','normal','vert','bot');

else
        %  Get the position of the current axes in normalized units.
        ha1 = get(gca,'units');
        if ha1(1) ~= 'n'
                set(gca,'units','normal')
                hp1 = get(gca,'pos');
        else
                hp1 = get(gca,'pos');
        end
        %  Create a temporary axes whose borders are the edge of the
        %  Figure Window.  This will trick TEXT into using screen
        %  coordinates.
        ha = axes('pos',[0 0 1 1],'vis','off','units','normal');
        ht1 = text(xcor, ycor, textblk,'vert','bot','units','normal','fontsize',14);
        %  Get the current position of the text with respect to the
        %  Figure Window.
        he1 = get(ht1, 'extent');
        %  Create the X and Y limits to be used to place the main text
        %  block in the original axes.
        x = he1(1)+he1(3)-hp1(1);
        y = he1(2)+hp1(2);
        %  Remove the temporary axes.
        delete(ha)
        %  Place the main text block.
        ht1 = text(x, y, textblk,'vert','bot','units','normal','fontsize',14);

end

%  Get the position of the main text block.
he1 = get(ht1,'extent');
%  Create the X and Y coordinates for the sub/super-script.
x = he1(1)+he1(3);
y = he1(2);
set(ht1,'vert','mid');
%  Place the sub/super-script.
ht2 = text(x,y,s_script,'vert',s,'units','normal','fontsize',12);

%  Test for the output
if nargout == 1
        handle = [ht1, ht2];
elseif nargout ~= 0
        error('Too many outputs')
else
        return
end


