      subroutine comptc0
      use module
      implicit real(8) (a-h,o-x,z),logical(1)(y)
      !
      !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
      ! Calcul du nombre de determinants TCP engendres par 
      ! chaque classes de determinant du CAS
      ! idimc(classe du string CAS)=nombre total de determinants
      ! engendres par un des determinants de la classe
      ! = nb de TP possibles
      ! idimc_somme= nb total de determinants
      !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
      !
      l=len_trim(gener)
      maxt=2
      if(gener(l-1:l)=='+S') maxt=1
      if(index(gener,'+')==0) maxt=0
      maxp=maxt
      if(w)print*,'maxt,maxp,gener',maxt,maxp,gener
      if(w2)print*,
     *'              k,  nca,ncb ,nta,ntb,npa,npb, idimtp(ictp)'
      idimc_somme=0
      do k=1,nclasc
         if(.not.exist_clasc(k)) cycle
         nca=iclasc1(1,k)
         ncb=iclasc1(2,k)
         if(nocac0+nca>noac) cycle
         if(nocbc0+ncb>noac) cycle
         idimc(k)=0
         do nta=0,maxt
            npa=nta-nca
            if(npa>maxp.or.npa<0) cycle
            do ntb=0,maxt
               npb=ntb-ncb
               nt=nta+ntb
               np=npa+npb
               if(npb>maxp.or.npb<0) cycle
               if(np>maxp) cycle
               if(nt>maxt) cycle
               if(igener==3.and.nt+np>3) cycle
               if(igener==2.and.nt+np>2) cycle
               do ictp=1,36
               !print*,'all',icltp1(:,ictp)
               !print*,'All',(/nta,ntb,npa,npb/)
                  if(all(icltp1(:,ictp)==(/nta,ntb,npa,npb/))) idimc(k)=
     *            idimc(k)+idimtp(ictp)
                  if(w2.and.all(icltp1(:,ictp)==(/nta,ntb,npa,npb/)))
     *            print'('' idimc interm'',i4,3(2x,2i3),i8)'
     *            ,k,nca,ncb,nta,ntb,npa,npb,idimtp(ictp)
               enddo
            enddo
         enddo
         idimc_somme=idimc_somme+idimc(k)*
     *   c(noac,nocac0+nca)*c(noac,nocbc0+ncb)
         if(w2)print'(''k,nca,ncb, IDIMC   sum'',i4,2x,2i3,2i8)'
     *   ,k,nca,ncb,idimc(k)!,sum(idimc(1:k))
     *   ,idimc_somme
      enddo
      return
      end
       subroutine comptc0_sel
      use module
      implicit real(8) (a-h,o-x,z),logical(1)(y)
      yw=.false.
      !
      !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
      ! Calcul du nombre de determinants TCP engendres par 
      ! chaque classe de determinant du CAS (CAS selectionne)
      ! jdimc(classe du string CAS,idist)=nombre total de determinants
      ! engendres
      !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
      !
      l=len_trim(gener)
      maxt=2
      if(gener(l-1:l)=='+S') maxt=1
      if(index(gener,'+')==0) maxt=0
      maxp=maxt
      if(w)print*,'maxt,maxp,gener',maxt,maxp,gener
      if(w2)print*,
     *'              k, dist,nca,ncb ,nta,ntb,npa,npb, idimtp(ictp)'
      do k=1,nclasc
         if(.not.exist_clasc(k)) cycle
         nca=iclasc1(1,k)
         ncb=iclasc1(2,k)
         do idist=0,2
            jdimc(k,idist)=0
            do nta=0,maxt
               npa=nta-nca
               if(npa>maxp.or.npa<0) cycle
               do ntb=0,maxt
                  npb=ntb-ncb
                  if(npb<0) cycle
                  nt=nta+ntb
                  np=npa+npb
                  call lim_sel(nt,np,idist,ibon)
                  if(ibon==0) cycle
                  if(igener==3.and.nt+np>3) cycle
                  if(igener==2.and.nt+np>2) cycle
                  do ictp=1,36
                  !print*,'all',icltp1(:,ictp)
                  !print*,'All',(/nta,ntb,npa,npb/)
                     if(all(icltp1(:,ictp)==(/nta,ntb,npa,npb/))) 
     *               jdimc(k,idist)=jdimc(k,idist)+idimtp(ictp)
                     if(w2.and.all(icltp1(:,ictp)==(/nta,ntb,npa,npb/)))
     *               print'('' jdimc interm'',2i4,3(2x,2i3),i8)'
     *               ,k,idist,nca,ncb,nta,ntb,npa,npb,idimtp(ictp)
                  enddo
               enddo
            enddo
         enddo
         if(yw) then
            print'(''k,nca,ncb,idist JDIMC '',i4,2x,3i3,2i8)'
     *      ,k,nca,ncb,0,jdimc(k,0)
            print'(''k,nca,ncb,idist JDIMC '',i4,2x,3i3,2i8)'
     *      ,k,nca,ncb,1,jdimc(k,1)
            print'(''k,nca,ncb,idist JDIMC '',i4,2x,3i3,2i8)'
     *      ,k,nca,ncb,2,jdimc(k,2)
         endif
      enddo
      return
      end
