function hb_file_write ( output_unit, title, key, totcrd, ptrcrd, indcrd, ...
  valcrd, rhscrd, mxtype, nrow, ncol, nnzero, neltvl, ptrfmt, indfmt, ...
  valfmt, rhsfmt, rhstyp, nrhs, nrhsix, colptr, rowind, values, ...
  rhsval, rhsptr, rhsind, rhsvec, guess, exact )

%*****************************************************************************80
%
%% HB_FILE_WRITE writes an HB file.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    11 November 2003
%
%  Author:
%
%    John Burkardt
%
%  Reference:
%
%    Iain Duff, Roger Grimes, John Lewis,
%    User's Guide for the Harwell-Boeing Sparse Matrix Collection,
%    October 1992.
%
%  Input:
%
%    integer OUTPUT_UNIT, the unit to which data is written.
%
%    character ( len = 72 ) TITLE, a title for the matrix.
%
%    character ( len = 8 ) KEY, an identifier for the matrix.
%
%    integer TOTCRD, the total number of lines of data.
%
%    integer PTRCRD, the number of input lines for pointers.
%
%    integer INDCRD, the number of input lines for row indices.
%
%    integer VALCRD, the number of input lines for numerical values.
%
%    integer RHSCRD, the number of input lines for right hand sides.
%
%    character ( len = 3 ) MXTYPE, the matrix type.
%    First character is R for Real, C for complex, P for pattern only.
%    Second character is S for symmetric, U for unsymmetric, H for
%      Hermitian, Z for skew symmetric, R for rectangular.
%    Third character is A for assembled and E for unassembled
%      finite element matrices.
%
%    integer NROW, the number of rows or variables.
%
%    integer NCOL, the number of columns or elements.
%
%    integer NNZERO.  In the case of assembled sparse matrices,
%    this is the number of nonzeroes.  In the case of unassembled finite
%    element matrices, in which the right hand side vectors are also
%    stored as unassembled finite element vectors, this is the total
%    number of entries in a single unassembled right hand side vector.
%
%    integer NELTVL, the number of finite element matrix entries,
%    set to 0 in the case of assembled matrices.
%
%    character ( len = 16 ) PTRFMT, the format for reading pointers.
%
%    character ( len = 16 ) INDFMT, the format for reading indices.
%
%    character ( len = 20 ) VALFMT, the format for reading values.
%
%    character ( len = 20 ) RHSFMT, the format for reading values
%    of the right hand side.
%
%    character ( len = 3 ) RHSTYP, the right hand side type.
%    First character is F for full storage or M for same as matrix.
%    Second character is G if starting "guess" vectors are supplied.
%    Third character is X if exact solution vectors are supplied.
%    Ignored if NRHS = 0.
%
%    integer NRHS, the number of right hand sides.
%
%    integer NRHSIX, the number of row indices (set to 0
%    in the case of unassembled matrices.)  Ignored if NRHS = 0.
%
%    integer COLPTR(NCOL+1), COLPTR(I) points to the location of
%    the first entry of column I in the sparse matrix structure.
%
%    integer ROWIND(NNZERO) or ROWIND(NELTVL), the row index of
%    each item.
%
%    real VALUES(NNZERO) or VALUES(NELTVL), the nonzero values
%    of the matrix.
%
%    If RHSTYP(1:1) == 'F':
%
%      real RHSVAL(NROW,NRHS), contains NRHS dense right hand
%      side vectors.
%
%      integer RHSPTR(*), is not used.
%
%      integer RHSIND(*), is not used.
%
%      real RHSVEC(*), is not used.
%
%    If RHSTYP(1:1) = 'M' and MXTYPE(3:3) = 'A':
%
%      real RHSVAL(NROW,NRHS), is not used.
%
%      integer RHSPTR(NRHS+1), RHSPTR(I) points to the location of
%      the first entry of right hand side I in the sparse right hand
%      side vector.
%
%      integer RHSIND(NRHSIX), indicates, for each entry of
%      RHSVAL, the corresponding row index.
%
%      real RHSVEC(NRHSIX), contains the value of the right hand
%      side entries.
%
%    If RHSTYP(1:1) = 'M' and MXTYPE(3:3) = 'E':
%
%      real RHSVAL(NNZERO,NRHS), contains NRHS unassembled
%      finite element vector right hand sides.
%
%      integer RHSPTR(*), is not used.
%
%      integer RHSIND(*), is not used.
%
%      real RHSVEC(*), is not used.
%
%    real GUESS(NROW,NRHS), the starting guess vectors.
%
%    real EXACT(NROW,NRHS), the exact solution vectors.
%

%
%  Write the header block.
%
  hb_header_write ( output_unit, title, key, totcrd, ptrcrd, indcrd, ...
    valcrd, rhscrd, mxtype, nrow, ncol, nnzero, neltvl, ptrfmt, indfmt, ...
    valfmt, rhsfmt, rhstyp, nrhs, nrhsix );
%
%  Write the matrix structure.
%
  hb_structure_write ( output_unit, ncol, mxtype, nnzero, neltvl, ...
    ptrfmt, indfmt, colptr, rowind );
%
%  Write the matrix values.
%
  hb_values_write ( output_unit, valcrd, mxtype, nnzero, neltvl, ...
    valfmt, values );
%
%  Write the right hand sides.
%
  hb_rhs_write ( output_unit, nrow, nnzero, nrhs, nrhsix, ...
    rhscrd, ptrfmt, indfmt, rhsfmt, mxtype, rhstyp, rhsval, ...
    rhsind, rhsptr, rhsvec );
%
%  Write the starting guesses.
%
  hb_guess_write ( output_unit, nrow, nrhs, rhscrd, rhsfmt, rhstyp, ...
    guess );
%
%  Write the exact solutions.
%
  hb_exact_write ( output_unit, nrow, nrhs, rhscrd, rhsfmt, rhstyp, ...
    exact );

  return
end
