function r8vec_index_search_test ( )

%*****************************************************************************80
%
%% r8lib_index_search_test() tests r8vec_index_search().
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    19 April 2009
%
%  Author:
%
%    John Burkardt
%
  n_max = 20;
  n = 0;
  x = [];
  indx = [];

  fprintf ( 1, '\n' );
  fprintf ( 1, 'r8vec_index_search_test()\n' );
  fprintf ( 1, '  R8VEC_INDEX_SEARCH searches for an entry\n' );
  fprintf ( 1, '  with a given value.\n' );
  fprintf ( 1, '\n' );
  fprintf ( 1, '  Generate some random values:\n' );
  fprintf ( 1, '\n' );

  for i = 1 : n_max
    xval = n_max * rand ( 1, 1 );
    xval = round ( xval );
    fprintf ( 1, '  %f\n', xval );
    [ n, x, indx ] = r8vec_index_insert_unique ( n, x, indx, xval );
  end

  fprintf ( 1, '\n' );
  fprintf ( 1, '  Indexed list of entries:\n' );
  fprintf ( 1, '\n' );
  fprintf ( 1, '  I  INDX(I)  X(I)  X(INDX(I))\n' );
  fprintf ( 1, '\n' );
  for i = 1 : n
    fprintf ( 1, '  %3d  %3d  %9f  %9f\n', i, indx(i), x(i), x(indx(i)) );
  end

  fprintf ( 1, '\n' );
  fprintf ( 1, '  Results of search for given XVAL:\n' );
  fprintf ( 1, '\n' );
  fprintf ( 1, '  XVAL  Less Equal More\n' );
  fprintf ( 1, '\n' );

  for i = 0 : n_max
    xval = i;
    [ less, equal, more ] = r8vec_index_search ( n, x, indx, xval );
    fprintf ( 1, '  %6f  %3d  %3d  %3d\n', xval, less, equal, more );
  end

  return
end
