function [map,nmberg,ngen] = genera(G,multab)
%
% A set of group elements that can produce all other elements by group element
% multiplication, are generated. Element number map(L,1) multiplied by element
% number map(L,2), gives element number L. If map(L,2) == 0, L is one of the
% generators. ngen(I) = group element index of the Ith generator. nmberg = the
% total number of generators. The list of group elements is traversed,
% starting with N = 1. When N has been increased by 1, it is checked that N
% has not been produced by multiplication of generators, that already have
% been registred. If not, map(N,1) is still equal to zero and we register N as
% a new generator. The number N2 of group elements that not yet have been
% checked, is diminished by 1. Then we form the products of N with all
% preceding elements. If these products give new elements, these are
% registered and N2 is diminished by 1. All preceding group elements may be
% used in these products, since if they are not generators themselves, it has
% been registered how they can be produced by generators. When N2 = 0, all
% group elements have been treated and those L with map(L,2) = 0, are the 
% generators.
%
for L = 1:G
  map(L,1) = 0;
  map(L,2) = 0;
end
map(1,1) = 1;
if G > 1
  N2 = G - 1;
  for N = 2:G
    if map(N,1) == 0
      map(N,1) = N;
      N2 = N2 - 1;
      if N2 == 0
        break;
      end
    end
    for M = 2:N
      N1 = multab(M,N);
      if N1 > N & map(N1,1) == 0
        map(N1,1) = M;
        map(N1,2) = N;
        N2 = N2 - 1;
        if N2 == 0
          break;
        end
      end
    end
    if N2 == 0
      break;
    end
    for M = 2:N
      N1 = multab(N,M);
      if N1 > N & map(N1,1) == 0
        map(N1,1) = N;
        map(N1,2) = M;
        N2 = N2 - 1;
        if N2 == 0
          break;
        end
      end
    end
    if N2 == 0
      break;
    end
  end
  nmberg = 1;
  ngen(1) = 1;
  for L = 2:G
    if map(L,2) == 0
      nmberg = nmberg + 1;
      ngen(nmberg) = L;
    end
  end
else
  nmberg = 1;
  ngen(1) = 1;
end
return