function cc_levels_constrained_animate ( )

%*****************************************************************************80
%
%% CC_LEVELS_CONSTRAINED_ANIMATE displays a sequence of grids generated by CC_LEVELS_CONSTRAINED.
%
%  Licensing:
%
%    This code is distributed under the GNU LGPL license.
%
%  Modified:
%
%    15 November 2006
%
%  Author:
%
%    John Burkardt
%
  fprintf ( 1, '\n' );
  timestamp ( );

  fprintf ( 1, '\n' );
  fprintf ( 1, 'CC_LEVELS_CONSTRAINED_ANIMATE:\n' );
  fprintf ( 1, '  MATLAB version\n' );
  fprintf ( 1, '  Display the 2D Clenshaw-Curtis grids\n' );
  fprintf ( 1, '  generated by CC_LEVELS_CONSTRAINED.\n' );

  dim_num = 2;
  level_min(1:dim_num) = 0;
 
  while ( 1 )
%
%  Get user input.
%
    q_max = input ( 'Enter Q_MAX or RETURN to exit;' );
    
    if ( isempty ( q_max ) )
      break
    end
    
    alpha = input ( 'Enter [ ALPHA1, ALPHA2 ] or RETURN to exit;' );
    
    if ( isempty ( alpha ) )
      break
    end

    level_max(1:2) = [ q_max / alpha(1), q_max / alpha(2) ];
%
%  Compute data.
%
    grid_points_old = [];
    grid_points_old_num = 0;

    grid_points = [];
    grid_points_num = 0;

    for q = 0 : q_max

      if ( 0 < grid_points_num )
        grid_points_old(1:2,grid_points_old_num+1:grid_points_old_num+grid_points_num) = ...
          grid_points(1:2,1:grid_points_num);
      end 

      grid_points_old_num = grid_points_old_num + grid_points_num;

      [ grid_num, grid_points_num ] = cc_levels_constrained_size ( dim_num, ...
        q, alpha, level_min, level_max );
    
      fprintf ( 1, '\n' );
      fprintf ( 1, '  Number of grids is %d\n', grid_num );
      fprintf ( 1, '  Number of points is %d\n', grid_points_num );

      [ grid_level, grid_points ] = cc_levels_constrained ( dim_num, ...
        q, alpha, level_min, level_max, grid_num, grid_points_num );

      clf
%
%  We have to name the axes in order to control the grid.
%
      axes_handle = axes;
%
%  Plot the points.
%
      handle_new = scatter ( grid_points(1,:), grid_points(2,:), 'r', 'filled' );

      hold on

      if ( 0 < grid_points_old_num )
        handle_old = scatter ( grid_points_old(1,:), grid_points_old(2,:), 'b', 'filled' );
      end
%
%  Force the plotting region to be square, not rectangular.
%
      axis square
%
%  Request grid lines.
%
      grid on
%
%  Specify the location of the grid lines, and suppress labeling.
%
      set ( axes_handle, 'xtick', [ -1, -.75, -.5, -.25, 0, .25, .50, .75, 1] );
      set ( axes_handle, 'xticklabel', [] );
      set ( axes_handle, 'ytick', [ -1, -.75, -.5, -.25, 0, .25, .50, .75, 1] );
      set ( axes_handle, 'yticklabel', [] );
%
%  Make the plotting region slightly bigger than the data.
%
      axis ( [ -1.1, 1.1, -1.1, 1.1 ] )
%
%  Title
%
      s = sprintf ( '+Q = %f', q );
      title ( s );

      fprintf ( 1, '+Q = %f, Press return\n', q );
      pause
      hold off

    end

    fprintf ( 1, 'Press return to CLEAR the grid!\n' );
    pause
    clf

  end

  fprintf ( 1, '\n' );
  fprintf ( 1, 'CC_LEVELS_CONSTRAINED_ANIMATE:\n' );
  fprintf ( 1, '  Normal end of execution.\n' );

  fprintf ( 1, '\n' );
  timestamp ( );

  return
end
