function knnsearch_test ( )

%*****************************************************************************80
%
%% knnsearch_test() tests knnsearch().
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    14 October 2022
%
%  Author:
%
%    John Burkardt
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'knnsearch_test():\n' );
  fprintf ( 1, '  knnsearch() finds the nearest data value in a sorted list.\n' );

  nd = 11;
  xd = linspace ( 0, 10, nd );
  fprintf ( 1, '\n' );
  fprintf ( 1, '  xd:\n' );
  disp ( xd );

  ni = 6;
  xi = [ -10.1, 1.2, 4.5, 5.2, 10.4, 12.5 ];
  fprintf ( 1, '\n' );
  fprintf ( 1, '  xi:\n' );
  disp ( xi );

  idx = knnsearch ( xd, xi );

  fprintf ( 1, '\n' );
  fprintf ( 1, '  Item  Value  Index  Nearest\n' );
  fprintf ( 1, '\n' );
  for i = 1 : ni
    fprintf ( 1, '    %2d  %6.2f  %2d  %2d\n', i, xi(i), idx(i), xd(idx(i)) );
  end

  return
end
