function i4st_write ( filename, m, n, nst, ist, jst, ast )

%*****************************************************************************80
%
%% i4st_write() writes an I4ST file.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    27 September 2018
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    string 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.
%
%    integer AST(NST), the nonzero values.
%
  output = fopen ( filename, 'wt' );

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

  for k = 1 : nst

    fprintf ( output, '  %d  %d  %d\n', ist(k), jst(k), ast(k) );

  end

  fclose ( output );

  return
end
