function varargout = stathdr(varargin)
% ------------------------------------------------------------------
% Display or return a string containing the statistics header.
%
% SYNOPSIS:
%
%   stathdr()
%   s = stathdr()
%   stathdr(stat)
%   s = stathdr(stat)
%
% PARAMETERS:
%
%   stat
%      Character specifying the statistics to use. Possible values are 
%      described in function `limp'.
%
%      If no arguments, all stat headers are generated.
%
% If called with areturn argument, the header is not displayed, but only 
% returned.
% 
% ------------------------------------------------------------------
%Time:<Last updated on 98/07/07 at 11:53:41 by veins@PC159>
%File:<c:/codas3/gfi/matlab/matlab50/scan/stathdr.m>

scanglob;

stats = '';
if nargin == 0,
  stats = 'SP';
end

if (nargin > 0) & length(varargin{1}),
  stats = varargin{1};
end

s = '';
% Loop through the statistics:
for i=1:length(stats),

  stat = stats(i);
  
  switch stat
	 case 'S',
		s = sprintf('%s%s%s%s%s', s, ...
			   sprintf(' STATISTICS: SCAN [''S'']\n'), ...
			   sprintf(' LOG FILE: %s\n', LOGFILE), ...
				sprintf(' INDEX FILE: %s\n', INDFILE), ...
				sprintf(' TOTAL NUMBER OF PINGS: %d\n\n', NDATA));
	 case 'P',
		np = min(NDATA, START + NPINGS - 1);
		s = sprintf('%s%s%s%s%s%s', s, ...
			   sprintf(' STATISTICS: PING [''P'']\n'), ...
			   sprintf(' LOG FILE: %s\n', LOGFILE), ...
			   sprintf(' PINGS FROM: %d\n', START), ...
			   sprintf('         TO: %d\n', START + np), ...
			   sprintf(' TOTAL NUMBER OF PINGS: %d\n\n', np));
	 otherwise,
		error(['Unknown statistics ' stat]);
  end
end

if nargout == 0,
  sprintf('%s', s);
else
  varargout{1} = s;
end

return;


