function [ ig1, ig2 ] = ig_memory ( i, g, ig1, ig2 )

%*****************************************************************************80
%
%% IG_MEMORY stores the IG 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 IG1, IG2.  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 IG parameter for generator G.
%
  g_max = 32;

  persistent ig1_save;
  persistent ig2_save;

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

  if ( i < 0 )
    ig1 = ig1_save(g);
    ig2 = ig2_save(g);
  elseif ( i == 0 )
    ig1_save(1:g_max) = 0;
    ig2_save(1:g_max) = 0;
    ig1 = 0;
    ig2 = 0;
  elseif ( 0 < i )
    ig1_save(g) = ig1;
    ig2_save(g) = ig2;
  end

  return
end
