function tau = trig_cardinal ( xi, xdj, nd, h )

%*****************************************************************************80
%
%% trig_cardinal() evaluates a trigonometric cardinal function.
%
%  Discussion:
%
%    The trigonometric cardinal functions are similar to a Lagrange
%    polynomial basis, in that each function vanishes at all but one
%    data node.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    24 August 2019
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    real XI(NI), interpolation points.
%
%    real XDJ, one of a set of ND equally spaced data nodes.
%
%    integer ND, the number of data nodes.
%
%  Output:
%
%    real TAU(NI), the value of the cardinal trigonometric function 
%    associated with node XDJ at the interpolation nodes.
%
  ws = warning ( 'off', 'MATLAB:divideByZero' );

  if ( rem ( nd, 2 ) == 1 )
    tau =      sin ( pi * ( xi - xdj ) / h ) ./ ...
        ( nd * sin ( pi * ( xi - xdj ) / h / nd ) );
  else
    tau =      sin ( pi * ( xi - xdj ) / h ) ./ ...
        ( nd * tan ( pi * ( xi - xdj ) / h / nd ) );
  end

  warning ( ws )
%
%  Fix value at xi=xdj.
%
  tau ( xi == xdj ) = 1.0;

  return
end

