function sort_heap_external_test ( )

%*****************************************************************************80
%
%% SORT_HEAP_EXTERNAL_TEST tests SORT_HEAP_EXTERNAL.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    15 June 2015
%
%  Author:
%
%    John Burkardt
%
  n = 20;

  fprintf ( 1, '\n' );
  fprintf ( 1, 'SORT_HEAP_EXTERNAL_TEST\n' );
  fprintf ( 1, '  SORT_HEAP_EXTERNAL sorts objects externally.\n' );

  seed = 123456789;

  [ a, seed ] = i4vec_uniform_ab ( n, 1, n, seed );

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

  indx = 0;
  isgn = 0;
  i1 = 0;
  j1 = 0;
  k0 = 0;
  k1 = 0;
  n1 = 0;

  while ( true )

    [ indx, i, j, i1, j1, k0, k1, n1 ] = sort_heap_external ( n, indx, ...
      isgn, i1, j1, k0, k1, n1 );

    if ( indx < 0 )
      isgn = 1;
      if ( a(i) <= a(j) )
        isgn = -1;
      end 
    elseif ( 0 < indx )
      t = a(i);
      a(i) = a(j);
      a(j) = t;
    else
      break;
    end

  end

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

  return
end
