function initp()
%------------------------------------------------------------------
% NAME
%
%   initp - Initialize scanning of log pings
%
% SYNOPSIS
%
%   initp
%
% DESCRIPTION
%
%   This function performs the following initializations:
%
%   1) Get the header (HDR) from the log file (LOGFILE)
%   2) Determine the number of columns (NCOL) from the header (HDR) 
%   3) Select which machine format (HOST) should be used for opening the
%      binary log file.
%   4) Set all limits (LIM) to default values
%
%------------------------------------------------------------------
%Time:<Last updated on 98/10/29 at 15:11:35 by jaccard@pc34.gfi.uib.no>
%File:</home1/jaccard/data1/codas3/gfi/matlab/matlab50/scan_bin/initp.m>

scanglob;

%--- Short cut to avoid initial scanning:
ft = fmodtime(strvcat(BINFILE, MATFILE), YEAR_BASE);
if (length(ft) > 1) & (ft(1) < ft(2)),
  load(MATFILE);
  fprintf('%s', STATSTR);
  return;
end

%--- Get header information from log file:
HDR   = get_hdr(LOGFILE);
NVARS = length(HDR);

%--- Find heading variables:
HDG = ones(1,NVARS) * NaN;
ii = 1:NVARS;
for i=ii,
  if ~isempty(findstr(HDR{i}, '[HDG]')),
	 HDG(i) = 0;
  end
end
  
%--- Select opening parameters:
if length(TYPE) == 0,
	TYPE = 'float64';
end
host = 'nlbdgcas';
HOST = [];
i = 1;
while (length(HOST) ~= 1) & (i < length(host)),
  fpbin = fopen(BINFILE, 'rb', host(i));
  d = fread(fpbin, 1, TYPE);
  if d == 1.0,
	 HOST = host(i);
  end
  i = i + 1;
  fclose(fpbin);
end
if length(HOST) ~= 1,
  error([ 'Cannot find opening parameters for binary file ' BINFILE ]);
end

%--- Set global limits:
str = limp(-1);
fprintf('%s', LIMSTR);

%--- Initialize statistics:
STAT = statinit(NVARS);

%--- Get initial statistics:
NTOT = statp;

%--- Save data into ascii file:
logp(10, STATSTR);

%--- Save global variables from initial scan
save(MATFILE, 'NVARS', 'HDR', 'HDG', 'STAT', 'HOST', 'TYPE', 'LIM', 'NTOT', ...
	 'STATSTR', 'LIMSTR');

return;






