function cplex_solution_read_test ( filename )

%*****************************************************************************80
%
%% CPLEX_SOLUTION_READ_TEST tests CPLEX_SOLUTION_READ.
%
%  Discussion:
%
%    The CPLEX XML data file is read, the solution data X is extracted,
%    X is printed, and a copy of the X array is written to a text file.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    05 July 2018
%
%  Author:
%
%    John Burkardt
%
%  Parameters:
%
%    Input, string FILENAME, the name of the file to be examined.
%
  timestamp ( );
  fprintf ( 1, '\n' );
  fprintf ( 1, 'CPLEX_SOLUTION_READ_TEST:\n' );
  fprintf ( 1, '  MATLAB/Octave version %s\n', version ( ) );
  fprintf ( 1, '  CPLEX_SOLUTION_READ reads the CPLEX XML file "%s"\n', filename );
%
%  Extract the solution data.
%
  x = cplex_solution_read ( filename );
%
%  Report the solutions.
%
  [ var_num, sol_num ] = size ( x );
  
  fprintf ( 1, '\n' );
  fprintf ( 1, '  %dx%d solution data:\n', var_num, sol_num );
  fprintf ( 1, '  Number of nonzero entries per column:\n' );
  for j = 1 : sol_num
    fprintf ( 1, '  %d', nnz ( x(:,j ) ) );
  end
  fprintf ( 1, '\n' );
  fprintf ( 1, '  Sum of entries per column:\n' );
  for j = 1 : sol_num
    fprintf ( 1, '  %d', sum ( x(:,j ) ) );
  end
  fprintf ( 1, '\n' );

  if ( var_num <= 100 )

    fprintf ( 1, '\n' );

    for i = 1 : var_num
      fprintf ( 1, '  %2d:  ', i );
      for j = 1 : sol_num
        fprintf ( 1, ' %2d', x(i,j) );
      end
      fprintf ( 1, '\n' );
    end

  else

    fprintf ( 1, '\n' );
    fprintf ( 1, '  The solution is large.  We won''t print it.\n' );

  end
%
%  Save X as a text file.
%
  [ filepath, name, extension ] = fileparts ( filename );
  filename2 = strcat ( name, '.txt' );

  output = fopen ( filename2, 'wt' );

  for i = 1 : var_num
    for j = 1 : sol_num
      fprintf ( output, '  %g', x(i,j) );
    end
    fprintf ( output, '\n' );
  end
  fclose ( output );

  fprintf ( 1, '\n' );
  fprintf ( 1, '  Wrote the ASCII file "%s"\n', filename2 );
%
%  Terminate.
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'CPLEX_SOLUTION_READ_TEST:\n' );
  fprintf ( 1, '  Normal end of execution.\n' );
  timestamp ( );

  return
end
