function [jpdd,allow,laj] = repres(multab,G,steer,inel,lj,ncl,nfirst,classl,sirt,...
                       onert,cind,ch,nmberg,ngen,map,norder,ibz,ksym,nopi1,nopli1,sil)
%
% Function repres calculates the irreducible group representations, using
% the group characters calculated by function charac.
%
fid = fopen('Irrepres.m', 'a');
ncl1 = ncl - 1;
laj(1:ncl) = lj(1:ncl);
n2(1:ncl) = 1:ncl;
for I = 1:ncl1
  I1 = I + 1;
  for J = I1:ncl
    if laj(I) > laj(J)
      nip = laj(J);
      laj(J) = laj(I);
      laj(I) = nip;
      nip = n2(J);
      n2(J) = n2(I);
      n2(I) = nip;
    end
  end
end
if steer(7)
  fprintf(fid, 'New representation numbering:\n');
  fprintf(fid, '%3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d\n', 1:ncl);
  fprintf(fid, '\n');
  fprintf(fid, 'Old representation numbering:\n');
  fprintf(fid, '%3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d\n', n2(1:ncl));
  fprintf(fid, '\n');
end
pi2i = 2*pi*i;
KJ = 0;
while KJ < ncl
  KJ = KJ + 1;
  J = n2(KJ);
  LJ1 = laj(KJ);
  if LJ1 ~= 1
    I = sirt(J,1);
    IN = nfirst(I);
    IN = classl(IN);
    lab = pi2i*(sirt(J,3) - 1)/sirt(J,2);
    lab = exp(lab);
    NO1 = norder(I) - 1;
    if onert(J) == 1
      fclose(fid);
      [loopl,lpstr,numl] = permu(multab,G,steer,inel,IN);
      fid = fopen('Irrepres.m', 'a');
      NML = 0;
      IND = 1;
      while NML < numl
        NML = NML + 1;
        if NML > 1
          IND = IND + loopl(NML - 1);
        end
        vec = zeros(1,G);
        K2 = lpstr(IND);
        vec(K2) = 1;
        P = 1;
        LPE = IND + loopl(NML);
        for N = (IND + 1):(LPE - 1)
          K3 = lpstr(N);
          P = P*lab;
          vec(K3) = P;
        end
%
% Projection SJ*vec
%
        vec2 = zeros(1,G);
        for K4 = 1:G
          for K5 = 1:G
            K6 = inel(K5);
            K6 = multab(K4,K6);
            K6 = cind(K6);
            vec2(K4) = vec2(K4) + conj(ch(J,K6))*vec(K5);
          end
        end
        I2 = 1;
        while I2 <= G
          if abs(vec2(I2)) >= 0.001
            break;
          end
          I2 = I2 + 1;
        end
        if I2 <= G
          rnorm = 0;
          for I2 = 1:G
            rnorm = rnorm + (abs(vec2(I2)))^2;
          end
          rnorm = 1/sqrt(rnorm);
          fi(1:G,1) = vec2(1:G).'*rnorm;
          ntry2 = zeros(1,G);
          ntry2(IN) = 1;
          K2 = IN;
          for I2 = 1:NO1
            K2 = multab(K2,IN);
            ntry2(K2) = 1;
          end
%
% Multiply fi with all group elements (except for powers of already tested group
% elements) to form new independent vectors.
%
          IV = 1;
          for K3 = 1:G
            if ntry2(K3) ~= 1
              ntry2(K3) = 1;
