function value = elliptic_inc_fk ( phi, k )

%*****************************************************************************80
%
%% elliptic_inc_fk() evaluates the incomplete elliptic integral F(PHI,K).
%
%  Discussion:
%
%    The value is computed using Carlson elliptic integrals:
%
%      F(phi,k) = sin(phi) * RF ( cos^2 ( phi ), 1-k^2 sin^2 ( phi ), 1 ).
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    21 June 2018
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    real PHI, K, the arguments.
%    0 <= PHI <= PI/2.
%    0 <= K^2 <= 1 / sin^2 ( PHI )
%
%  Output:
%
%    real VALUE, the function value.
%
  sp = sin ( phi );
  cp = cos ( phi );

  x = cp ^ 2;
  y = ( 1.0 - k * sp ) * ( 1.0 + k * sp );
  z = 1.0;
  errtol = 1.0E-03;

  [ value, ierr ] = rf ( x, y, z, errtol );
  if ( ierr ~= 0 )
    fprintf ( 1, 'ELLIPTIC_INC_FK - Fatal error!\n' );
    fprintf ( 1, '  RF returned IERR = %d\n', ierr );
    error ( 'ELLIPTIC_INC_FK - Fatal error!' );
    return
  end

  value = sp * value;

  return
end
