function [ a, more ] = vector_representative_next ( d, b, a, more )

%*****************************************************************************80
%
%% vector_representative_next() generates vector representatives one at a time.
%
%  Example:
%
%    d = 3
%    b = 3
%
%    1: 1  1  1
%    2: 1  1  2
%    3: 1  1  3
%    4: 1  2  2
%    5: 1  2  3
%    6: 1  3  3
%    7: 2  2  2
%    8: 2  2  3
%    9: 2  3  3
%   10: 3  3  3
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    31 October 2022
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    integer d: the vector dimension.
%
%    integer B, the base to be used.  B = 2 will
%    give vectors of 1's and 2's, for instance.
%
%    integer A(D), except on the first call, this should
%    be the output value of A on the last call.
%
%    logical MORE, should be FALSE on the first call, and
%    thereafter should be the output value of MORE from the previous call.  
%
%  Output:
%
%    integer A(D), the next vector.
%
%    logical MORE, is TRUE if another vector was computed.
%    If MORE is FALSE on return, then ignore the output value A, and
%    stop calling the routine.
%
  if ( ~ more )

    a(1:d) = 1;
    more = true;

  else
      
    for i = d : -1 : 1

      a(i) = a(i) + 1;

      if ( a(i) <= b )
        a(i+1:d) = a(i);
        return
      end

    end

    more = false;

  end

  return
end

