      subroutine mulcovvd(x1,i,a,b,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
      character(31) elmat(27)
      !
      !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
      ! 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 :[x...]       det2 :i---->[]--->ab
      !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
      !
      aa1=aaa1
      aa2=aaa2
      ysp1=itest(21)==1
      ysp0=itest(21)==0
      if(ysp1) then
         aa1=aa1*2
         aa2=aa2*2
      endif
      x=num_oav(x1)
      a1=num_oav(a)
      b1=num_oav(b)
      i1=num_oav(i)
      !////////////////////////////////
      if(w)print*,'mulcovvd 0',x1,i,a,b
!      if(iter>=iterh)print*,'subr mulcovvd classhab(1,2)'
      if (iter>=iterh) call classhab(1,2)
      !////////////////////////////////
      n=0
      nntp=0
      call caldfc(idist,0,0)
      call caldfc(idist2,1,2)
      if ((ilc1(b)/=0).and.(ilp(i,a)/=0)) then
         if(ipc(ilp(i,a),nlco+ilc1(b))/=0) then
            itp1(1)=1
            itp2(1)=abs(ipc(ilp(i,a),nlco+ilc1(b)))
            n=n+1
            if (b>a) then
               ltp1(n)=1
            elseif (b==a) then
               ltp1(n)=3
            else
               ltp1(n)=2
            endif
            nntp(ltp1(n))=nntp(ltp1(n))+1
         endif
      elseif ((ilc1(a)/=0).and.(ilp(i,b)/=0)) then
         if(ipc(ilp(i,b),nlco+ilc1(a))/=0) then
            itp1(1)=1
            itp2(1)=abs(ipc(ilp(i,b),nlco+ilc1(a)))
            n=n+1
            if (b>a) then
               ltp1(n)=1
            elseif (b==a) then
               ltp1(n)=3
            else
               ltp1(n)=2
            endif
            nntp(ltp1(n))=nntp(ltp1(n))+1
         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)
         if(w)print*,'aa1,aa2',aa1,aa2
         elmat(1:3)=(/'      ->       | I+    -> A+ B+',
     *                '      ->       | I+    -> B+ A+',
     *                '      ->       | I+    -> B+=A+'/)
         call mula0(x,0,0,0)
         !
         jsgna=1-mod(nocac0+ninac-num_oav(i),2)*2
         jsgnb=1-mod(nocbc0+ninac-num_oav(i),2)*2
         !
         if(w)print*,'icas1'
         call mula(aa1,'+ovv',elmat,n,3,jsgnb,'B-','I-')
         if(ysp0)call mula(aa1,'-ovv',elmat,n,3,jsgna,'A-')
         !
         !===============
         !
         if(a/=b) then
