      subroutine mulcvvvd(x1,a,b,d,aaa1,aaa2)
      use module
      use mod_ena
      use mod_mula
      IMPLICIT REAL(8)(A-H,O-X,Z),logical(1)(y)
      integer a,x1,b,d,x,apair
      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...] -->a       det2 : -->bc
      !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 
 
      x=num_oav(x1)
      aa1=aaa1
      aa2=aaa2
      ysp1=itest(21)==1
      ysp0=itest(21)==0
      if(ysp1) then
         aa1=aa1*2
         aa2=aa2*2
      endif
 
 
      !a et b doivent etre lies au cas
      ! on n'ajoute rien
      !
      if(igener<2) return
      !//////////////////////////////////
      if(w)print*,'mulcvvvd 0',x1,a,b,d
      !//////////////////////////////////
      if ((ilc1(a).ne.0).and.(ilc1(b).ne.0).and.(ilc1(d).ne.0)) then
         n=1
         nntp=0
         call caldfc(idist,0,1)
         call caldfc(idist2,0,2)
         ii1=ilc1(b)
         ii2=ilc1(d)
         itp1(1)=ilc1(a)
         if (b>d) then
            itp2(1)=+num1(ii1)+ii2
            ltp1(1)=2
         elseif (b==d) then
            itp2(1)=ii1
            ltp1(1)=3
         else
            itp2(1)=num1(ii2)+ii1
            ltp1(1)=1
         endif
         nntp(ltp1(1))=nntp(ltp1(1))+1
         call reoitp(n,3,nntp)
         if(w)print'(a,20i4)','a,b,d',a,b,d,n,
     *   ltp1(n),nntp(ltp1(n)),
     *   itp1(n),itp2(n)
         nn=3
         if(b/=d) nn=2
         !
         elmat(1:3)=(/'      -> A+    |       -> B+ D+',
     *                '      -> A+    |       -> D+ B+',
     *                '      -> A+    |       -> D+=B+'/)
         call mula0(x,0,0,0)
         !
         if(w)print*,'icas1'
         call mula(aa1,'+vvv',elmat,n,nn,1,'A-','D-')
         if(ysp0)call mula(aa1,'-vvv',elmat,n,nn,1,'B-')
         !
         !========================
         if(d/=b) then
            !
            if(w)print*,'icas3'
            call mula(aa1-aa2,'+vvv',elmat,n,nn,1)
            if(ysp0)
     *      call mula(aa1-aa2,'-vvv',elmat,n,nn,1,'A-','D-','B-')
            !
            !======================
            !
            if(w)print*,'icas5'
            call mula(aa2,'+vvv',elmat,n,nn,1,'A-','B-')
            if(ysp0)call mula(aa2,'-vvv',elmat,n,nn,1,'D-')
            !
         endif
      endif
 
 
      !//////////////////////////////////
      !On va rajouter un trou i
      !det1 i--->[x]--->a det2 i--->bc
      !//////////////////////////////////
      !i doit etre lie a a
      if(igener<3) return
      if(w)print*,'1mulcvvvd on ajoute un trou',x,a,b,d
      n=0
      nntp=0
      call caldfc(idist,1,1)
      call caldfc(idist2,1,2)
      do ipairia=idebliscond(a),idebliscond(a+1)-1
         i=ilpair(1,liscond(ipairia))
         ipair2=ilp(i,b)
         ilc2=ilc1(d)
         if(ipair2==0.or.ilc2==0) then
            ipair2=ilp(i,d)
            ilc2=ilc1(b)
            if(ipair2==0.or.ilc2==0) cycle
         endif
         if(ipc(ipair2,nlco+ilc2)==0) cycle
         n=n+1
         itp1(n)=il(i,a)
         itp2(n)=abs(ipc(ipair2,nlco+ilc2))
         if (b>d) then
            ltp1(n)=2
         else if (b==d) then
            ltp1(n)=3
         else
            ltp1(n)=1
         endif
         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)
      enddo
      if(n/=0) then
         nn=3
         if(b/=d) nn=2
         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+    | i+    -> B+ D+',
     *                'i+    -> A+    | i+    -> D+ B+',
     *                'i+    -> A+    | i+    -> D+=B+'/)
 
         call mula0(x,0,0,0)
         !
         if(w)print*,'icas1'
         call mula(aa1,'+vvv',elmat,n,nn,1,'A-','D-')
         if(ysp0)call mula(aa1,'-vvv',elmat,n,nn,1,'B-','i-')
         !
         if(w)print*,'icas2'
         call mula(aa1,'+vvv',elmat,n,nn,1,'A-','D-','i-')
         if(ysp0)call mula(aa1,'-vvv',elmat,n,nn,1,'B-')
         !
         !========================
         if(d/=b) then
            jsgn=1
            !if(d<b) jsgn=-1
            !
            if(w)print*,'icas3'
            call mula(aa1-aa2,'+vvv',elmat,n,nn,jsgn)
            if(ysp0)call mula(aa1-aa2,'-vvv',elmat,n,nn,jsgn,
     *      'A-','D-','B-','i-')
            !
            if(w)print*,'icas4'
            call mula(aa1-aa2,'+vvv',elmat,n,nn,jsgn,'i-')
            if(ysp0)
     *      call mula(aa1-aa2,'-vvv',elmat,n,nn,jsgn,'A-','D-','B-')
            !
            !======================
            !
            if(w)print*,'icas5'
            call mula(aa2,'+vvv',elmat,n,nn,1,'A-','B-')
            if(ysp0)call mula(aa2,'-vvv',elmat,n,nn,1,'D-','i-')
            !
            if(w)print*,'icas6'
            call mula(aa2,'+vvv',elmat,n,nn,1,'A-','B-','i-')
            if(ysp0)call mula(aa2,'-vvv',elmat,n,nn,1,'D-')
            !
         endif
      endif
 
 
      !On va rajouter deux trous i et j
      !det1 ij--->[x....]--->a det2 ij--->bc
      if(igener<4) return
      !/////////////////////////////////////////////
      if(w)print*,'mulcvvvd on ajoute deux trous',x,a,b,d
      !/////////////////////////////////////////////
      !i liee a a et j doit etre liea au cas et i liee a b et j liee a c
      n=0
      nntp=0
      call caldfc(idist,2,1)
      call caldfc(idist2,2,2)
      do apair=idebliscond(a),ifinliscond(a)
         i=ilpair(1,liscond(apair))
         do jj=1,nlco
            j=ilc(jj)
            if (ilp(j,a)/=0.and.j<i.and.ilc1(i)/=0) cycle
            ipair_1=ilp(i,b)
            ipair_2=ilp(i,d)
            jpair_1=ilp(j,b)
            jpair_2=ilp(j,d)
            if (ipair_1/=0.and.jpair_2/=0) then
               if(ipc(ilp(i,a),ilc1(j))==0) cycle
               ii1=ipair_1
               ii2=jpair_2
               iimax=max(ipair_1,jpair_2)
               iimin=min(ipair_1,jpair_2)
               iio=iimax*(iimax-1)/2+iimin
               if(ipp(iio)==0) cycle
               n=n+1
               itp1(n)=abs(ipc(ilp(i,a),ilc1(j)))
               itp2(n)=abs(ipp(iio))
               if (b>d) then
                  ltp1(n)=2
               elseif (b==d) then
                  ltp1(n)=3
               else
                  ltp1(n)=1
               endif
               if(i==j) ltp1(n)=ltp1(n)+3
               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)
            elseif (ipair_2/=0.and.jpair_1/=0) then
               if(ipc(ilp(i,a),ilc1(j))==0) cycle
               ii1=ipair_2
               ii2=jpair_1
               iimax=max(ii1,ii2)
               iimin=min(ii1,ii2)
               iio=iimax*(iimax-1)/2+iimin
               if(ipp(iio)==0) cycle
               n=n+1
               itp1(n)=abs(ipc(ilp(i,a),ilc1(j)))
               itp2(n)=abs(ipp(iio))
               if (b>d) then
                  ltp1(n)=2
               elseif (b==d) then
                  ltp1(n)=3
               else
                  ltp1(n)=1
               endif
               if(i==j) ltp1(n)=ltp1(n)+3
               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)
            endif
         enddo
      enddo
      if(n/=0) then
         call reoitp(n,6,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:6)
         elmat(1:6)=(/'i+ j+ -> A+    | i+ j+ -> B+ D+',
     *                'i+ j+ -> A+    | i+ j+ -> D+ B+',
     *                'i+ j+ -> A+    | i+ j+ -> D+=B+',
     *                'i+=j+ -> A+    | i+=j+ -> B+ D+',
     *                'i+=j+ -> A+    | i+=j+ -> D+ B+',
     *                'i+=j+ -> A+    | i+=j+ -> D+=B+'/)
         !
         call mula0(x,0,0,0)
         !
         if(w)print*,'icas1'
         call mula(aa1,'+vvv',elmat,n,6,1,'A-','D-')
         if(ysp0)call mula(aa1,'-vvv',elmat,n,6,1,'B-','i-','j-')
         !
         if(w)print*,'icas2'
         call mula(aa1,'+vvv',elmat,n,6,1,'A-','D-','j-')
         if(ysp0)call mula(aa1,'-vvv',elmat,n,6,1,'B-','i-')
         !
         if(w)print*,'icas3'
         call mula(aa1,'+vvv',elmat,n,3,1,'A-','D-','i-')
         if(ysp0)call mula(aa1,'-vvv',elmat,n,3,1,'B-','j-')
         !
         if(w)print*,'icas4'
         call mula(aa1,'+vvv',elmat,n,6,1,'A-','D-','i-','j-')
         if(ysp0)call mula(aa1,'-vvv',elmat,n,6,1,'B-')
         !
         !========================
         !
         if(b/=d) then
            jsgn=1
