function [ x, h, status ] = p00_step ( problem, option, nvar, x, par_index, ...
  h, hmin, hmax )

%*****************************************************************************80
%
%% p00_step() takes one continuation step.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    08 October 2008
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    integer PROBLEM, the problem index.
%
%    integer OPTION, the option index.
%
%    integer NVAR, the number of variables.
%
%    real X(NVAR), the starting point.
%
%    integer PAR_INDEX, the continuation parameter. 
%    If the program is free to choose this value, set it to 0.
%
%    real H, HMIN, HMAX, the suggested step, and the minimum
%    and maximum stepsizes.  H may be negative.
%
%  Output:
%
%    real X(NVAR), the new point, if STATUS = 0.
%
%    real H, the stepsize that was used.
%
%    integer STATUS, the status of the calculation.
%    nonnegative, successful.
%    negative, the Newton iteration failed repeatedly even when the
%    minimum stepsize was used.
%

%
%  Compute the tangent.
%
  tan = p00_tan ( problem, option, nvar, x );
%
%  Estimate the next point.
%
  h_reduction = 0

  while ( true )

    xt = x + h * tan;
%
%  Use the Newton method.
%
    [ xt, status ] = p00_newton ( problem, option, nvar, xt, par_index );
 
    if ( 0 <= status )

      if ( h_reduction == 0 )
        if ( status <= 1 )
          h = h * 4.0;
        elseif ( status <= 3 )
          h = h * 2.0;
        end
        if ( hmax < abs ( h ) )
          h = hmax * r8_sign ( h );
        end
      end

      break
    end

    if ( abs ( h ) <= hmin )
      break
    end

    if ( hmin < abs ( h ) )
      h = h / 2.0;
      if ( abs ( h ) < hmin )
        h = hmin * r8_sign ( h );
      end
      h_reduction = h_reduction + 1;
    end

  end

  x = xt;

  return
end
