function  th = signature(name,logo,fontsize)
%SIGNATURE  Places a timestamp/signature on the current figure.
%
%  SIGNATURE will place as text the current time vertically on the far
%  right of the active figure using a default font size of 8 points.  
%
%  SIGNATURE(STRING1) will place vertically on the far right of the
%  current figure one line of text with STRING1 and the time.
%
%  SIGNATURE(STRING1,STRING2) will place a second text string, STRING2,
%  vertically just to the right of the STRING1/time string.
%
%  SIGNATURE(STRING1,STRING2,FSIZE) will place the 2 text strings
%  on the current figure using a font size of FSIZE.
%
%  TH = SIGNATURE returns handle(s) of the created text object(s).
%
%  Try the following example to get a feel for how SIGNATURE works:
%
%  >> plot(randn(30,1));      % Create a plot of random numbers.
%  >> signature('John Doe','NPS Oceanography');  % Sign it!

%  Kirill K. Pankratov,   kirill@plume.mit.edu
%  April 8, 1994;  April 27, 1994
%
%  Mike Cook - NPS Oceanography Dept., JUL 94 - downloaded program
%  by above author from ftp archive from the MATHWORKS and modified,
%  and added better online help.

%  User changeable defaults.
namedflt = '';  		% Name default
logodflt = '';   		% "Logo" default
ftszdflt = 8;          		% Font size default

%  Hardwired defaults.
ishm = 1;   		% hours and minutes to be added to date? (1=yes)
color = [1 1 1]; 	% Color of the text
ftname = 'helvetica';	% Fontname
offset = 0.75;		% Offset factor of STRING2 from STRING1
posdflt = [0.925, 0.5];	% default position (in Normalize units)

defAX = gca;	       % Remember current axis for later

%  Replace any defaults with user supplied values
if nargin < 4, pos = posdflt; end
if nargin < 3, fontsize = ftszdflt; end
if nargin < 2, logo = logodflt; end
if nargin < 1, name = namedflt; end
if length(fontsize)<2, fontsize = fontsize([1 1]'); end

%  Create a time string 
time = clock;
cstr = num2str(time(5));
if length(cstr)==1, cstr = ['0' cstr]; end  % Add '0' for minutes
d = date;
if ishm, d = [d ', ' num2str(time(4)) ':' cstr]; end
string = [name '  ' d];

%  Make an invisible axes 
ah = axes('units','normal','pos',[0 0 1 1]);
set(ah,'xlim',[0 1],'ylim',[0 1],'visible','off')
%MC% set(ah,'xtick',[], 'ytick',[])

th = text(pos(1,1),pos(1,2),string);  % Draw STRING1
%MC% set(th,'fontsize',fontsize(1),'fontname',ftname,'color',color,'Rotation',90, ...
%MC%        'HorizontalAlignment','center','VerticalAlignment','middle')
set(th,'fontsize',fontsize(1),'fontname',ftname,'Rotation',90, ...
       'HorizontalAlignment','center','VerticalAlignment','middle')
drawnow
ext = get(th,'extent');
if size(pos,1)<2
  pos(1) = pos(1)+offset*ext(3);
else, pos = pos(2,:);
end

%MC% if logo~=[]                           % Draw STRING2 if added
if ~isempty(logo)
 th(2) = text(pos(1),pos(2),logo);
%MC% set(th(2),'fontsize',fontsize(2),'fontname',ftname,'color',color,'Rotation',90, ...
%MC%           'HorizontalAlignment','center','VerticalAlignment','middle')
 set(th(2),'fontsize',fontsize(2),'fontname',ftname,'Rotation',90, ...
           'HorizontalAlignment','center','VerticalAlignment','middle')
end

th = th(:);    % Output handles
axes(defAX);   % Set axis back to one which was current before
               % function was called.
