function [ lg1, lg2 ] = lg_memory ( i, g, lg1, lg2 )

%*****************************************************************************80
%
%% LG_MEMORY stores the LG 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 LG1, LG2.  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 LG parameter for generator G.
%
  g_max = 32;

  persistent lg1_save;
  persistent lg2_save;

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

  if ( i < 0 )
    lg1 = lg1_save(g);
    lg2 = lg2_save(g);
  elseif ( i == 0 )
    lg1_save(1:g_max) = 0;
    lg2_save(1:g_max) = 0;
    lg1 = 0;
    lg2 = 0;
  elseif ( 0 < i )
    lg1_save(g) = lg1;
    lg2_save(g) = lg2;
  end

  return
end
