function hilbert_curve_display ( m )

%*****************************************************************************80
%
%% HILBERT_CURVE_DISPLAY displays a Hilbert Curve.
%
%  Discussion:
%
%    The Hilbert curve of index M connects the cells labeled D = 0 through 
%    D = N * N - 1, by a path that joins neighboring cells.  Here N = 2^M,
%    and the cells lie in an NxN grid.
%
%  Licensing:
%
%    This code is distributed under the GNU LGPL license.
%
%  Modified:
%
%    05 October 2017
%
%  Author:
%
%    John Burkardt
%
%  Parameters:
%
%    Input, integer M, the index of the Hilbert curve.
%    The number of cells is N=2^M.
%    0 < M.
%
%    Input, integer D, the Hilbert coordinate of the cell.
%    0 <= D < N * N.
%
%    Output, integer X, Y, the Cartesian coordinates of the cell.
%    0 <= X, Y < N.
%
  if ( m <= 0 )
    fprintf ( 1, '\n' );
    fprintf ( 1, 'HILBERT_CURVE_DISPLAY - Fatal error!\n' );
    fprintf ( 1, '  0 < M required.\n' );
    fprintf ( 1, '  M = %d\n', m );
    error ( 'HILBERT_CURVE_DISPLAY: Fatal error!' );
  end

  n = 2^m;
  nn = n * n;

  clf
  hold on
  axis ( [ -0.5, n-0.5, -0.5, n-0.5 ] );

  for k = 0 : nn - 1

    if ( 0 < k )
      xold = xnew;
      yold = ynew;
    end

    [ xnew, ynew ] = d2xy ( m, k );

    if ( 0 < k )
      plot ( [ xold, xnew ], [ yold, ynew ], 'b-', 'LineWidth', 2 );
    end

  end

  hold off
  axis equal
  axis off

  return
end
