      subroutine mulccovd(x1,y1,i,a,aaa1,aaa2)
      use module
      use mod_ena
      use mod_dim
      use mod_ena2
      use mod_itp
      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,bb
      integer,allocatable,dimension(:) :: idetc1,idetc2,isgnc
      dimension ntp(0:9),aal(4),isec1(4),isec2(4)
      character(31) elmat(27)
      integer(1) l1,l2
      !
      !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
      ! 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 : i[xy...] -->       det2 :-->a
      !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
      !i et a doivent etre lies au cas
      !///////////////////////////////////////////////////////////
      if(w)print*,'mulccovd 0',x1,y1,i,a
      !///////////////////////////////////////////////////////////
      ! on n'ajoute rien
      !
 
      call caldfc(idist,1,0)
      call caldfc(idist2,0,1)
      x=num_oav(x1)
      y=num_oav(y1)
      a1=num_oav(a)
      i1=num_oav(i)
      aa1=aaa1
      aa2=aaa2
      !symetrie de spin
      ysp1=itest(21)==1
      ysp0=itest(21)==0
      if(ysp1) then
         aa1=aa1*2
         aa2=aa2*2
      endif
      !
      ! signe : saut i-C   j-C
      jsgn=1-mod(ninac-num_oav(i),2)*2
      jsgn1=jsgn
      if(y<x) jsgn1=-jsgn
      if(w)print*,'mulccovd 0',x,y,i,a
      ilci=ilc1(i)
      ilca=ilc1(a)
      if (ilci/=0.and.ilca/=0) then
         itp1(1)=ilc1(i)
         itp2(1)=ilc1(a)
         ltp1(1)=1
         nntp(1)=1
         if(w)print'(a,20i4)','a,j,i',a,j,i,1,
     *   ltp1(1),nntp(ltp1(1)),
     *   itp1(1),itp2(1)
         if(w)print'(a,20i3)','ITP',itp1(1)
         if(w)print'(a,20i3)','ITP',itp2(1)
         !
         elmat(1)='I+    ->       |       -> A+   '
         call mula0(x,y,0,0)
         !
         if(w)print*,'icas1'
         call mula(aa1,'+-ov',elmat,n,1,jsgn,'A-')
         if(ysp0)call mula(aa1,'-+ov',elmat,n,1,jsgn,'I-')
         if(x/=y) then
            if(w)print*,'icas2'
            ydir=.false.
            yoci((/x,y/))=.true.
            call mula(aa1-aa2,'++ov',elmat,n,1,jsgn1)
            if(ysp0)call mula(aa1-aa2,'--ov',elmat,n,1,jsgn1,'A-','I-')
            yoci((/x,y/))=.false.
            ydir=.true.
            if(w)print*,'icas3'
            call mula(aa2,'+-vo',elmat,n,1,jsgn,'I-')
            if(ysp0)call mula(aa2,'-+vo',elmat,n,1,jsgn,'A-')
         endif
      endif
 
      !////////////////////////////////
      !On va rajouter un trou j
      !det1 ij--->[xy....] det2 j--->a
      !////////////////////////////////
      if(igener<2) return
      if(itest(22)==1.and.iter==1) return
      if(w)print*,'mulccovd on ajoute un trou',x,y,i,a
      ilci=ilc1(i)
      if (ilci/=0) then
         n=0
         nntp=0
         call caldfc(idist,2,0)
         call caldfc(idist2,1,1)
         do jpair1=idebliscond(a),idebliscond(a+1)-1
            jpair=liscond(jpair1)
            j=ilpair(1,jpair)
            ilcj=ilc1(j)
            if (ilcj==0) cycle
            n=n+1
            itp2(n)=il(j,a)
            if (ilci>ilcj) then
               itp1(n)=num1(ilci)+ilcj
            else if (ilci<ilcj) then
               itp1(n)=num1(ilcj)+ilci
            else
               itp1(n)=ilci
            endif
            call muladd_o_o(j,i,ltp1(n))
            nntp(ltp1(n))=nntp(ltp1(n))+1
            if(w)print'(a,20i4)','a,j,i',a,j,i,n,
     *      ltp1(n),nntp(ltp1(n)),
     *      itp1(n),itp2(n)
         enddo
         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)
            !
            elmat(1:3)=(/'j+ I+ ->       | j+    -> A+   ',
     *                   'I+ j+ ->       | j+    -> A+   ',
     *                   'I+=j+ ->       | j+    -> A+   '/)
            call mula0(x,y,0,0)
            aa3=aa1
            !
            if(w)print*,'icas1'
            call mula(aa3,'+-ov',elmat,n,3,jsgn,'A-')
            if(ysp0)call mula(aa3,'-+ov',elmat,n,3,jsgn,'I-','j-')
            !
            if(w)print*,'icas2'
            call mula(aa3,'+-ov',elmat,n,3,jsgn,'A-','j-')
            if(ysp0)call mula(aa3,'-+ov',elmat,n,3,jsgn,'I-')
            !
            !==============
            !
            if(x/=y) then
               aa3=aa1-aa2
               ydir=.false.
               yoci((/x,y/))=.true.
               !
               if(w)print*,'icas3'
               call mula(aa3,'++ov',elmat,n,3,jsgn1)
               if(ysp0)
     *         call mula(aa3,'--ov',elmat,n,3,jsgn1,'A-','I-','j-')
               !
               if(w)print*,'icas4'
               call mula(aa3,'++ov',elmat,n,3,jsgn1,'j-')
               if(ysp0)call mula(aa3,'--ov',elmat,n,3,jsgn1,'A-','I-')
               ydir=.true.
               yoci((/x,y/))=.false.
               !
               !
               !==============
               !
               aa3=aa2
               !
               if(w)print*,'icas5'
               call mula(aa3,'+-vo',elmat,n,3,jsgn,'I-')
               if(ysp0)call mula(aa3,'-+vo',elmat,n,3,jsgn,'A-','j-')
               !
               if(w)print*,'icas6'
               call mula(aa3,'+-vo',elmat,n,3,jsgn,'I-','j-')
               if(ysp0)call mula(aa3,'-+vo',elmat,n,3,jsgn,'A-')
            endif
            !
         endif
      endif
      !On va rajouter une particule b
      !det1 i--->[xy....]--->b det2 ab
      !////////////////////////////////////////////////
      if(w)print*,'mulccovd on ajoute une particule',x,y,i,a
      !////////////////////////////////////////////////
      ilca=ilc1(a)
      if (ilca/=0) then
         n=0
         nntp=0
         call caldfc(idist,1,1)
         call caldfc(idist2,0,2)
         do jpair1=idebliscond(i),idebliscond(i+1)-1
            jpair=liscond(jpair1)
            b=ilpair(2,jpair)
            ilcb=ilc1(b)
            if (ilcb==0) cycle
            n=n+1
            itp1(n)=il(i,b)
            if (ilca>ilcb) then
               itp2(n)=num1(ilca)+ilcb
            else if (ilca<ilcb) then
               itp2(n)=num1(ilcb)+ilca
            else
               itp2(n)=ilca
            endif
            call muladd_o_o(a,b,ltp1(n))
            nntp(ltp1(n))=nntp(ltp1(n))+1
            if(w)print'(a,20i4)','a,b,i',a,b,i,n,
     *      ltp1(n),nntp(ltp1(n)),
     *      itp1(n),itp2(n)
         enddo
         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)
            !
            elmat(1:3)=(/'I+    -> b+    |       -> A+ b+',
     *                   'I+    -> b+    |       -> b+ A+',
     *                   'I+    -> b+    |       -> A+=b+'/)
            call mula0(x,y,0,0)
            aa3=aa1
            !
            if(w)print*,'icas1'
            call mula(aa3,'+-ov',elmat,n,3,jsgn,'A-')
            if(ysp0)call mula(aa3,'-+ov',elmat,n,3,jsgn,'I-','b-')
            !
            if(w)print*,'icas2'
            call mula(aa3,'+-ov',elmat,n,3,jsgn,'A-','b-')
            if(ysp0)call mula(aa3,'-+ov',elmat,n,3,jsgn,'I-')
            !
            !==============
            !
            if(x/=y) then
               aa3=aa1-aa2
               !
               ydir=.false.
               yoci((/x,y/))=.true.
               if(w)print*,'icas3'
               call mula(aa3,'++ov',elmat,n,3,jsgn1)
               if(ysp0)
     *         call mula(aa3,'--ov',elmat,n,3,jsgn1,'A-','I-','b-')
               !
               if(w)print*,'icas4'
               call mula(aa3,'++ov',elmat,n,3,jsgn1,'b-')
               if(ysp0)call mula(aa3,'--ov',elmat,n,3,jsgn1,'A-','I-')
               ydir=.true.
               yoci((/x,y/))=.false.
               !
               !==============
               !
               aa3=aa2
               !
               if(w)print*,'icas5'
               call mula(aa3,'+-vo',elmat,n,3,jsgn,'I-')
               if(ysp0)call mula(aa3,'-+vo',elmat,n,3,jsgn,'A-','b-')
               !
               if(w)print*,'icas6'
               call mula(aa3,'+-vo',elmat,n,3,jsgn,'I-','b-')
               if(ysp0)call mula(aa3,'-+vo',elmat,n,3,jsgn,'A-')
            endif
            !
         endif
      endif
      !On va rajouter une particule b et un trou j
      !det1 ij--->[xy....]--->b det2 j--->ab
      if(igener<3) return
      !/////////////////////////////////////////////////////////////
      if(w)print*,'mulccovd on ajoute une particule et un trou',
     *x1,y1,i,a
      !/////////////////////////////////////////////////////////////
      n=0
      nntp=0
      call caldfc(idist,2,1)
      call caldfc(idist2,1,2)
      if (ilc1(a)/=0) then
         do jpair=1,nlpairp
            j=ilpair(1,jpair)
            b=ilpair(2,jpair)
            if(ilc1(i)/=0) then
               if(ipc(jpair,ilc1(i))==0) cycle
               if(ipc(jpair,nlco+ilc1(a))==0) cycle
               n=n+1
               itp1(n)=abs(ipc(jpair,ilc1(i)))
               itp2(n)=abs(ipc(jpair,nlco+ilc1(a)))
               call muladd_o_o(j,i,l1)
               call muladd_o_o(a,b,l2)
               ltp1(n)=l1+3*(l2-1)
               nntp(ltp1(n))=nntp(ltp1(n))+1
               if(w)print'(a,20i4)','a1,b,i,j',a,b,i,j,n,
     *         ltp1(n),nntp(ltp1(n)),
     *         itp1(n),itp2(n)
            endif
         enddo
      endif
