function [ cg1, cg2 ] = cg_memory ( i, g, cg1, cg2 )

%*****************************************************************************80
%
%% CG_MEMORY stores the CG values for all generators.
%
%  Licensing:
%
%    This code is distributed under the GNU LGPL license.
%
%  Modified:
%
%    30 March 2013
%
%  Author:
%
%    John Burkardt
%
%  Parameters:
%
%    Input, integer I, the desired action.
%    -1, get a value.
%    0, initialize all values.
%    1, set a value.
%
%    Input, integer G, for I = -1 or +1, the index of
%    the generator, with 1 <= G <= 32.
%
%    Input/output, integer CG1, CG2.  For I = -1,
%    these are output, for I = +1, these are input, for I = 0,
%    these arguments are ignored.  When used, the arguments are
%    old or new values of the CG parameter for generator G.
%
  g_max = 32;

  persistent cg1_save;
  persistent cg2_save;

  if ( g < 1 )
    fprintf ( 1, '\n' );
    fprintf ( 1, 'CG_MEMORY - Fatal error!\n' );
    fprintf ( 1, '  Input generator index G is out of bounds.\n' );
    error ( 'CG_MEMORY - Fatal error!' );
  end

  if ( g_max < g )
    fprintf ( 1, '\n' );
    fprintf ( 1, 'CG_MEMORY - Fatal error!\n' );
    fprintf ( 1, '  Input generator index G is out of bounds.\n' );
    error ( 'CG_MEMORY - Fatal error!' );
  end

  if ( i < 0 )
    cg1 = cg1_save(g);
    cg2 = cg2_save(g);
  elseif ( i == 0 )
    cg1_save(1:g_max) = 0;
    cg2_save(1:g_max) = 0;
    cg1 = 0;
    cg2 = 0;
  elseif ( 0 < i )
    cg1_save(g) = cg1;
    cg2_save(g) = cg2;
  end

  return
end
