function hh = sign_title(string, varargin)
% SIGN_TITLE puts a title and signature on the current axis
%    SIGN_TITLE is called in exactly the same way as the standard matlab
%    function TITLE and is a replacement for it. The signature added to the
%    title is a personal identifier, the calling mfile and the date.

% $Id: sign_title.m,v 1.7 2001/05/21 06:03:21 man133 Exp $
% Copyright J. V. Mansbridge, CSIRO, Wed Oct 29 13:11:16 EST 1997

if nargin == 0
  help sign_title
  error('sign_title was passed no arguments')
end

% Find the name of the function or m-file that called sign_title. If we had
% just used mfile then it would return 'sign_title'.
dblist = dbstack;
if length(dblist) == 1
  str_add = [':JVM: ' date];
else
  str_add = [':JVM:' dblist(2).name ': ' date];
end
max_line_length = 100;

% Note that STRING may be a string or a cell of strings.

if iscell(string)
  title_new = string;
  num_lines = length(string);
  last_line_orig = string{num_lines};
  if length(last_line_orig) > max_line_length - length(str_add)
    title_new(num_lines+1) = {str_add};
  else
    title_new{num_lines} = [last_line_orig str_add];
  end
else
  if length(string) > max_line_length - length(str_add)
    title_new(1) = {string};
    title_new(2) = {str_add};
  else
    title_new = [string str_add];
  end
end

if nargin <= 1
  han = title(title_new);
else
  han = title(title_new, varargin{:});
end

if nargout > 0
  hh = han;
end
