function h_to_xyz_test ( )

%*****************************************************************************80
%
%% h_to_xyz_test() tests h_to_xyz().
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    22 August 2024
%
%  Author:
%
%    John Burkardt
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'h_to_xyz_test():\n' );
  fprintf ( 1, '  h_to_xyz() converts a Hilbert 3D curve coordinate H \n' );
  fprintf ( 1, '  within a cube of side 2^r into (x,y,z) coordinates\n' );

  r = 1;
        
  fprintf ( 1, '\n' );
  fprintf ( 1, '  For r = %d\n', r );
  fprintf ( 1, '   h   x   y   z\n' );
  fprintf ( 1, '\n' );

  hmax = 2^(3*r)-1;
  for h = 0 : hmax
    [ x, y, z ] = h_to_xyz ( h, r );
    fprintf ( 1, '  %2d  %2d  %2d  %2d\n', h, x, y, z );
  end

  xvec = zeros ( hmax + 1, 1 );
  yvec = zeros ( hmax + 1, 1 );
  zvec = zeros ( hmax + 1, 1 );

  for h = 0 : hmax
    [ x, y, z ] = h_to_xyz ( h, r );
    xvec(h+1) = x;
    yvec(h+1) = y;
    zvec(h+1) = z;
  end

  clf ( );
  plot3 ( xvec, yvec, zvec, 'linewidth', 3 );
  grid ( 'on' );
  xlabel ( '<-- X -->' );
  ylabel ( '<-- Y -->' );
  zlabel ( '<-- Z -->' );
  title ( 'HIlbert curve, r = 1' );
  view ( 3 );
  filename = 'hilbert_curve_3d_r1.png';
  print ( '-dpng', filename );
  fprintf ( 1, '  Graphics saved as "%s"\n', filename );
%
%  Make level 2 curve.
%
  r = 2;
        
  fprintf ( 1, '\n' );
  fprintf ( 1, '  For r = %d\n', r );
  fprintf ( 1, '   h   x   y   z\n' );
  fprintf ( 1, '\n' );

  hmax = 2^(3*r)-1;
  for h = 0 : hmax
    [ x, y, z ] = h_to_xyz ( h, r );
    fprintf ( 1, '  %2d  %2d  %2d  %2d\n', h, x, y, z );
  end

  xvec = zeros ( hmax + 1, 1 );
  yvec = zeros ( hmax + 1, 1 );
  zvec = zeros ( hmax + 1, 1 );

  for h = 0 : hmax
    [ x, y, z ] = h_to_xyz ( h, r );
    xvec(h+1) = x;
    yvec(h+1) = y;
    zvec(h+1) = z;
  end

  clf ( );
  plot3 ( xvec, yvec, zvec, 'linewidth', 3 );
  grid ( 'on' );
  xlabel ( '<-- X -->' );
  ylabel ( '<-- Y -->' );
  zlabel ( '<-- Z -->' );
  title ( 'HIlbert curve, r = 2' );
  view ( 3 );
  filename = 'hilbert_curve_3d_r2.png';
  print ( '-dpng', filename );
  fprintf ( 1, '  Graphics saved as "%s"\n', filename );

  return
end

