function [ n_data, n, k, pik ] = elliptic_pik_values ( n_data )

%*****************************************************************************80
%
%% elliptic_pik_values() returns values of the complete elliptic integral Pi(N,K).
%
%  Discussion:
%
%    This is one form of what is sometimes called the complete elliptic integral
%    of the third kind.
%
%    The function is defined by the formula:
%
%      Pi(N,K) = integral ( 0 <= T <= PI/2 ) 
%        dT / (1 - N sin^2(T) ) sqrt ( 1 - K^2 * sin ( T )^2 )
%
%    In MATLAB, the function can be evaluated by:
%
%      ellipticPi(n,k^2)
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    30 May 2018
%
%  Author:
%
%    John Burkardt
%
%  Reference:
%
%    Milton Abramowitz and Irene Stegun,
%    Handbook of Mathematical Functions,
%    US Department of Commerce, 1964.
%
%    Stephen Wolfram,
%    The Mathematica Book,
%    Fourth Edition,
%    Wolfram Media / Cambridge University Press, 1999.
%
%  Input:
%
%    integer N_DATA.  The user sets N_DATA to 0 before the first call.  
%    Thereafter, it should simply be the value returned by the previous call.
%
%  Output:
%
%    integer N_DATA.  On each call, the routine increments N_DATA by 1, and
%    returns the corresponding data; when there is no more data, the
%    output value of N_DATA will be 0 again.
%
%    real N, K, the arguments of the function.
%
%    real PIK, the value of the function.
%
  n_max = 20;

  k_vec = [ ...
    0.5000000000000000, ...
    0.7071067811865476, ...
    0.8660254037844386, ...
    0.9746794344808963, ...
    0.5000000000000000, ...
    0.7071067811865476, ...
    0.8660254037844386, ...
    0.9746794344808963, ...
    0.5000000000000000, ...
    0.7071067811865476, ...
    0.8660254037844386, ...
    0.9746794344808963, ...
    0.5000000000000000, ...
    0.7071067811865476, ...
    0.8660254037844386, ...
    0.9746794344808963, ...
    0.5000000000000000, ...
    0.7071067811865476, ...
    0.8660254037844386, ...
    0.9746794344808963 ];

  n_vec = [ ...
    -10.0, ...
    -10.0, ...
    -10.0, ...
    -10.0, ...
     -3.0, ...
     -3.0, ...
     -3.0, ...
     -3.0, ...
     -1.0, ...
     -1.0, ...
     -1.0, ...
     -1.0, ...
      0.0, ...
      0.0, ...
      0.0, ...
      0.0, ...
      0.5, ...
      0.5, ...
      0.5, ...
      0.5  ];

  pik_vec = [ ...
    0.4892245275965397, ...
    0.5106765677902629, ...
    0.5460409271920561, ...
    0.6237325893535237, ...
    0.823045542660675,  ...
    0.8760028274011437, ...
    0.9660073560143946, ...
    1.171952391481798, ...
    1.177446843000566, ...
    1.273127366749682, ...
    1.440034318657551, ...
    1.836472172302591, ...
    1.685750354812596, ...
    1.854074677301372, ...
    2.156515647499643, ...
    2.908337248444552, ...
    2.413671504201195, ...
    2.701287762095351, ...
    3.234773471249465, ...
    4.633308147279891 ];

  if ( n_data < 0 )
    n_data = 0;
  end

  n_data = n_data + 1;

  if ( n_max < n_data )
    n_data = 0;
    k = 0.0;
    n = 0.0;
    pik = 0.0;
  else
    k = k_vec(n_data);
    n = n_vec(n_data);
    pik = pik_vec(n_data);
  end

  return
end
