function ring_data_write ( m, p, id, filename )

%*****************************************************************************80
%
%% ring_data_write() writes the ring data to a file.
%
%  Discussion:
%
%    Each data line records x, y, id.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    11 September 2018
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    integer M, the number of points.
%
%    real P(M,2), the ring data.
%
%    integer ID(M), an identifier for the ring.
%
%    string FILENAME, the output filename.
%

%
%  Open the file.
%
  output = fopen ( filename, 'wt' );

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

  for i = 1 : m
    fprintf ( output, '  %g  %g  %d\n', p(i,1), p(i,2), id(i) );
  end
%
%  Close the file.
%
  fclose ( output );

  return
end
