function str = sptfileheader(varargin)
%SPTFILEHEADER Utility for generating a file header
%   SPTFILEHEADER Generates a file header with no custom annotations for
%   the signal processing toolbox using '%' as the commenting character.
%
%   SPTFILEHEADER(DESC) Generates a file header and adds the description
%   DESC before the toolbox information.  If DESC is less than 10
%   characters it will be on the same line as the toolbox information.
%
%   SPTFILEHEADER(DESC, TBX) Generates a file header for the toolbox
%   specified in the string TBX.
%
%   SPTFILEHEADER(DESC, TBX, COM) Generates a file header using the
%   COM as the commenting character.
%
%   SPTFILEHEADER(DESC, TBX, COM, DATEFORM) Generates a file header using
%   the specified DATEFORM.  See DATESTR for more information.  DATEFORM is
%   0 by default.
%
%   If DESC or TBX is '', the defaults will be used.

%   Author(s): J. Schickler
%   Copyright 1988-2004 The MathWorks, Inc.
%   $Revision: 1.2.4.4 $  $Date: 2004/08/10 02:11:59 $

desc     = '';
tbx      = 'signal';
comment  = '%';
dateform = 0;

if length(varargin) > 0
    if isnumeric(varargin{end})
        dateform      = varargin{end};
        varargin(end) = [];
    end
end
if length(varargin) > 0
    desc = varargin{1};
end
if length(varargin) > 1
    tbx = varargin{2};
end
if length(varargin) > 2,
    comment = varargin{3};
end

% If the description is short and does not end with a '.' we want to
% attach it to the 'generated by' line.  Otherwise it goes on its own line.
if isempty(desc)
    str = 'G';
elseif length(desc) < 10 && desc(end) ~= '.',
    str = ' g';
else
    str = sprintf('\n%s G', comment);
end

% Get the toolbox info which includes the name and version.
minfo = ver('matlab');
tinfo = ver(tbx);
tinfo = tinfo(1); % In case there are multiple toolboxes on the path.

% Make sure the "generated on/at/in" makes sense.
switch dateform
    case {3, 4, 5, 10, 11, 12, 17, 18, 27, 28}
        prestr = 'in';
    case {13, 14, 15, 16}
        prestr = 'at';
    otherwise
        prestr = 'on';
end

str = sprintf('%s%s\n%s', ...
    sprintf('%s\n%s %s%s', comment, comment, desc, str), ...
    sprintf('enerated by MATLAB(R) %s and the %s %s.', minfo.Version, ...
        tinfo.Name, tinfo.Version), ...
    sprintf('%s\n%s Generated %s: %s\n%s', comment, comment, prestr, ...
        datestr(now, dateform), comment));

% [EOF]