!            if(b>a) then
!               jsgna1=-jsgna
!               jsgnb1=-jsgnb
!            else
!               jsgna1=jsgna
!               jsgnb1=jsgnb
!            endif
            !
            if(w)print*,'icas2'
            call mula(aa1-aa2,'+ovv',elmat,n,2,jsgna)
            if(ysp0)
     *   call mula(aa1-aa2,'-ovv',elmat,n,2,jsgnb,'A-','I-','B-')
            !
            !================
            !
            if(w)print*,'icas3'
            call mula(aa2,'+ovv',elmat,n,2,jsgnb,'A-','I-')
            if(ysp0)call mula(aa2,'-ovv',elmat,n,2,jsgna,'B-')
         endif
         !
      endif
      hab=0
      if(itest(22)==1.and.iter==1) return
 
 
      !On va rajouter un trou j
      !det1 j--->[x....] det2 ij --->ab
      if(igener<4) return
      !///////////////////////////////////////////
      if(w)print*,'mulcovvd on ajoute un trou ',x,i,a,b
      !///////////////////////////////////////////
      n=0
      nntp=0
      call caldfc(idist,1,0)
      call caldfc(idist2,2,2)
      do jj=1,nlco
         j=ilc(jj)
         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
            itp2(n)=abs(ipp(ii1))
            itp1(n)=ilc1(j)
            call mulcovvd2(i,j,a,b,ltp1(n))
            nntp(ltp1(n))=nntp(ltp1(n))+1
            if(w)print'(a,20i4)','a,i,j,b',a,i,j,b,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
            itp2(n)=abs(ipp(ii1))
            itp1(n)=ilc1(j)
            call muladd_o_o(j,i,ltp1(n))
            if(a>b) ltp1(n)=ltp1(n)+3
            if(a==b) ltp1(n)=ltp1(n)+6
            !call mulcovvd2(i,j,a,b,ltp1(n))
            nntp(ltp1(n))=nntp(ltp1(n))+1
            if(w)print'(a,20i4)','a,i,j,b',a,i,j,b,n,
     *      ltp1(n),nntp(ltp1(n)),
     *      itp1(n),itp2(n)
         endif
      enddo
      if(n==0) return
      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)=(/'j+             | j+ I+ -> A+ B+',
     *             'j+             | I+ j+ -> A+ B+',
     *             'j+             | I+=j+ -> A+ B+',
     *             'j+             | j+ I+ -> B+ A+',
     *             'j+             | I+ j+ -> B+ A+',
     *             'j+             | I+=j+ -> B+ A+',
     *             'j+             | j+ I+ -> B+=A+',
     *             'j+             | I+ j+ -> B+=A+',
     *             'j+             | I+=j+ -> B+=A+'/)
 
      !
      jsgna=1-mod(nocac0+ninac-num_oav(i),2)*2
      jsgnb=1-mod(nocbc0+ninac-num_oav(i),2)*2
      aa3=aa1
      call mula0(x,0,0,0)
      !
      if(w)print*,'icas1'
      call mula(aa3,'+ovv',elmat,n,9,jsgnb,'I-','B-')
      if(ysp0)call mula(aa3,'-ovv',elmat,n,9,jsgna,'j-','A-')
      !
      if(w)print*,'icas2'
      call mula(aa3,'+ovv',elmat,n,9,-jsgnb,'I-','B-','j-')
      if(ysp0)call mula(aa3,'-ovv',elmat,n,9,-jsgna,'A-')
      !
      if(a/=b) then
         aa3=aa1-aa2
         jsgna=-jsgna
         jsgnb=-jsgnb
         if(w)print*,'icas3'
         call mula(aa3,'+ovv',elmat,n,9,jsgna)
         if(ysp0)
     *   call mula(aa3,'-ovv',elmat,n,9,jsgnb,'j-','A-','I-','B-')
         !
         if(w)print*,'icas4'
         call mula(aa3,'+ovv',elmat,n,9,-jsgna,'j-')
         if(ysp0)call mula(aa3,'-ovv',elmat,n,9,-jsgnb,'A-','I-','B-')
         !
         !========================
         !
         elmat(1:9)=(/'j+             | j+ I+ -> B+ A+',
     *                'j+             | I+ j+ -> B+ A+',
     *                'j+             | I+=j+ -> B+ A+',
     *                'j+             | j+ I+ -> A+ B+',
     *                'j+             | I+ j+ -> A+ B+',
     *                'j+             | I+=j+ -> A+ B+',
     *                'j+             | j+ I+ -> A+=B+',
     *                'j+             | I+ j+ -> A+=B+',
     *                'j+             | I+=j+ -> A+=B+'/)
 
         !
         jsgna=1-mod(nocac0+ninac-num_oav(i),2)*2
         jsgnb=1-mod(nocbc0+ninac-num_oav(i),2)*2
         aa3=aa2
         !
         if(w)print*,'icas5'
         call mula(aa2,'+ovv',elmat,n,9,jsgnb,'I-','B-')
         if(ysp0)call mula(aa2,'-ovv',elmat,n,9,jsgna,'j-','A-')
         !
         if(w)print*,'icas6'
         call mula(aa2,'+ovv',elmat,n,9,-jsgnb,'I-','B-','j-')
         if(ysp0)call mula(aa2,'-ovv',elmat,n,9,-jsgna,'A-')
      endif
      !
      return
      end
 
       subroutine mulcovvd2(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
