function msm_to_mm_coordinate_complex_hermitian ( output_filename, a ) 

%*****************************************************************************80
%
%% msm_to_mm_coordinate_complex_hermitian() writes a "matrix coordinate complex hermitian" Matrix Market file.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    02 November 2008
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    string OUTPUT_FILENAME, the name of the file to which the information
%    should be written.
%
%    sparse matrix A, the NROW by NCOL matrix, stored in MATLAB sparse 
%    matrix format, which is to be written to the file.
%
  [ nrow, ncol ] = size ( a );
  nnzeros = nnz ( a );

  fid = fopen ( output_filename, 'wt+' );

  if ( fid < 0 ); 
    fprintf ( 1, '\n' );
    fprintf ( 1, 'MSM_TO_MM_COORDINATE_COMPLEX_HERMITIAN - Fatal error!\n' );
    fprintf ( 1, '  Cannot open the output file.\n' );
    error ( 'MSM_TO_MM_COORDINATE_COMPLEX_HERMITIAN - Fatal error!'); 
  end;

  fprintf ( fid, '%%%%MatrixMarket matrix coordinate complex hermitian\n');
  fprintf ( fid, '%%%%  Created by MSM_TO_MM_COORDINATE_COMPLEX_HERMITIAN.M\n' );
  fprintf ( fid, '  %d  %d  %d\n', nrow, ncol, nnzeros );

  for j = 1 : ncol
    [ rows, temp, vals ] = find ( a(:,j) );
    sz = size ( rows ); 
    for k2 = 1 : sz
      if ( j <= rows(k2) )
        fprintf ( fid, '  %d  %d  %f  %f\n', rows(k2), j, real ( vals(k2) ), imag ( vals(k2) ) );
      end
    end
    
  end

  fclose ( fid );

  return
end
