function catp(varargin)
% ------------------------------------------------------------------
% Catalog of log data.
%
% SYNOPSIS:
%
%   catp(move)
%
%      Catalog content of 'DATA' acccording to string 'move'. Possible
%      moves are:
%
%         '-fwd'     : forward one ping
%         '-ffwd'    : forward NCATP pings
%         '-rew'     : rewind one ping
%         '-rrew'    : rewind NCATP pings
%         '-refresh' : redisplay current pings
%         '-start'   : position cataloging to start
%         '-scroll'  : toggle scrolling
%
%   catp
%   catp(start)
%   catp(start, vars)
%
%      Catalog log pings, starting from ping number 'start' (default from
%      CATP_STARTP or 1) and displaying only pings from variable numbers
%      listed in column  vector 'vars' (default: all variables).
%
%   catp(0)
%
%		 Reset global variables from 'catp', and exit 'catp'.
%
% Normally, an uicontrol will be initialized to control cataloging of
% of log pings. All cataloging commands should be send to 'catp' through
% the button window, except for starting 'catp'. 
%
% ------------------------------------------------------------------
%Time:<Last updated on 98/10/06 at 16:58:09 by veins@TORSK>
%File:<c:/codas3/gfi/matlab/matlab50/scan_bin/catp.m>

scanglob;

%--- Arguments:
if (nargin == 1) & ~isstr(varargin{1}) & (varargin{1} == 0),
  DATA = [];
  CATP_SCROLL = 0;
  CATP_STARTP = 1;
  CATP_VARS   = 1:NVARS;
  return;
end

move = '-refresh';
if isempty(CATP_VARS),
  CATP_VARS = 1:NVARS;
end
if isempty(CATP_STARTP),
  CATP_STARTP = 1;
end

%--- Move argument:
if (nargin == 1) & isstr(varargin{1}),
  move = varargin{1};
end

%--- Initial arguments:
if (nargin > 0) & ~isstr(varargin{1}) & (varargin{1} > 0),
  CATP_STARTP = varargin{1};
end
if nargin > 1,
  CATP_VARS = varargin{2};
end		

%--- Initialize UIC:
if isempty(CATP_UIC_),
  CATP_SCROLL = 0;
  catp_uic;
end

%--- Update scrolling:
if strcmp(move, '-scroll'),
  CATP_SCROLL = ~CATP_SCROLL;
  return;
end

%--- Loop through the data:
done = 0;
while ~done,

  %--- Update start ping:
  switch move
	 case '-start',
		CATP_SCROLL = 0;
		CATP_STARTP = 1;
	 case '-refresh',
		CATP_SCROLL = 0;
		CATP_STARTP;
	 case '-fwd',
		CATP_STARTP = CATP_STARTP + 1;
	 case '-ffwd',
		CATP_STARTP = CATP_STARTP + NCATP;
	 case '-rew',
		CATP_STARTP = CATP_STARTP - 1;
	 case '-rrew',
		CATP_STARTP = CATP_STARTP - NCATP;
	 otherwise,
		error([ 'Unknown option ' move]);
  end
  CATP_STARTP = max([ 1, CATP_STARTP ]);
  CATP_STARTP = min([ CATP_STARTP, NTOT-NCATP+1 ]);
  %--- Get the data:
  [err, DATA] = getp(-CATP_STARTP, NCATP);
  if err > 0,
	 error([ 'Error while reading pings' ]);
  elseif err == -1,
	 CATP_SCROLL = 0;
	 fprintf('\n\n\t AT EOF ... \n\n');
  end
  
  %--- Flag data:
  [DATA, flags] = flagdata(DATA, LIM, '-hdg', HDG);
 
  %--- Display data:
  fprintf('\n%s\n\n', ...
		'------------------------------------------------------------------');
  ii = 1:size(DATA,2);
  for i=ii,
	 jj = 1:length(CATP_VARS);
	 for j=jj,
		fprintf('%10.5f ', DATA(CATP_VARS(j),i));
	 end
	 fprintf('\n');
  end
  
  %--- Check for scrolling interruptions:
  catp_uic('catp_interrupt'); 

  %--- Loop exit flag:
  if CATP_SCROLL <= 0,
	 done = 1;
  end
  
end

return;

