function r8st_diagonal_test ( )

%*****************************************************************************80
%
%% r8st_diagonal_test() tests r8st_diagonal().
%
%  Licensing:
%
%    This code is distributed under the MIT license. 
%
%  Modified:
%
%    21 September 2015
%
%  Author:
%
%    John Burkardt
%
  nz_num = 20;

  col = [ ...
    5, 6, 2, 2, 3, 4, 4, 5, 1, 6, ...
    4, 6, 5, 1, 6, 3, 1, 2, 1, 3 ];
  row = [ ...
    1, 3, 4, 6, 5, 2, 6, 3, 1, 2, ...
    4, 6, 5, 4, 4, 3, 6, 2, 3, 4 ];

  fprintf ( 1, '\n' );
  fprintf ( 1, 'r8st_diagonal_test():\n' );
  fprintf ( 1, '  r8st_diagonal() rearranges an r8st matrix\n' );
  fprintf ( 1, '  so that the diagonal is listed first.\n' );

  m = 6;
  n = 6;

  fprintf ( 1, '\n' );
  fprintf ( 1, '  Matrix order M =         %d\n', m );
  fprintf ( 1, '  Matrix order N =         %d\n', n );
  fprintf ( 1, '  Matrix nonzeros NZ_NUM = %d\n', nz_num );

  a = r8st_indicator ( m, n, nz_num, row, col );

  fprintf ( 1, '\n' );
  fprintf ( 1, '  Before rearrangement:\n' );
  fprintf ( 1, '         K    ROW(K)    COL(K)      A(K)\n' );
  fprintf ( 1, '\n' );
  for k = 1 : nz_num
    fprintf ( 1, '  %8d  %8d  %8d  %14.6g\n', k, row(k), col(k), a(k) );
  end

  [ row, col, a ] = r8st_diagonal ( m, n, nz_num, row, col, a );

  fprintf ( 1, '\n' );
  fprintf ( 1, '  After rearrangement:\n' );
  fprintf ( 1, '         K    ROW(K)    COL(K)      A(K)\n' );
  fprintf ( 1, '\n' );
  for k = 1 : nz_num
    fprintf ( 1, '  %8d  %8d  %8d  %14.6g\n', k, row(k), col(k), a(k) );
  end

  return
end
