function [iter] = zc_iter(f,tol)
%
%  This routine checks for need to iterate on zero-crossing function
%    f is the matrix of zero-crossing function values: f = [f1,f2]
%    tol is the required accuracy
%    iter = 0: don't iterate, no zero crossing
%         = 1: iterate, one or more than one zero crossings
%         < 0: don't iterate, one zero crossing converged on -iter
%
%  We start by unpacking the input variables
%
f1 = f(:,1);
f2 = f(:,2);
%
%  we need to check which of the zero-crossing functions are currently
%  active
%
iter = 0;
nbr_zcf = 0;
indx_zcf = 0;
[n,m] = size(f);
for i=1:n,
  if f1(i)*f2(i) < 0,
    nbr_zcf = nbr_zcf + 1;
    indx_zcf = i;
  end,
end
%
%  If multiple zero crossings occurred, we need to iterate
%
if nbr_zcf > 1,
  iter = 1;
  return,
end
%
%  If one zero-crossing function is active, check whether we got
%  convergence already
%
if nbr_zcf == 1,
  if abs(f2(indx_zcf)) < tol,
    iter = -indx_zcf;
   else
    iter = 1;
  end,
end
%
return