      subroutine mulcvood(x1,a,i,j,aaa1,aaa2)
      use module
      use mod_ena
      use mod_mula
      IMPLICIT REAL(8)(A-H,O-X,Z),logical(1)(y)
      integer a,x1,y1,z1,b,b1,x,y,z,i,i1,a1,j,j3,bb
      character(31) elmat(27)
      logical::coucou
      !
      !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
      ! Preparation des listes d'adresses du CAS et des TP
      !
      ! i,j,k,l,aa = indices et valeur de l'integrale
      ! itp1,itp2,itp3,itp4 : adresses de la partie T/P
      ! ntp,ntp1,ntp2       : nombre d'adresses T/P
      !  det1 :ij-->[x...]-->a       det2 :[]
      !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
      !
      if(igener<3) return
!      if(iter>=iterh)print*,'subr mulcvood classhab(2,1)'
      if (iter>=iterh) call classhab(2,1)
      !///////////////////////////////////////
      if(w)print*,'mulcvood 0',x,a,i,j,aa1,aa2
      !///////////////////////////////////////
      x=num_oav(x1)
      a1=num_oav(a)
      j3=num_oav(j)
      i1=num_oav(i)
      aa1=aaa1
      aa2=aaa2
      ysp1=itest(21)==1
      ysp0=itest(21)==0
      if(ysp1) then
         aa1=aa1*2
         aa2=aa2*2
      endif
      n=0
      nntp=0
      call caldfc(idist,2,1)
      call caldfc(idist2,0,0)
      if((ilc1(j)/=0).and.(ilp(i,a)/=0)) then
         if(ipc(ilp(i,a),ilc1(j))/=0) then
            itp2(1)=1
            itp1(1)=abs(ipc(ilp(i,a),ilc1(j)))
            n=n+1
            if (j>i) then
               ltp1(n)=1
            elseif (i==j) then
               ltp1(n)=3
            else
               ltp1(n)=2
            endif
            nntp(ltp1(n))=nntp(ltp1(n))+1
            if(w)print'(a,20i4)','a,i,j',a,i,j,n,
     *         ltp1(n),nntp(ltp1(n)),
     *         itp1(n),itp2(n)
         endif
      elseif ((ilc1(i)/=0).and.(ilp(j,a)/=0)) then
         if(ipc(ilp(j,a),ilc1(i))/=0) then
            itp2(1)=1
            itp1(1)=abs(ipc(ilp(j,a),ilc1(i)))
            n=n+1
            if (j>i) then
               ltp1(n)=1
            elseif (i==j) then
               ltp1(n)=3
            else
               ltp1(n)=2
            endif
            nntp(ltp1(n))=nntp(ltp1(n))+1
            if(w)print'(a,20i4)','a,i,j',a,i,j,n,
     *         ltp1(n),nntp(ltp1(n)),
     *         itp1(n),itp2(n)
         endif
      endif
      if(n/=0) then
         call reoitp(n,3,nntp)
         if(w)print'(a,20i3)','ITP',itp1(1:n)
         if(w)print'(a,20i3)','ITP',itp2(1:n)
         if(w)print'(a,20i3)','NNTP',NNTP(0:3)
         call mula0(x,0,0,0)
         elmat(1:3)=(/'I+ J+ -> A+    |               ',
     *                'J+ I+ -> A+    |               ',
     *                'J+=I+ -> A+    |               '/)
         !
         jsgna=1-mod(nocac0+num_oav(j)+num_oav(i),2)*2
         jsgnb=1-mod(nocbc0+num_oav(j)+num_oav(i),2)*2
         !
         if(w)print*,'icas1'
         call mula(aa1,'+voo',elmat,n,3,jsgnb,'A-','J-')
         if(ysp0)call mula(aa1,'-voo',elmat,n,3,jsgna,'I-')
         !
         !
         if(w)print*,'icas2'
         call mula(aa1-aa2,'+voo',elmat,n,3,-jsgna)
         if(ysp0)
     *   call mula(aa1-aa2,'-voo',elmat,n,3,-jsgnb,'J-','A-','I-')
         !
         !
         if(i/=j) then
         if(w)print*,'icas3'
         call mula(aa2,'+voo',elmat,n,3,jsgnb,'A-','I-')
         if(ysp0)call mula(aa2,'-voo',elmat,n,3,jsgna,'J-')
         endif
         !
      endif
 
      hab=0
 
 
      !
      !///////////////////////////////
      !On va rajouter une particule b
      !det1 ij--->[x....]--->ab det2 --->b
      !///////////////////////////////
      if(igener<4) return
      if(itest(22)==1.and.iter==1) return
      if(w)print*,'1mulcvood on ajoute une particule',x,a,i,j
      !b liee a j
      n=0
      nntp=0
      call caldfc(idist,2,2)
      call caldfc(idist2,0,1)
      do bb=1,nlcv
         b=ilc(nlco+bb)
         if(w)print*,'ilp',ilp(i,a),ilp(j,b),ilp(j,a),ilp(i,b)
         if ((ilp(i,a)/=0).and.(ilp(j,b)/=0)) then
            ipair=ilp(i,a)
            jpair=ilp(j,b)
            iimax=max(ipair,jpair)
            iimin=min(ipair,jpair)
            ii1=iimax*(iimax-1)/2+iimin
            if(ipp(ii1)==0) cycle
            n=n+1
            itp1(n)=abs(ipp(ii1))
            itp2(n)=ilc1(b)
            call mulcvood2(i,j,a,b,ltp1(n))
            nntp(ltp1(n))=nntp(ltp1(n))+1
            if(w)print'(a,20i4)','a,b,i,j',a,b,i,j,n,
     *      ltp1(n),nntp(ltp1(n)),
     *      itp1(n),itp2(n)
         elseif((ilp(j,a)/=0).and.(ilp(i,b)/=0)) then
            ipair=ilp(i,b)
            jpair=ilp(j,a)
            iimax=max(ipair,jpair)
            iimin=min(ipair,jpair)
            ii1=iimax*(iimax-1)/2+iimin
            if(ipp(ii1)==0) cycle
            n=n+1
            itp1(n)=abs(ipp(ii1))
            itp2(n)=ilc1(b)
            call mulcvood2(i,j,a,b,ltp1(n))
            nntp(ltp1(n))=nntp(ltp1(n))+1
            if(w)print'(a,20i4)','a,b,i,j',a,b,i,j,n,
     *      ltp1(n),nntp(ltp1(n)),
     *      itp1(n),itp2(n)
         endif
      enddo
      call reoitp(n,27,nntp)
      if(w)print'(a,20i3)','ITP',itp1(1:n)
      if(w)print'(a,20i3)','ITP',itp2(1:n)
      !
      !
      !
      elmat(1:9)=(/'I+ J+ -> b+ A+ |       -> b+   ',
     *             'J+ I+ -> b+ A+ |       -> b+   ',
     *             'I+=J+ -> b+ A+ |       -> b+   ',
     *             'I+ J+ -> A+ b+ |       -> b+   ',
     *             'J+ I+ -> A+ b+ |       -> b+   ',
     *             'I+=J+ -> A+ b+ |       -> b+   ',
     *             'I+ J+ -> A+=b+ |       -> b+   ',
     *             'J+ I+ -> A+=b+ |       -> b+   ',
     *             'I+=J+ -> A+=b+ |       -> b+   '/)
      !
      jsgna=1-mod(nocac0+num_oav(j)+num_oav(i),2)*2
      jsgnb=1-mod(nocbc0+num_oav(j)+num_oav(i),2)*2
      if(w)print*,'aa1,aa2',aa1,aa2,noac,num_oav(i),num_oav(j),jsgna,jsg
      aa3=aa1
      call mula0(x,0,0,0)
      !
      call mula(aa3,'+voo',elmat,n,9,jsgnb,'J-','A-')
      if(ysp0)call mula(aa3,'-voo',elmat,n,9,jsgna,'I-','b-')
      !
      !
      call mula(aa3,'+voo',elmat,n,9,jsgnb,'J-','A-','b-')
      if(ysp0)call mula(aa3,'-voo',elmat,n,9,jsgna,'I-')
      !
      !=================
      if(i/=j) then
         !
         aa3=aa1-aa2
         call mula(aa3,'+voo',elmat,n,9,-jsgna)
         if(ysp0)
     *   call mula(aa3,'-voo',elmat,n,9,-jsgnb,'b-','J-','I-','A-')
         !
         call mula(aa3,'+voo',elmat,n,9,-jsgna,'b-')
         if(ysp0)call mula(aa3,'-voo',elmat,n,9,-jsgnb,'J-','I-','A-')
         !
         !======================
         !
         aa3=aa2
         elmat(1:9)=(/'J+ I+ -> b+ A+ |       -> b+   ',
     *                'I+ J+ -> b+ A+ |       -> b+   ',
     *                'J+=I+ -> b+ A+ |       -> b+   ',
     *                'J+ I+ -> A+ b+ |       -> b+   ',
     *                'I+ J+ -> A+ b+ |       -> b+   ',
     *                'J+=I+ -> A+ b+ |       -> b+   ',
     *                'J+ I+ -> A+=b+ |       -> b+   ',
     *                'I+ J+ -> A+=b+ |       -> b+   ',
     *                'J+=I+ -> A+=b+ |       -> b+   '/)
         !
         call mula(aa3,'+voo',elmat,n,9,jsgnb,'J-','A-')
         if(ysp0)call mula(aa3,'-voo',elmat,n,9,jsgna,'I-','b-')
         !
         !
         call mula(aa3,'+voo',elmat,n,9,jsgnb,'J-','A-','b-')
         if(ysp0)call mula(aa3,'-voo',elmat,n,9,jsgna,'I-')
         !
      endif
      return
      end
 
       subroutine mulcvood2(i,j,a,b,ltp1)
      integer(1) ltp1
      integer a,b
      if (a<b) then
         if (j<i) then
            ltp1=5
         elseif (i==j) then
            ltp1=6
         else
            ltp1=4
         endif
      elseif(b==a) then
         if (j<i) then
            ltp1=8
         elseif (i==j) then
            ltp1=9
         else
            ltp1=7
         endif
      else
         if (j<i) then
            ltp1=2
         elseif (i==j) then
            ltp1=3
         else
            ltp1=1
         endif
      endif
      return
      end
