function [dfi,nvr] = subsp(nvr,kelem,nvct,J,LJ1,G,dfi,inel,multab,steer,cind,ch,norder)
%
% This function finds an irreducible vector, if possible, within
% a certain subspace of the irreducible space.
%
pi2i = 2*pi*i;
N = 0;
I = 1;
nvr1 = nvr;
ninv = zeros(1,G);
%
% Operate with the regular representatives on the eigenspace dfi(1:nvr,1:G)
% to decide for which operators, except those in kelem(1:nvct),
% dfi(1:nvr,1:G) is an invariant subspace.
%
for L = 1:G
  if kelem(I) ~= L
    for J1 = 1:nvr1
      K = inel(L);
      vec(1:G) = dfi(J1,multab(K,1:G));
      vec2(1:nvr1) = conj(dfi(1:nvr1,1:G))*vec(1:G).';
      for I1 = 1:G
        rin = vec(I1);
        for J2 = 1:nvr1
          rin = rin - vec2(J2)*dfi(J2,I1);
        end
        vec(I1) = rin;
      end
      I1 = 1;
      while I1 <= G
        if abs(vec(I1)) >= 0.001
          break;
        end
        I1 = I1 + 1;
      end
      if I1 <= G
        break;
      end
    end
    if I1 > G
      N = N + 1;
      ninv(N) = L;
    end
  else
    if I < nvct
      I = I + 1;
    end
  end
end
if N ~= 0
  for L = 1:N
    K = ninv(L);
    K1 = inel(K);
    for I1 = 1:nvr1
      vec(1:G) = dfi(I1,multab(K1,1:G));
      subm(1:nvr1,I1) = conj(dfi(1:nvr1,1:G))*vec(1:G).';
    end
    wr = eig(subm);
    I1 = 1;
    while I1 <= (nvr1-1)
      I2 = I1 + 1;
      if ~(abs(wr(I1)-wr(I2)) < 0.001)
        break;
      end
      I1 = I1 + 1;
    end
    if I1 < nvr1
      K2 = cind(K);
      K2 = norder(K2);
      for I1 = 1:K2
        eigenv(I1) = exp(pi2i*(I1-1)/K2);
      end
      J1 = 1;
      while J1 <= K2
        if (abs(wr(1)-eigenv(J1)) < 0.001)
          LAB = eigenv(J1);
          break;
        end
        J1 = J1 + 1;
      end 
      if J1 <= K2
        kloop = 0;
        [fi,nvr2] = eigvec(K,LAB,J,kloop,steer,inel,cind,ch,multab,G);
        [fi,K5] = intsec(nvr1,nvr2,G,fi,dfi);
        if K5 ~= 0
          nvr1 = K5;
          dfi(1:nvr1,1:G) = fi(1:G,1:nvr1).';
          if nvr1 == LJ1
            break;
          end
        end
      end
    end
  end
end
nvr = nvr1;
return
