function r8st_write ( output_filename, m, n, nst, ist, jst, ast )

%*****************************************************************************80
%
%% r8st_write() writes an R8ST file.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    23 July 2014
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    string OUTPUT_FILENAME, the name of the file.
%
%    integer M, the number of rows.
%
%    integer N, the number of columns.
%
%    integer NST, the number of nonzeros.
%
%    integer IST(NST), JST(NST), the row and column indices.
%
%    real AST(NST), the nonzero values.
%
  output_unit = fopen ( output_filename, 'wt' );

  if ( output_unit < 0 ) 
    fprintf ( 1, '\n' );
    fprintf ( 1, 'R8ST_WRITE - Error!\n' );
    fprintf ( 1, '  Could not open the output file.\n' );
    error ( 'R8ST_WRITE - Error!' );
    return;
  end

  for k = 1 : nst

    fprintf ( output_unit, '  %8d  %8d  %16.8f\n', ist(k), jst(k), ast(k) );

  end

  fclose ( output_unit );

  return
end
