      subroutine mulcvovd(x1,a,i,b,aa1,aa2)
      use module
      use mod_ena
      use mod_ena2
      use mod_itp
      IMPLICIT REAL(8)(A-H,O-X,Z),logical(1)(y)
      integer a,x1,y1,z1,b,b1,x,y,z,i,i1,a1,d,dd,bb
      dimension ntp(0:27),aal(4),isec1(4),isec2(4)
      !
      !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
      ! 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-->[x...] -->a       det2 :-->b
      !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
      !i et a doivent etre liees et b liee au cas
      ! on n'ajoute rien
      !
      x=num_oav(x1)
      a1=num_oav(a)
      b1=num_oav(b)
      i1=num_oav(i)
      !
      ! signe : saut i-C
      jsgn=1-2*mod(ninac-num_oav(i),2)
 
      call mulcvovd_1(x1,a,i,b,aa1,aa2,x,a1,b1,i1,jsgn)
      if(itest(22)==1.and.iter==1) return
      call mulcvovd_2(x1,a,i,b,aa1,aa2,x,a1,b1,i1,jsgn)
 
 
      return
      end
       subroutine mulcvovd_1(x1,a,i,b,aa1,aa2,x,a1,b1,i1,jsgn)
      use module
      use mod_ena
      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,d,dd,bb
      dimension ntp(0:27),aal(4),isec1(4),isec2(4)
      character(31) elmat(27)
 
      !/////////////////////////////////
      if(w)print*,'mulcvovd 0',x,a,i,b
      !/////////////////////////////////
      call caldfc(idist,1,1)
      call caldfc(idist2,0,1)
 
      ysp1=itest(21)==1
      ysp0=itest(21)==0
      if ((ilc1(b)/=0).and.(il(i,a)/=0)) then
         itp1(1)=il(i,a)
         itp2(1)=ilc1(b)
         n=1
         nntp(1)=1
         ltp1(1)=1
         if(w)print'(a,20i3)','ITP',itp1(1:n)
         if(w)print'(a,20i3)','ITP',itp2(1:n)
         elmat(1)='I+    -> A+    |       -> B+   '
         call mula0(x,0,0,0)
         !
         aa3=aa1
         if(ysp1) aa3=aa3*2
         jsgn=1-mod(ninac-num_oav(i),2)*2
         !
         if(w)print*,'icas1',jsgn
         call mula(aa3,'+vov',elmat,n,1,jsgn,'A-','B-')
         if(ysp0)call mula(aa3,'-vov',elmat,n,1,jsgn,'I-')
         !
         !==========================
         !
         aa3=aa1-aa2
         if(ysp1) aa3=aa3*2
         !
         if(w)print*,'icas3',jsgn
         call mula(aa3,'+vov',elmat,n,1,jsgn)
         if(ysp0)call mula(aa3,'-vov',elmat,n,1,jsgn,'A-','I-','B-')
         !
         !==========================
         !
         aa3=aa2
         if(ysp1) aa3=aa3*2
         jsgna=1-mod(nocac0+ninac-num_oav(i),2)*2
         jsgnb=1-mod(nocbc0+ninac-num_oav(i),2)*2
         !
         if(w)print*,'icas5',jsgn
         call mula(aa3,'+vvo',elmat,n,1,jsgnb,'A-','I-')
         if(ysp0)call mula(aa3,'-vvo',elmat,n,1,jsgna,'B-','j-')
         !
      endif
 
 
      !On va rajouter un trou j
      !det1 ij--->[x....]--->a det2 j--->b
      if(igener<3) return
      if(itest(22)==1.and.iter==1) return
      !/////////////////////////////////////////////////
      if(w)print*,'mulcvovd On va rajouter un trou j',x,a,i,b
      !/////////////////////////////////////////////////
      n=0
      nntp=0
      call caldfc(idist,2,1)
      call caldfc(idist2,1,1)
      do jpair1=idebliscond(b),idebliscond(b+1)-1
         jpair=liscond(jpair1)
         j=ilpair(1,jpair)
         if ((ilp(j,a)/=0).and.(ilc1(i)/=0)) then
            if(ipc(ilp(j,a),ilc1(i))==0) cycle
            n=n+1
            itp2(n)=il(j,b)
            itp1(n)=abs(ipc(ilp(j,a),ilc1(i)))
            if(j<i) then
               ltp1(n)=1
            else if(j>i) then
               ltp1(n)=2
            else if(j==i) then
               ltp1(n)=3
            endif
            nntp(ltp1(n))=nntp(ltp1(n))+1
            if(w)print'(a,20i4)','a,b,j,i',a,b,j,i,n,
     *      ltp1(n),nntp(ltp1(n)),
     *      itp1(n),itp2(n)
         elseif((ilp(i,a)/=0).and.(ilc1(j)/=0)) then
            if(ipc(ilp(i,a),ilc1(j))==0) cycle
            n=n+1
            itp2(n)=il(j,b)
            itp1(n)=abs(ipc(ilp(i,a),ilc1(j)))
            if(j<i) then
               ltp1(n)=1
            else if(j>i) then
               ltp1(n)=2
            else if(j==i) then
               ltp1(n)=3
            endif
            nntp(ltp1(n))=nntp(ltp1(n))+1
            if(w)print'(a,20i4)','a,b,j,i',a,b,j,i,n,
     *      ltp1(n),nntp(ltp1(n)),
     *      itp1(n),itp2(n)
         endif
      enddo
      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+ -> A+    | j+    -> B+   ',
     *             'I+ j+ -> A+    | j+    -> B+   ',
     *             'I+=j+ -> A+    | j+    -> B+   '/)
      call mula0(x,0,0,0)
      !
      aa3=aa1
      if(ysp1) aa3=aa3*2
      jsgn=1-mod(ninac-num_oav(i),2)*2
      !
      if(w)print*,'icas1',jsgn
      call mula(aa3,'+vov',elmat,n,3,jsgn,'A-','B-')
      if(ysp0)call mula(aa3,'-vov',elmat,n,3,jsgn,'I-','j-')
      !
      if(w)print*,'icas2',jsgn
      call mula(aa3,'+vov',elmat,n,3,jsgn,'A-','B-','j-')
      if(ysp0)call mula(aa3,'-vov',elmat,n,3,jsgn,'I-')
      !
      !==========================
      !
      aa3=aa1-aa2
      if(ysp1) aa3=aa3*2
      !
      if(w)print*,'icas3',jsgn
      call mula(aa3,'+vov',elmat,n,3,jsgn)
      if(ysp0)call mula(aa3,'-vov',elmat,n,3,jsgn,'A-','I-','B-','j-')
      !
      if(w)print*,'icas4',jsgn
      call mula(aa3,'+vov',elmat,n,3,jsgn,'j-')
      if(ysp0)call mula(aa3,'-vov',elmat,n,3,jsgn,'A-','I-','B-')
      !
      !==========================
      !
      aa3=aa2
      if(ysp1) aa3=aa3*2
      jsgna=1-mod(nocac0+ninac-num_oav(i),2)*2
      jsgnb=1-mod(nocbc0+ninac-num_oav(i),2)*2
      !
      if(w)print*,'icas5',jsgn
      call mula(aa3,'+vvo',elmat,n,3,jsgnb,'A-','I-')
      if(ysp0)call mula(aa3,'-vvo',elmat,n,3,jsgna,'B-','j-')
      !
      !
      if(w)print*,'icas6',jsgn
      call mula(aa3,'+vvo',elmat,n,3,-jsgnb,'A-','I-','j-')
      if(ysp0)call mula(aa3,'-vvo',elmat,n,3,-jsgna,'B-')
      !
 
 
      !///////////////////////////////
      !On va rajouter une particule d
      !det1 i--->[x....]--->ad det2 bd
      !///////////////////////////////
      if(w)print*,'mulcvovd on ajoute une particule',x1,a,i,b
      if (ilc1(b)==0) return
      n=0
      nntp=0
      call caldfc(idist,1,2)
      call caldfc(idist2,0,2)
      bb=ilc1(b)
      do dd=1,nlcv
         d=ilc(nlco+dd)
         if (ilp(i,a)/=0) then
            if(ipc(ilp(i,a),nlco+ilc1(d))==0) cycle
            n=n+1
            itp1(n)=abs(ipc(ilp(i,a),nlco+ilc1(d)))
            if (bb>dd) then
               itp2(n)=num1(bb)+dd
            elseif (d==b) then
               itp2(n)=dd
            else
               itp2(n)=num1(dd)+bb
            endif
            call mulcvovd_4(a,b,d,ltp1(n))
            nntp(ltp1(n))=nntp(ltp1(n))+1
            if(w)print'(a,20i4)','a,b,d,i',a,b,d,i,n,
     *      ltp1(n),nntp(ltp1(n)),
     *      itp1(n),itp2(n)
         elseif((ilp(i,d)/=0).and.(ilc1(a)/=0)) then
            if(ipc(ilp(i,d),nlco+ilc1(a))==0) cycle
            n=n+1
            itp1(n)=abs(ipc(ilp(i,d),nlco+ilc1(a)))
            if (bb>dd) then
               itp2(n)=num1(bb)+dd
            elseif (d==b) then
               itp2(n)=dd
            else
               itp2(n)=num1(dd)+bb
            endif
            call mulcvovd_4(a,b,d,ltp1(n))
            nntp(ltp1(n))=nntp(ltp1(n))+1
            if(w)print'(a,20i4)','a,b,d,i',a,b,d,i,n,
     *      ltp1(n),nntp(ltp1(n)),
     *      itp1(n),itp2(n)
         endif
      enddo
      if(n==0) return
      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)=(/'I+    -> A+ d+ |       -> B+ d+',
     *             'I+    -> d+ A+ |       -> d+ B+',
     *             'I+    -> A+ d+ |       -> d+ B+',
     *             'I+    -> d+ A+ |       -> B+ d+',
     *             'I+    -> d+=A+ |       -> d+ B+',
     *             'I+    -> d+=A+ |       -> B+ d+',
     *             'I+    -> d+ A+ |       -> d+=B+',
     *             'I+    -> A+ d+ |       -> d+=B+',
     *             'I+    -> d+=A+ |       -> d+=B+'/)
      call mula0(x,0,0,0)
      !
      aa3=aa1
      if(ysp1) aa3=aa3*2
      jsgn=1-mod(ninac-num_oav(i),2)*2
      !
      if(w)print*,'icas1'
      call mula(aa3,'+vov',elmat,n,9,jsgn,'A-','B-')
      if(ysp0)call mula(aa3,'-vov',elmat,n,9,jsgn,'I-','d-')
      !
      !
      if(w)print*,'icas2'
      call mula(aa3,'+vov',elmat,n,9,jsgn,'A-','B-','d-')
      if(ysp0)call mula(aa3,'-vov',elmat,n,9,jsgn,'I-')
      !
      !==========================
      !
      aa3=aa1-aa2
      if(ysp1) aa3=aa3*2
      !
      if(w)print*,'icas3'
      call mula(aa3,'+vov',elmat,n,9,jsgn)
      if(ysp0)call mula(aa3,'-vov',elmat,n,9,jsgn,'A-','I-','B-','d-')
      !
      if(w)print*,'icas4'
      call mula(aa3,'+vov',elmat,n,9,jsgn,'d-')
      if(ysp0)call mula(aa3,'-vov',elmat,n,9,jsgn,'A-','I-','B-')
      !
      !==========================
      !
      aa3=aa2
      if(ysp1) aa3=aa3*2
      jsgna=1-mod(ninac+nocac0+num_oav(i),2)*2
      jsgnb=1-mod(ninac+nocbc0+num_oav(i),2)*2
      !
      if(w)print*,'icas5'
      call mula(aa3,'+vvo',elmat,n,9,jsgnb,'A-','I-')
      if(ysp0)call mula(aa3,'-vvo',elmat,n,9,jsgna,'B-','d-')
      !
      !
      if(w)print*,'icas6',aa1,aa2
      call mula(aa3,'+vvo',elmat,n,9,-jsgnb,'A-','I-','d-')
      if(ysp0)call mula(aa3,'-vvo',elmat,n,9,-jsgna,'B-')
      !
 
 
      return
      end
       subroutine mulcvovd_3(i,j,a,b,d,ltp1)
      IMPLICIT REAL(8)(A-H,O-X,Z),logical(1)(y)
      integer(1) ltp1
      integer a,b,i,d,j
      call mulcvovd_4(a,b,d,ltp1)
      if(j>i) then
         ltp1=ltp1+9
      else if (j==i) then
         ltp1=ltp1+18
      endif
      return
      end
       subroutine mulcvovd_2(x1,a,i,b,aa1,aa2,x,a1,b1,i1,jsgn)
      use module
      use mod_ena
      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,d,dd,bb
      dimension ntp(0:27),aal(4),isec1(4),isec2(4)
      character(31) elmat(27)
 
 
      !/////////////////////////////////////////////
      !On va rajouter une particule d et un trou j
      !det1 ij-->[x....]--->ad det2 j--->bd
      !/////////////////////////////////////////////
      if(igener<4) return
      if(w)print*,'mulcvovd on ajoute une particule et un trou',
     *x1,a,i,b
      ysp1=itest(21)==1
      ysp0=itest(21)==0
      n=0
      nntp=0
      call caldfc(idist,2,2)
      call caldfc(idist2,1,2)
      if (ilc1(b)/=0) then
         do jpair=1,nlpairp
            ipair=ilp(i,a)
            j=ilpair(1,jpair)
            d=ilpair(2,jpair)
            if ((ilp(j,b)/=0).and.(ilc1(d)/=0)) cycle
            nv=n
            if (ilp(i,a)/=0) then
               if(ipc(ilp(j,d),nlco+ilc1(b))==0) cycle
               ipair=ilp(i,a)
               kpair=ilp(j,d)
               iimax=max(ipair,kpair)
               iimin=min(ipair,kpair)
               ii1=iimax*(iimax-1)/2+iimin
               if(ipp(ii1)==0) cycle
               n=n+1
               itp1(n)=abs(ipp(ii1))
               itp2(n)=abs(ipc(ilp(j,d),nlco+ilc1(b)))
            elseif((ilp(j,a)/=0).and.(ilp(i,d)/=0)) then
               if(ipc(ilp(j,d),nlco+ilc1(b))==0) cycle
               ipair=ilp(j,a)
               kpair=ilp(i,d)
               iimax=max(ipair,kpair)
               iimin=min(ipair,kpair)
               ii1=iimax*(iimax-1)/2+iimin
               if(ipp(ii1)==0) cycle
               n=n+1
               itp1(n)=abs(ipp(ii1))
               itp2(n)=abs(ipc(ilp(j,d),nlco+ilc1(b)))
            endif
            if(nv==n) cycle
            call mulcvovd_3(i,j,a,b,d,ltp1(n))
            nntp(ltp1(n))=nntp(ltp1(n))+1
            if(w)print'(a,20i4)','a,b,d,i,j',a,b,d,i,j,n,
     *      ltp1(n),nntp(ltp1(n)),
     *      itp1(n),itp2(n)
         enddo
      endif
      do jpair1=idebliscond(b),ifinliscond(b)
         jpair=liscond(jpair1)
         j=ilpair(1,jpair)
         do dd=1,nlcv
            d=ilc(nlco+dd)
            nv=n
            if ((ilp(i,a)/=0).and.(ilp(j,d)/=0)) then
               if(ipc(ilp(j,b),nlco+ilc1(d))==0) cycle
               ipair=ilp(i,a)
               kpair=ilp(j,d)
               iimax=max(ipair,kpair)
               iimin=min(ipair,kpair)
               ii1=iimax*(iimax-1)/2+iimin
               if(ipp(ii1)==0) cycle
               n=n+1
               itp1(n)=abs(ipp(ii1))
               itp2(n)=abs(ipc(ilp(j,b),nlco+ilc1(d)))
            elseif((ilp(j,a)/=0).and.(ilp(i,d)/=0)) then
               if(ipc(ilp(j,b),nlco+ilc1(d))==0) cycle
               ipair=ilp(j,a)
               kpair=ilp(i,d)
               iimax=max(ipair,kpair)
               iimin=min(ipair,kpair)
               ii1=iimax*(iimax-1)/2+iimin
               if(ipp(ii1)==0) cycle
               n=n+1
               itp1(n)=abs(ipp(ii1))
               itp2(n)=abs(ipc(ilp(j,b),nlco+ilc1(d)))
            endif
            if(nv==n) cycle
            call mulcvovd_3(i,j,a,b,d,ltp1(n))
            nntp(ltp1(n))=nntp(ltp1(n))+1
            if(w)print'(a,20i4)','a,b,d,i,j',a,b,d,i,j,n,
     *      ltp1(n),nntp(ltp1(n)),
     *      itp1(n),itp2(n)
         enddo
      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+ I+ -> A+ d+ | j+    -> B+ d+',
     *             'j+ I+ -> d+ A+ | j+    -> d+ B+',
     *             'j+ I+ -> A+ d+ | j+    -> d+ B+',
     *             'j+ I+ -> d+ A+ | j+    -> B+ d+',
     *             'j+ I+ -> d+=A+ | j+    -> d+ B+',
     *             'j+ I+ -> d+=A+ | j+    -> B+ d+',
     *             'j+ I+ -> d+ A+ | j+    -> d+=B+',
     *             'j+ I+ -> A+ d+ | j+    -> d+=B+',
     *             'j+ I+ -> d+=A+ | j+    -> d+=B+'/)
      elmat(10:18)=elmat(1:9)
      elmat(19:27)=elmat(1:9)
      elmat(10:18)(1:6)='I+ j+'
      elmat(19:27)(1:6)='j+=I+'
      call mula0(x,0,0,0)
      !
      aa3=aa1
      if(ysp1) aa3=aa3*2
      jsgn=1-mod(ninac-num_oav(i),2)*2
      !
      if(w)print*,'icas1'
      call mula(aa3,'+vov',elmat,n,27,jsgn,'A-','B-')
      if(ysp0)call mula(aa3,'-vov',elmat,n,27,jsgn,'j-','I-','d-')
      !
      !
      if(w)print*,'icas2'
      call mula(aa3,'+vov',elmat,n,27,jsgn,'A-','B-','j-')
      if(ysp0)call mula(aa3,'-vov',elmat,n,27,jsgn,'I-','d-')
      !
      !
      if(w)print*,'icas3'
      call mula(aa3,'+vov',elmat,n,27,jsgn,'A-','B-','d-')
      if(ysp0)call mula(aa3,'-vov',elmat,n,27,jsgn,'I-','j-')
      !
      !
      if(w)print*,'icas4'
      call mula(aa3,'+vov',elmat,n,27,jsgn,'A-','B-','d-','j-')
      if(ysp0)call mula(aa3,'-vov',elmat,n,27,jsgn,'I-')
      !
      !============
      !
      !
      aa3=aa1-aa2
      if(ysp1) aa3=aa3*2
      jsgn=1-mod(ninac-num_oav(i),2)*2
      if(w)print*,'icas5'
      call mula(aa3,'+vov',elmat,n,27,jsgn)
      if(ysp0)
     *call mula(aa3,'-vov',elmat,n,27,jsgn,'I-','A-','B-','d-','j-')
      !
      !
      if(w)print*,'icas6'
      call mula(aa3,'+vov',elmat,n,27,jsgn,'j-')
      if(ysp0)call mula(aa3,'-vov',elmat,n,27,jsgn,'I-','A-','B-','d-')
      !
      !
      if(w)print*,'icas7'
      call mula(aa3,'+vov',elmat,n,27,jsgn,'d-')
      if(ysp0)call mula(aa3,'-vov',elmat,n,27,jsgn,'I-','A-','B-','j-')
      !
      !
      if(w)print*,'icas8'
      call mula(aa3,'+vov',elmat,n,27,jsgn,'d-','j-')
      if(ysp0)call mula(aa3,'-vov',elmat,n,27,jsgn,'I-','A-','B-')
      !
      !============
      !
 
      aa3=aa2
      if(ysp1) aa3=aa3*2
      jsgna=1-mod(ninac+nocac0-num_oav(i),2)*2
      jsgnb=1-mod(ninac+nocbc0-num_oav(i),2)*2
      if(w)print*,'icas9'
      call mula(aa3,'+vvo',elmat,n,27,jsgnb,'I-','A-')
      if(ysp0)call mula(aa3,'-vvo',elmat,n,27,jsgna,'B-','d-','j-')
      !
      !
      if(w)print*,'icasa'
      call mula(aa3,'+vvo',elmat,n,27,-jsgnb,'I-','A-','j-')
      if(ysp0)call mula(aa3,'-vvo',elmat,n,27,-jsgna,'B-','d-')
      !
      !
      if(w)print*,'icasb'
      call mula(aa3,'+vvo',elmat,n,27,-jsgnb,'I-','A-','d-')
      if(ysp0)call mula(aa3,'-vvo',elmat,n,27,-jsgna,'B-','j-')
      !
      !
      if(w)print*,'icasc'
      call mula(aa3,'+vvo',elmat,n,27,jsgnb,'I-','A-','d-','j-')
      if(ysp0)call mula(aa3,'-vvo',elmat,n,27,jsgna,'B-')
 
 
 
 
      return
      end
 
       subroutine mulcvovd_4(a,b,d,ltp1)
      IMPLICIT REAL(8)(A-H,O-X,Z),logical(1)(y)
      integer(1) ltp1
      integer a,b,i,d
      if(a<b) then
         if(d<a) then
            ltp1=2
         else if(d==a) then
            ltp1=5
         else if(d<b) then
            ltp1=3
         else if(d==b) then
            ltp1=8
         else
            ltp1=1
         endif
      else if(a>b) then
         if(d<b) then
            ltp1=2
         else if(d==b) then
            ltp1=7
         else if(d<a) then
            ltp1=4
         else if(d==a) then
            ltp1=6
         else
            ltp1=1
         endif
      else if(a==b) then
         if(d<a) then
            ltp1=2
         else if(d>a) then
            ltp1=1
         else
            ltp1=9
         endif
      endif
      return
      end
