function value = gennf ( dfn, dfd, xnonc )

%*****************************************************************************80
%
%% gennf() generates a noncentral F random deviate.
%
%  Discussion:
%
%    This procedure generates a random deviate from the noncentral F
%    (variance ratio) distribution with DFN degrees of freedom in the
%    numerator, and DFD degrees of freedom in the denominator, and
%    noncentrality parameter XNONC.
%
%    It directly generates the ratio of noncentral numerator chisquare variate
%    to central denominator chisquare variate.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    31 March 2013
%
%  Author:
%
%    Original FORTRAN77 version by Barry Brown, James Lovato.
%    MATLAB version by John Burkardt.
%
%  Input:
%
%    real DFN, the numerator degrees of freedom.
%    1.0 < DFN.
%
%    real DFD, the denominator degrees of freedom.
%    0.0 < DFD.
%
%    real XNONC, the noncentrality parameter.
%    0.0 <= XNONC.
%
%  Output:
%
%    real VALUE, a random deviate from the distribution.
%
  if ( dfn <= 1.0 )
    fprintf ( 1, ' \n' );
    fprintf ( 1, 'GENNF - Fatal error!\n' );
    fprintf ( 1, '  DFN <= 1.0\n' );
    error ( 'GENNF - Fatal error!\n' );
  end

  if ( dfd <= 0.0 )
    fprintf ( 1, ' \n' );
    fprintf ( 1, 'GENNF - Fatal error!\n' );
    fprintf ( 1, '  DFD <= 0.0\n' );
    error ( 'GENNF - Fatal error!\n' );
  end

  if ( xnonc < 0.0 )
    fprintf ( 1, ' \n' );
    fprintf ( 1, 'GENNF - Fatal error!\n' );
    fprintf ( 1, '  XNONC < 0.0\n' );
    error ( 'GENNF - Fatal error!\n' );
  end

  xnum = gennch ( dfn, xnonc ) / dfn;
  xden = genchi ( dfd ) / dfd;

  value = xnum / xden;

  return
end
