function value = r8_inits ( dos, nos, eta )

%*****************************************************************************80
%
%% R8_INITS initializes a Chebyshev series.
%
%  Licensing:
%
%    This code is distributed under the GNU LGPL license.
%
%  Modified:
%
%    22 April 2016
%
%  Author:
%
%    MATLAB version by John Burkardt.
%
%  Reference:
%
%    Roger Broucke,
%    Algorithm 446:
%    Ten Subroutines for the Manipulation of Chebyshev Series,
%    Communications of the ACM,
%    Volume 16, Number 4, April 1973, pages 254-256.
%
%  Parameters:
%
%    Input, real DOS(NOS), the Chebyshev coefficients.
%
%    Input, integer NOS, the number of coefficients.
%
%    Input, real ETA, the desired accuracy.
%
%    Output, integer VALUE, the number of terms of the series needed
%    to ensure the requested accuracy.
%
  if ( nos < 1 )
    fprintf ( 1, '\n' );
    fprintf ( 1, 'R8_INITS - Fatal error!\n' );
    fprintf ( 1, '  Number of coefficients < 1.\n' );
    error ( 'R8_INITS - Fatal error!' )
  end

  if ( eta < dos(nos) )

    fprintf ( 1, '\n' );
    fprintf ( 1, 'R8_INITS - Warning!\n' );
    fprintf ( 1, '  ETA may be too small.\n' );
    fprintf ( 1, '  The requested accuracy cannot be guaranteed\n' );
    fprintf ( 1, '  even if all available coefficients are used.\n' );
    value = nos;

  else

    err = 0.0;

    for i = nos : -1 : 1
      value = i;
      err = err + abs ( dos(value) );
      if ( eta < err )
        break
      end
    end

  end

  return
end
