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

%*****************************************************************************80
%
%% I4ST_WRITE writes an I4ST file.
%
%  Licensing:
%
%    This code is distributed under the GNU LGPL license.
%
%  Modified:
%
%    27 September 2018
%
%  Author:
%
%    John Burkardt
%
%  Parameters:
%
%    Input, string FILENAME, the name of the file.
%
%    Input, integer M, the number of rows.
%
%    Input, integer N, the number of columns.
%
%    Input, integer NST, the number of nonzeros.
%
%    Input, integer IST(NST), JST(NST), the row and column indices.
%
%    Input, 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
