function a = r8col_sort_heap_a ( m, n, a )
%*****************************************************************************80
%
%% R8COL_SORT_HEAP_A ascending heapsorts an R8COL.
%
% Discussion:
%
% An R8COL is an M by N array of R8's, regarded as an array of N columns,
% each of length M.
%
% In lexicographic order, the statement "X < Y", applied to two real
% vectors X and Y of length M, means that there is some index I, with
% 1 <= I <= M, with the property that
%
% X(J) = Y(J) for J < I,
% and
% X(I) < Y(I).
%
% In other words, the first time they differ, X is smaller.
%
% For large arrays, this code is much slower than the builtin
% MATLAB "sortrows" function. To use sortrows, just transpose your data
% before and after the call:
%
% a = ( sortrows ( a' ) )';
%
% Licensing:
%
% This code is distributed under the GNU LGPL license.
%
% Modified:
%
% 13 February 2011
%
% Author:
%
% John Burkardt
%
% Input:
%
% integer M, N, the number of rows and columns.
%
% real A(M,N), the array of N columns of M-vectors.
%
% Output:
%
% real A(M,N), the columns of A have been sorted.
%
if ( m <= 0 )
return
end
if ( n <= 1 )
return
end
%
% Initialize.
%
i = 0;
indx = 0;
isgn = 0;
j = 0;
%
% Call the external heap sorter.
%
while ( true )
[ indx, i, j ] = sort_heap_external ( n, indx, isgn );
%
% Interchange the I and J objects.
%
if ( 0 < indx )
a = r8col_swap ( m, n, a, i, j );
%
% Compare the I and J objects.
%
elseif ( indx < 0 )
isgn = r8col_compare ( m, n, a, i, j );
elseif ( indx == 0 )
break
end
end
return
end