!      else
         do jpair1=idebliscond(a),ifinliscond(a)
            jpair=liscond(jpair1)
            j=ilpair(1,jpair)
            do bb=1,nlcv
               b=ilc(nlco+bb)
               if(ilp(j,b)/=0.and.ilc1(a)/=0) cycle
               if(ilc1(i)/=0.and.ilp(j,b)/=0) then
                  if(ipc(ilp(j,b),ilc1(i))==0) cycle
                  if(ipc(jpair,nlco+ilc1(b))==0) cycle
                  n=n+1
                  itp1(n)=abs(ipc(ilp(j,b),ilc1(i)))
                  itp2(n)=abs(ipc(jpair,nlco+ilc1(b)))
                  call muladd_o_o(j,i,l1)
                  call muladd_o_o(a,b,l2)
                  ltp1(n)=l1+3*(l2-1)
                  nntp(ltp1(n))=nntp(ltp1(n))+1
                  if(w)print'(a,20i4)','a2,b,i,j',a,b,i,j,n,
     *            ltp1(n),nntp(ltp1(n)),
     *            itp1(n),itp2(n)
               else if(ilc1(j)/=0.and.ilp(i,b)/=0) then
                  if(ipc(ilp(i,b),ilc1(j))==0) cycle
                  if(ipc(jpair,nlco+ilc1(b))==0) cycle
                  n=n+1
                  itp1(n)=abs(ipc(ilp(i,b),ilc1(j)))
                  itp2(n)=abs(ipc(jpair,nlco+ilc1(b)))
                  call muladd_o_o(j,i,l1)
                  call muladd_o_o(a,b,l2)
                  ltp1(n)=l1+3*(l2-1)
                  nntp(ltp1(n))=nntp(ltp1(n))+1
                  if(w)print'(a,20i4)','a3,b,i,j',a,b,i,j,n,
     *            ltp1(n),nntp(ltp1(n)),
     *            itp1(n),itp2(n)
               endif
            enddo
         enddo
