function value = trig_interp_basis ( x, k )

%*****************************************************************************80
%
%% trig_interp_basis() evaluates a trigonometric cardinal basis function.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    20 October 2022
%
%  Author:
%
%    Original MATLAB code from Wikipedia page "Trigonometric interpolation",
%    attributed to Richard Braun at the University of Delaware.
%
%  Input:
%
%    real x(*), the evaluation points.
%
%    integer k, the order of the cardinal function.
%    K should be 1 or greater.
%
%  Output:
%
%    real value(*), the value of the cardinal function at the points.
%    

%
%  Suppress the "divide by zero" warning.
%
  ws = warning ( 'off', 'MATLAB:divideByZero' );

  if ( rem ( k, 2 ) == 1 )
    value =      sin ( k * pi * x / 2.0 ) ...
        ./ ( k * sin (     pi * x / 2.0 ) );
  else
    value =      sin ( k * pi * x / 2.0 ) ...
        ./ ( k * tan (     pi * x / 2.0 ) );
  end
%
%  Restore the warning.
%
  warning ( ws );
%
%  Fix the value at 0.
%
  value ( x == 0.0 ) = 1.0;

  return
end