!            if(d<b) jsgn=-1
            if(w)print*,'icas21',aa1,aa2,b,d
            call mula(aa1-aa2,'+vvv',elmat,n,6,jsgn)
            if(ysp0)call mula(aa1-aa2,'-vvv',elmat,n,6,jsgn,
     *      'A-','D-','B-','i-','j-')
            !
            if(w)print*,'icas22'
            call mula(aa1-aa2,'+vvv',elmat,n,6,jsgn,'j-')
            if(ysp0)
     *      call mula(aa1-aa2,'-vvv',elmat,n,6,jsgn,'A-','D-','B-','i-')
            !
            if(w)print*,'icas23'
            call mula(aa1-aa2,'+vvv',elmat,n,3,jsgn,'i-')
            if(ysp0)
     *      call mula(aa1-aa2,'-vvv',elmat,n,3,jsgn,'A-','D-','B-','j-')
            !
            if(w)print*,'icas24'
            call mula(aa1-aa2,'+vvv',elmat,n,6,jsgn,'i-','j-')
            if(ysp0)
     *      call mula(aa1-aa2,'-vvv',elmat,n,6,jsgn,'A-','D-','B-')
            !
            !======================
            !
            if(w)print*,'icas31'
            call mula(aa2,'+vvv',elmat,n,6,1,'A-','B-')
            if(ysp0)call mula(aa2,'-vvv',elmat,n,6,1,'D-','i-','j-')
            !
            if(w)print*,'icas32'
            call mula(aa2,'+vvv',elmat,n,6,1,'A-','B-','j-')
            if(ysp0)call mula(aa2,'-vvv',elmat,n,6,1,'D-','i-')
            !
            if(w)print*,'icas33'
            call mula(aa2,'+vvv',elmat,n,3,1,'A-','B-','i-')
            if(ysp0)call mula(aa2,'-vvv',elmat,n,3,1,'D-','j-')
            !
            if(w)print*,'icas34'
            call mula(aa2,'+vvv',elmat,n,6,1,'A-','B-','i-','j-')
            if(ysp0)call mula(aa2,'-vvv',elmat,n,6,1,'D-')
            !
         endif
      endif
 
      return
      end