!      endif
      if(n>0) then
         call reoitp(n,9,nntp)
         if(w)print'(a,20i3)','ITP',itp1(1:n)
         if(w)print'(a,20i3)','ITP',itp2(1:n)
         !
         elmat(1:9)=(/'j+ I+ -> b+    | j+    -> A+ b+',
     *                'I+ j+ -> b+    | j+    -> A+ b+',
     *                'I+=j+ -> b+    | j+    -> A+ b+',
     *                'j+ I+ -> b+    | j+    -> b+ A+',
     *                'I+ j+ -> b+    | j+    -> b+ A+',
     *                'I+=j+ -> b+    | j+    -> b+ A+',
     *                'j+ I+ -> b+    | j+    -> A+=b+',
     *                'I+ j+ -> b+    | j+    -> A+=b+',
     *                'I+=j+ -> b+    | j+    -> A+=b+'/)
         call mula0(x,y,0,0)
         aa3=aa1
         !
         if(w)print*,'icas1'
         call mula(aa3,'+-ov',elmat,n,9,jsgn,'A-')
         if(ysp0)call mula(aa3,'-+ov',elmat,n,9,jsgn,'I-','b-','j-')
         !
         if(w)print*,'icas2'
         call mula(aa3,'+-ov',elmat,n,9,jsgn,'A-','j-')
         if(ysp0)call mula(aa3,'-+ov',elmat,n,9,jsgn,'I-','b-')
         !
         if(w)print*,'icas3'
         call mula(aa3,'+-ov',elmat,n,9,jsgn,'A-','b-')
         if(ysp0)call mula(aa3,'-+ov',elmat,n,9,jsgn,'I-','j-')
         !
         if(w)print*,'icas4'
         call mula(aa3,'+-ov',elmat,n,9,jsgn,'A-','b-','j-')
         if(ysp0)call mula(aa3,'-+ov',elmat,n,9,jsgn,'I-')
         !
         !================
         !
         if(x/=y) then
            aa3=aa1-aa2
            ydir=.false.
            yoci((/x,y/))=.true.
            if(w)print*,'icas21'
            call mula(aa3,'++ov',elmat,n,9,jsgn1)
            if(ysp0)
     *         call mula(aa3,'--ov',elmat,n,9,jsgn1,'A-','I-','b-','j-')
            !
            if(w)print*,'icas22'
            call mula(aa3,'++ov',elmat,n,9,jsgn1,'j-')
            if(ysp0)call mula(aa3,'--ov',elmat,n,9,jsgn1,'A-','I-','b-')
            !
            if(w)print*,'icas23'
            call mula(aa3,'++ov',elmat,n,9,jsgn1,'b-')
            if(ysp0)call mula(aa3,'--ov',elmat,n,9,jsgn1,'A-','I-','j-')
            !
            if(w)print*,'icas24'
            call mula(aa3,'++ov',elmat,n,9,jsgn1,'b-','j-')
            if(ysp0)call mula(aa3,'--ov',elmat,n,9,jsgn1,'A-','I-')
            ydir=.true.
            yoci((/x,y/))=.false.
            !
            !================
            !
            aa3=aa2
            if(w)print*,'icas31'
            call mula(aa3,'+-vo',elmat,n,9,jsgn,'I-')
            if(ysp0)call mula(aa3,'-+vo',elmat,n,9,jsgn,'A-','b-','j-')
            !
            if(w)print*,'icas32'
            call mula(aa3,'+-vo',elmat,n,9,jsgn,'I-','j-')
            if(ysp0)call mula(aa3,'-+vo',elmat,n,9,jsgn,'A-','b-')
            !
            if(w)print*,'icas33'
            call mula(aa3,'+-vo',elmat,n,9,jsgn,'I-','b-')
            if(ysp0)call mula(aa3,'-+vo',elmat,n,9,jsgn,'A-','j-')
            !
            if(w)print*,'icas34'
            call mula(aa3,'+-vo',elmat,n,9,jsgn,'I-','b-','j-')
            if(ysp0)call mula(aa3,'-+vo',elmat,n,9,jsgn,'A-')
         endif
      endif
 
      return
      end