%
% Multiply with the regular representation of group element K3.
%
              I3 = inel(K3);
              vec(1:G) = fi(multab(I3,1:G),1).';
              for K11 = 1:IV
                RIN = 0;
                RIN = vec(1:G)*conj(fi(1:G,K11));
                RINAB = abs(RIN);
                if RINAB >= 0.001
                  if abs(RINAB - 1) >= 0.001
                    vec(1:G) = vec(1:G) - RIN*fi(1:G,K11).';
                    rnorm = sum(abs(vec(1:G).').^2);
                    if rnorm >= 0.001
                      rnorm = 1/sqrt(rnorm);
                    else
                      break;
                    end
                    vec(1:G) = vec(1:G)*rnorm;
                  else
                    break;
                  end
                end   
              end
              if abs(RINAB - 1) >= 0.001
                IV = IV + 1;
                fi(1:G,IV) = vec(1:G).';
              end
              if IV >= LJ1
                break;
              end
            end
          end
        end
        if IV >= LJ1
          break;
        end
      end
    else
%
% An irreducible representation with no non-degenerate eigenvalue is calculated.
%
      fprint(fid,'\n\n');
      fprintf(fid,'The 3%dth irreducible representation has no non-degenerate eigenvalue\n\n', KJ);
      fclose(fid);
      [fi,LJ1] =...
      degen(J,KJ,LJ1,IN,lab,multab,G,ngen,map,nmberg,cind,norder,steer,inel,ch,sirt);
      fid = fopen('Irrepres.m', 'a');
    end
%
% Construction of the irreducible representation
%   
    if LJ1 ~= 0
      dfi(1:LJ1,1:G) = conj(fi(1:G,1:LJ1)).';          
      for K4 = 2:nmberg
        grupel(1:LJ1,1:LJ1,ngen(K4)) = zeros(LJ1);
      end
      grupel(1:LJ1,1:LJ1,1) = eye(LJ1);  
      for K1 = 2:nmberg
        K5 = ngen(K1);
        K2 = inel(K5);
        genfi(1:G,1:LJ1) = fi(multab(K2,1:G),1:LJ1);
        grupel(1:LJ1,1:LJ1,K5) = dfi(1:LJ1,1:G)*genfi(1:G,1:LJ1);
      end
      for LG = 1:G
        ML2 = map(LG,2);
        if ML2 ~= 0
          ML1 = map(LG,1);
          grupel(1:LJ1,1:LJ1,LG) =...
          grupel(1:LJ1,1:LJ1,ML1)*grupel(1:LJ1,1:LJ1,ML2);
%
% Construction of the irrep of the other group elements by multiplying 
% the representatives of the generators.
%           
        end
      end
      if steer(9)
        fprintf(fid, '\n\n');
        for I3 = 1:G
          for I4 = 1:LJ1
            for I5 = 1:LJ1
              grupelord(1,I5,I4,I3) = real(grupel(I5,I4,I3));
              grupelord(2,I5,I4,I3) = imag(grupel(I5,I4,I3));
            end
          end
        end
        for I3 = 1:G
          fprintf(fid, 'Representation number %3d, element number %3d\n', KJ, I3);
          for I4 = 1:LJ1
            fprintf(fid, '(%7.4f %7.4f) (%7.4f %7.4f) (%7.4f %7.4f) (%7.4f %7.4f)\n',...
                    grupelord(1:2,I4,1:LJ1,I3));
            fprintf(fid, '\n');
          end
        end
      end
    end
  else
    if steer(8)
      grupelord(1,1:G) = real(ch(J,cind(1:G)));
      grupelord(2,1:G) = imag(ch(J,cind(1:G)));
      fprintf(fid, '\n\n');
      for I3 = 1:G
        fprintf(fid, 'Representation number %3d, element number %3d\n', KJ, I3);
        fprintf(fid, '(%7.4f %7.4f)\n', grupelord(1:2,I3));
        fprintf(fid, '\n');
      end
      grupel(1,1,1:G) = grupelord(1,1:G) + i*grupelord(2,1:G);
    end
  end
  if ~(steer(20) | ibz | ksym)
    N6 = 1;
    while N6 <= nopi1
      N7 = nopli1(N6);
      N8 = 1;
      while N8 <= LJ1
        if abs(sil(N7) - grupel(N8,N8,N7)) > 1*10^(-3)
          break;
        end
        N8 = N8 + 1;
      end
      if N8 <= LJ1
        break;
      end
      N6 = N6 + 1;
    end
    if N6 > nopi1
      allow(KJ) = 1;
      for J2 = 1:G
        for J1 = 1:LJ1
          jpdd(KJ,J1,J2) = grupel(J1,J1,J2);
        end
      end
    else
      allow(KJ) = 0;
    end
  else
    allow(KJ) = 1;
    for J2 = 1:LJ1
      for J1 = 1:G
        jpdd(KJ,J2,J1) = grupel(J2,J2,J1);
      end
    end
  end
end
fclose(fid);
return 