function triangle_symq_rule_convert ( p )

%*****************************************************************************80
%
%% triangle_symq_rule_convert() retrieves a rule and has it rewritten.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    25 September 2024
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    integer p: the precision of the rule that is to be rewritten.
%
  vert1 = [ 0.0, 0.0 ];
  vert2 = [ 1.0, 0.0 ];
  vert3 = [ 0.0, 1.0 ];
  
  n = rule_full_size ( p );

  [ xy, w ] = triasymq ( p, vert1, vert2, vert3, n );
  
  xy = xy';

  write_rule ( p, n, xy, w );

  return
end
function write_rule ( p, n, xy, w )

%*****************************************************************************80
%
%% write_rule() writes a rule to a file using barycentric coordinates.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    09 June 2023
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    integer p: the precision of the rule.
%
%    integer n: the number of points in the rule.
%
%    real xy(n,2): the coordinates of the quadrature points.
%
%    real w(n): the weights.
%
  filename = sprintf ( '../triangle_symq_rule/rule%02d.m', p );

  output = fopen ( filename, 'w' );

  function_name = sprintf ( 'rule%02d()', p );
  function_header = sprintf ( 'function [ a, b, c, w ] = rule%02d ( )', p );

  fprintf ( output, '%s\n', function_header );
  fprintf ( output, '\n' );
  fprintf ( output, '%%*****************************************************************************80\n' );
  fprintf ( output, '%%\n' );
  fprintf ( output, [ '%%%% ', function_name, ' returns the rule of precision ', num2str(p), '.\n' ] );
  fprintf ( output, '%%\n' );
  fprintf ( output, '%%  Licensing:\n' );
  fprintf ( output, '%%\n' );
  fprintf ( output, '%%    This code is distributed under the MIT license.\n' );
  fprintf ( output, '%%\n' );
  fprintf ( output, '%%  Modified:\n' );
  fprintf ( output, '%%\n' );
  fprintf ( output, '%%    09 June 2023\n' );
  fprintf ( output, '%%\n' );
  fprintf ( output, '%%  Author:\n' );
  fprintf ( output, '%%\n' );
  fprintf ( output, '%%    John Burkardt\n' );
  fprintf ( output, '%%\n' );
  fprintf ( output, '%%  Reference:\n' );
  fprintf ( output, '%%\n' );        
  fprintf ( output, '%%    Hong Xiao, Zydrunas Gimbutas,\n' );
  fprintf ( output, '%%    A numerical algorithm for the construction of efficient\n' );  
  fprintf ( output, '%%    quadrature rules in two and higher dimensions, \n' );  
  fprintf ( output, '%%    Computers and Mathematics with Applications,\n' );
  fprintf ( output, '%%    Volume 59, 2010, pages 663-676.\n' );
  fprintf ( output, '%%\n' );
  fprintf ( output, '%%  Output:\n' );
  fprintf ( output, '%%\n' );
  fprintf ( output, '%%    real a(n), b(n), c(n): the barycentric coordinates of quadrature points.\n' );
  fprintf ( output, '%%\n' );
  fprintf ( output, '%%    real w(n): the quadrature weights.\n' );
  fprintf ( output, '%%\n' );

  a = xy(:,1);
  fprintf ( output, '  a = [ ...\n' );
  for i = 1 : n - 1
    fprintf ( output, '    %24.16f, ...\n', a(i) );
  end
  fprintf ( output, '    %24.16f ];\n', a(n) );

  b = xy(:,2);
  fprintf ( output, '\n' );
  fprintf ( output, '  b = [ ...\n' );
  for i = 1 : n - 1
    fprintf ( output, '    %24.16f, ...\n', b(i) );
  end
  fprintf ( output, '    %24.16f ];\n', b(n) );

  c = 1.0 - a - b;
  fprintf ( output, '\n' );
  fprintf ( output, '  c = [ ...\n' );
  for i = 1 : n - 1
    fprintf ( output, '    %24.16f, ...\n', c(i) );
  end
  fprintf ( output, '    %24.16f ];\n', c(n) );

  w = 2.0 * w;
  fprintf ( output, '\n' );
  fprintf ( output, '  w = [ ...\n' );
  for i = 1 : n - 1
    fprintf ( output, '    %24.16f, ...\n', w(i) );
  end
  fprintf ( output, '    %24.16f ];\n', w(n) );

  fprintf ( output, '\n' );
  fprintf ( output, '  return\n' );
  fprintf ( output, 'end\n' );

  fclose ( output );

  fprintf ( 1, '  Created "%s"\n', filename );

  return
end

