function varargout=plotlabel(str,varargin)
%This function puts a text string in the corner of a plot. The default
%position in the upperleft corner. Additional name-value pairs can be
%passed to this routine in order to modify the string properties. Here are
%some examples:
%       axislabel('(a)') : puts '(a)' in the upper left corner
%       axislabel('(a)','lowerright') : puts '(a)' in the lower right corner
%       axislabel('(a)','fontsize',20): puts '(a)' in the upeer left corner
%                                       using a fontsize of 20
%       axislabel('(a)','lowerright','fontsize',20) : you get the idea
%You can also return the string handle

if ~isempty(varargin)
    if mod(length(varargin),2)==0
        position='upperleft';
    else
        position=varargin{1};
        varargin=varargin(2:end);
    end
else
    position='upperleft';
end

if strcmpi(position,'upperleft')
    x=0.05;
    y=0.9;
    algn='left';
elseif strcmpi(position,'upperright')
    x=0.95;
    y=0.9;
    algn='right';
elseif strcmpi(position,'lowerright')
    x=0.9;
    y=0.1;
    algn='right';
elseif strcmpi(position,'lowerleft')
    x=0.1;
    y=0.1;
    algn='left';
elseif strcmpi(position,'center')
    x=0.5;
    y=0.85;
    algn='center';
else
    display('Invalid position specified')
end

h=text(x,y,str,'Units','Normalized','HorizontalAlignment',algn,varargin{:});
if nargout==1
    varargout{1}=h;
end
