function ccs_write ( prefix, nz_num, col, row, a )

%*****************************************************************************80
%
%% ccs_write() writes a ccs matrix to three files.
%
%  Discussion:
%
%    The ccs format is the double precision sparse compressed column
%    format.  Associated with this format, we have an M by N matrix
%    with NZ_NUM nonzero entries.  We construct the column pointer
%    vector COL of length N+1, such that entries of column J will be
%    stored in positions COL(J) through COL(J+1)-1.  This indexing
%    refers to both the ROW and A vectors, which store the row indices
%    and the values of the nonzero entries.  The entries of the
%    ROW vector corresponding to each column are assumed to be
%    ascending sorted.
%
%    The ccs format is equivalent to the MATLAB "sparse" format,
%    and the Harwell Boeing "real unsymmetric assembled" (RUA) format.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    02 September 2006
%
%  Author:
%
%    John Burkardt
%
%  Reference:
%
%    Iain Duff, Roger Grimes, John Lewis,
%    User's Guide for the Harwell-Boeing Sparse Matrix Collection,
%    October 1992
%
%  Input:
%
%    string prefix: the prefix used for the names of the column pointers,
%    row indices, and matrix values.
%
%    integer M, N, the number of rows and columns in the matrix.
%
%    integer NZ_NUM, the number of nonzero elements in the matrix.
%
%    integer COL(N+1), the column pointers.
%
%    integer ROW(NZ_NUM), the row indices.
%
%    real A(NZ_NUM), the nonzero elements of the matrix.
%

%
%  Write the column information.
%
  col_file = sprintf ( '%s_col.txt', prefix );
  output_unit = fopen ( col_file, 'wt' );

  if ( output_unit < 0 )
    fprintf ( 1, '\n' );
    fprintf ( 1, 'ccs_write(): Fatal error!\n' );
    fprintf ( 1, '  Could not open the output file "%s".\n', col_file );
    error ( 'ccs_write(): Fatal error!' );
  end

  n = length ( col ) - 1;
  for k = 1 : n + 1
    fprintf ( output_unit, '%8d\n', col(k) );
  end

  fclose ( output_unit );
%
%  Write the row information.
%
  row_file = sprintf ( '%s_row.txt', prefix );
  output_unit = fopen ( row_file, 'wt' );

  if ( output_unit < 0 )
    fprintf ( 1, '\n' );
    fprintf ( 1, 'ccs_write(): Fatal error!\n' );
    fprintf ( 1, '  Could not open the output file "%s".\n', row_file );
    error ( 'ccs_write(): Fatal error!' );
  end

  for k = 1 : nz_num

    fprintf ( output_unit, '%8d\n', row(k) );

  end

  fclose ( output_unit );
%
%  Write the value information.
%
  value_file = sprintf ( '%s_val.txt', prefix );
  output_unit = fopen ( value_file, 'wt' );

  if ( output_unit < 0 )
    fprintf ( 1, '\n' );
    fprintf ( 1, 'ccs_write(): Fatal error!\n' );
    fprintf ( 1, '  Could not open the output file "%s".\n', value_file );
    error ( 'ccs_write(): Fatal error!' );
  end

  for k = 1 : nz_num

    fprintf ( output_unit, '%14f\n', a(k) );

  end

  fclose ( output_unit );

  return
end
