function i4vec_sort_heap_index_d_test (  )

%*****************************************************************************80
%
%% i4vec_sort_heap_index_d_test() tests i4vec_sort_heap_index_d().
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    14 February 2003
%
%  Author:
%
%    John Burkardt
%
  n = 20;

  fprintf ( 1, '\n' );
  fprintf ( 1, 'i4vec_sort_heap_index_d_test():\n' );
  fprintf ( 1, '  i4vec_sort_heap_index_d() creates a descending\n' );
  fprintf ( 1, '  sort index for an integer array.\n' );

  a = randi ( [ 0, 3*n ], n );

  i4vec_print ( n, a, '  Unsorted array:' );

  indx = i4vec_sort_heap_index_d ( n, a );

  i4vec_print ( n, indx, '  Sort vector INDX:' );

  fprintf ( 1, '\n' );
  fprintf ( 1, '  I, INDX(I), A(INDX(I))\n' );
  fprintf ( 1, '\n' );
  for i = 1 : n
    fprintf ( 1, '  %8d  %8d  %8d\n', i, indx(i), a(indx(i)) );
  end

  return
end
