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

%*****************************************************************************80
%
%% vector_lex_next() generates vectors in lexicographic order.
%
%  Discussion:
%
%    The vectors are produced in lexical order, starting with
%    (1,1,...,1),
%    (1,1,...,2),
%    ...
%    (B,B,...,B).
%
%  Example:
%
%    d = 2,
%    b = 3
%
%    1   1
%    1   2
%    1   3
%    2   1
%    2   2
%    2   3
%    3   1
%    3   2
%    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: vector entries range from 1 to b.
%
%    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 )
        return
      end

      a(i) = 1;

    end

    more = false;

  end

  return
end
