      subroutine mulcoood(x1,i,j,k,aa1,aa2)
      use module
      use mod_ena
      use mod_itp
      use mod_mula
      IMPLICIT REAL(8)(A-H,O-X,Z),logical(1)(y)
      integer a,x1,b,d,x,i1,j3,k,k1,i,j,apair,bb,bpair
      dimension ntp(0:6),aal(4),isec1(4),isec2(4)
      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 : jk--->[x...]       det2 : -->i
      !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
      ! Rem: Si les ind sont tous differents, on a toujours j>k
      !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 
 
 
      ysp1=itest(21)==1
      ysp0=itest(21)==0
      i1=num_oav(i)
      j3=num_oav(j)
      k1=num_oav(k)
      x=num_oav(x1)
      if(w)print*,'mulcoood 0',x1,i,j,k
      call caldfc(idist,2,0)
      call caldfc(idist2,1,0)
      !
      !signe
      jsgn=1-mod(ninac+num_oav(j)+num_oav(i)+num_oav(k),2)*2
      if(w)print*,'i,j,k,jsgn',i,j,k,jsgn,aa1,aa2
      jsgn1=-jsgn
      jsgn2=-jsgn
      jsgn3=-jsgn
      !if(i==k.and.i>j) jsgn2=jsgn
      !if(k<j.and.j<i) jsgn2=jsgn
      if(igener<2) return
      n=0
      nntp=0
      if (ilc1(i).ne.0.and.ilc1(j).ne.0.and.ilc1(k).ne.0) then
         ! Adresse de la partie tp
         ii1=ilc1(j)
         ii2=ilc1(k)
         itp2(1)=ilc1(i)
         n=n+1
         if (j>k) then
            itp1(1)=+num1(ii1)+ii2
            ltp1(1)=1
         elseif (j==k) then
            itp1(1)=ii1
            ltp1(1)=3
         else
            itp1(1)=num1(ii2)+ii1
            ltp1(1)=2
         endif
         nntp(ltp1(n))=nntp(ltp1(n))+1
         if(w)print'(a,20i4)','i,j,k',i,j,k,n,
     *   ltp1(n),nntp(ltp1(n)),
     *   itp1(n),itp2(n)
         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)=(/'K+ J+ ->       | I+    ->      ',
     *                'J+ K+ ->       | I+    ->      ',
     *                'J+=K+ ->       | I+    ->      '/)
         call mula0(x,0,0,0)
         !
         aa3=aa1
         if(ysp1) aa3=aa3*2
         if(w)print*,'icas1'
         call mula(aa3,'+ooo',elmat,n,3,jsgn1,'I-','K-')
         if(ysp0)call mula(aa3,'-ooo',elmat,n,3,jsgn1,'J-')
         !
         !==========================
         !
         if(j/=k) then
            aa3=aa1-aa2
            if(ysp1) aa3=aa3*2
!            jsgn1=jsgn
            !signes: depend de l'ordre des indices I J K
            ! J I K x  I->K:(K-I-1)  J->x:(ninac-j-1)  --> K+I+J+ninac
            ! J K I x  idem
            ! I J K x  =-(J I K x)  K+I+J+ninac+1
            ! K I J x  I->K:(K-I-1)  J->x:(ninac-j)  --> K+I+J+ninac+1
            ! K J I x  =-(J K I x)=-(J I K x)        --> K+I+J+ninac+1
            ! I K J x  =-(K I J x)                   --> K+I+J+ninac
            !
!            if(w)print*,'icas',jsgn1
!            if(i==k.or.j==k) then
!               if(k<i.and.k<j) jsgn1=-jsgn1
!               if(i<j.and.j<k) jsgn1=-jsgn1
!               if(i==k.and.i<j) jsgn1=-jsgn1
!               if(k<j) jsgn1=-jsgn1
!            else
!         !      if(i<j) jsgn1=-jsgn1
!            endif
            if(w)print*,'icas3'
!            if(i<j.and.j<k) jsgn1=-jsgn1
!            if(i>j.and.j>k) jsgn1=-jsgn1
            !
            call mula(aa3,'+ooo',elmat,n,3,jsgn2)
            if(ysp0)call mula(aa3,'-ooo',elmat,n,3,jsgn2,'J-','I-','K-')
            !
            !==========================
            !
            aa3=aa2
            if(ysp1) aa3=aa3*2
            !
            if(w)print*,'icas5'
            call mula(aa3,'+ooo',elmat,n,3,jsgn3,'I-','J-')
            if(ysp0)call mula(aa3,'-ooo',elmat,n,3,jsgn3,'K-')
         endif
      endif
 
 
 
 
      !On va rajouter une particule a
      !det1 jk--->[x]--->a det2 i--->a
      if(igener<3) return
      if(w)print*,'mulcoood On va rajouter une particule a',x1,i,j,k
 
      n=0
      nntp=0
      call caldfc(idist,2,1)
      call caldfc(idist2,1,1)
      do apair=idebliscond(i),idebliscond(i+1)-1
         a=ilpair(2,liscond(apair))
         if ((ilp(j,a)/=0).and.(ilc1(k)/=0)) then
            !a liee a i et b liee a i et c liee au cas
            if(ipc(ilp(j,a),ilc1(k))==0) cycle
            n=n+1
            itp2(n)=il(i,a)
            itp1(n)=abs(ipc(ilp(j,a),ilc1(k)))
            if(j<k) then
               ltp1(n)=2
            else if(j>k) then
               ltp1(n)=1
            else
               ltp1(n)=3
            endif
            nntp(ltp1(n))=nntp(ltp1(n))+1
            if(w)print'(a,20i4)','a,i,j,k',a,i,j,k,n,
     *      ltp1(n),nntp(ltp1(n)),
     *      itp1(n),itp2(n)
         elseif ((ilp(k,a)/=0).and.(ilc1(j)/=0)) then
            if(ipc(ilp(k,a),ilc1(j))==0) cycle
            n=n+1
            itp2(n)=il(i,a)
            itp1(n)=abs(ipc(ilp(k,a),ilc1(j)))
            if(j<k) then
               ltp1(n)=2
            else if(j>k) then
               ltp1(n)=1
            else
               ltp1(n)=3
            endif
            nntp(ltp1(n))=nntp(ltp1(n))+1
            if(w)print'(a,20i4)','a,i,j,k',a,i,j,k,n,
     *      ltp1(n),nntp(ltp1(n)),
     *      itp1(n),itp2(n)
         endif
      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)=(/'K+ J+ -> a+    | I+    -> a+   ',
     *                'J+ K+ -> a+    | I+    -> a+   ',
     *                'J+=K+ -> a+    | I+    -> a+   '/)
         call mula0(x,0,0,0)
         aa3=aa1
         if(ysp1) aa3=aa3*2
!         jsgn=1-mod(ninac+num_oav(i)+num_oav(j)+num_oav(k),2)*2
         !
         if(w)print*,'icas1',jsgn1
         call mula(aa3,'+ooo',elmat,n,3,jsgn1,'I-','K-')
         if(ysp0)call mula(aa3,'-ooo',elmat,n,3,jsgn1,'J-','a-')
         !
         if(w)print*,'icas2',jsgn1
         call mula(aa3,'+ooo',elmat,n,3,jsgn1,'I-','K-','a-')
         if(ysp0)call mula(aa3,'-ooo',elmat,n,3,jsgn1,'J-')
         !
         !==========================
         !
         if(j/=k) then
            aa3=aa1-aa2
            if(ysp1) aa3=aa3*2
!            jsgn1=jsgn
            !signes: depend de l'ordre des indices I J K
            ! J I K x  I->K:(K-I-1)  J->x:(ninac-j-1)  --> K+I+J+ninac
            ! J K I x  idem
            ! I J K x  =-(J I K x)  K+I+J+ninac+1
            ! K I J x  I->K:(K-I-1)  J->x:(ninac-j)  --> K+I+J+ninac+1
            ! K J I x  =-(J K I x)=-(J I K x)        --> K+I+J+ninac+1
            ! I K J x  =-(K I J x)                   --> K+I+J+ninac
            !
            if(w)print*,'icas3',jsgn2
!            if(i==k.or.j==k) then
!               if(k<i.and.k<j) jsgn1=-jsgn1
!               if(i<j.and.j<k) jsgn1=-jsgn1
!               if(i==k.and.i<j) jsgn1=-jsgn1
!               if(k<j) jsgn1=-jsgn1
!            else
!         !      if(i<j) jsgn1=-jsgn1
!            endif
            !
            if(w)print*,'aa1,aa2',aa1,aa2,jsgn2
            call mula(aa3,'+ooo',elmat,n,3,jsgn2)
            if(ysp0)
     *      call mula(aa3,'-ooo',elmat,n,3,jsgn2,'J-','a-','I-','K-')
            !
            if(w)print*,'icas4',jsgn2
            call mula(aa3,'+ooo',elmat,n,3,jsgn2,'a-')
            if(ysp0)call mula(aa3,'-ooo',elmat,n,3,jsgn2,'J-','I-','K-')
            !
            !==========================
            !
            aa3=aa2
            if(ysp1) aa3=aa3*2
            !
            if(w)print*,'icas5'
            call mula(aa3,'+ooo',elmat,n,3,jsgn3,'I-','J-')
            if(ysp0)call mula(aa3,'-ooo',elmat,n,3,jsgn3,'K-','a-')
 
            if(w)print*,'icas6'
            call mula(aa3,'+ooo',elmat,n,3,jsgn3,'I-','J-','a-')
            if(ysp0)call mula(aa3,'-ooo',elmat,n,3,jsgn3,'K-')
         endif
         !
      endif
      !
      !
      !/////////////////////////////////////////////////////////////
      if(w)print*,'mulcoood On va rajouter deux particules a et b',
     *x1,i,j,k
      !/////////////////////////////////////////////////////////////
      if(igener<4) return
      n=0
      nntp=0
      call caldfc(idist,2,2)
      call caldfc(idist2,1,2)
      do apair=idebliscond(i),ifinliscond(i)
         a=ilpair(2,liscond(apair))
         do bb=1,nlcv
            b=ilc(nlco+bb)
            if(a>b.and.ilp(i,b)/=0.and.ilc1(a)/=0) cycle
            ipair_1=ilp(j,a)
            ipair_2=ilp(k,a)
            jpair_1=ilp(j,b)
            jpair_2=ilp(k,b)
            if (ipair_1/=0.and.jpair_2/=0) then
               iimax=max(ipair_1,jpair_2)
               iimin=min(ipair_1,jpair_2)
               iio=iimax*(iimax-1)/2+iimin
               if(ipp(iio)==0) cycle
               if(ipc(ilp(i,a),nlco+bb)==0) cycle
               n=n+1
               itp1(n)=abs(ipp(iio))
               itp2(n)=abs(ipc(ilp(i,a),nlco+bb))
            elseif (ipair_2/=0.and.jpair_1/=0) then
               iimax=max(ipair_2,jpair_1)
               iimin=min(ipair_2,jpair_1)
               iio=iimax*(iimax-1)/2+iimin
               if(ipp(iio)==0) cycle
               if(ipc(ilp(i,a),nlco+bb)==0) cycle
               n=n+1
               itp1(n)=abs(ipp(iio))
               itp2(n)=abs(ipc(ilp(i,a),nlco+bb))
            else
               cycle
            endif
            if(j<k) then
               ltp1(n)=2
            else if(j>k) then
               ltp1(n)=1
            else
               ltp1(n)=3
            endif
            if(a==b) ltp1(n)=ltp1(n)+3
            nntp(ltp1(n))=nntp(ltp1(n))+1
            if(w)print'(a,10i4)','j,k,i,a,b',
     *      j,k,i,a,b,n,ltp1(n),nntp(ltp1(n)),
     *      itp1(n),itp2(n)
         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)
         !
         elmat(1:6)=(/'K+ J+ -> a+ b+ | I+    -> a+ b+',
     *                'J+ K+ -> a+ b+ | I+    -> a+ b+',
     *                'J+=K+ -> a+ b+ | I+    -> a+ b+',
     *                'K+ J+ -> b+=a+ | I+    -> b+=a+',
     *                'J+ K+ -> b+=a+ | I+    -> b+=a+',
     *                'J+=K+ -> b+=a+ | I+    -> b+=a+'/)
         call mula0(x,0,0,0)
         aa3=aa1
         if(ysp1) aa3=aa3*2
!         jsgn=1-mod(ninac+num_oav(i)+num_oav(j)+num_oav(k),2)*2
         !
         if(w)print*,'icas1'
         call mula(aa3,'+ooo',elmat,n,6,jsgn1,'I-','K-')
         if(ysp0)call mula(aa3,'-ooo',elmat,n,6,jsgn1,'J-','a-','b-')
         !
         if(w)print*,'icas2'
         call mula(aa3,'+ooo',elmat,n,6,jsgn1,'I-','K-','b-')
         if(ysp0)call mula(aa3,'-ooo',elmat,n,6,jsgn1,'J-','a-')
         !
         if(w)print*,'icas3'
         call mula(aa3,'+ooo',elmat,n,3,jsgn1,'I-','K-','a-')
         if(ysp0)call mula(aa3,'-ooo',elmat,n,3,jsgn1,'J-','b-')
         !
         if(w)print*,'icas4'
         call mula(aa3,'+ooo',elmat,n,6,jsgn1,'I-','K-','a-','b-')
         if(ysp0)call mula(aa3,'-ooo',elmat,n,6,jsgn1,'J-')
         !
         !==========================
         !
         if(j/=k) then
            aa3=aa1-aa2
            if(ysp1) aa3=aa3*2
!            jsgn1=jsgn
!            !signes: depend de l'ordre des indices I J K
!            ! J I K x  I->K:(K-I-1)  J->x:(ninac-j-1)  --> K+I+J+ninac
!            ! J K I x  idem
!            ! I J K x  =-(J I K x)  K+I+J+ninac+1
!            ! K I J x  I->K:(K-I-1)  J->x:(ninac-j)  --> K+I+J+ninac+1
!            ! K J I x  =-(J K I x)=-(J I K x)        --> K+I+J+ninac+1
!            ! I K J x  =-(K I J x)                   --> K+I+J+ninac
!            !
!            if(i==k.or.j==k) then
!               if(k<i.and.k<j) jsgn1=-jsgn1
!               if(i<j.and.j<k) jsgn1=-jsgn1
!               if(i==k.and.i<j) jsgn1=-jsgn1
!               if(k<j) jsgn1=-jsgn1
!            else
!         !      if(i<j) jsgn1=-jsgn1
!            endif
!            jsgn1=jsgn
!            if(w)print*,'icas3'
!            !signes: depend de l'ordre des indices I J K
!            ! J I K x  I->K:(K-I-1)  J->x:(ninac-j-1)  --> K+I+J+ninac
!            ! J K I x  idem
!            ! I J K x  =-(J I K x)  K+I+J+ninac+1
!            ! K I J x  I->K:(K-I-1)  J->x:(ninac-j)  --> K+I+J+ninac+1
!            ! K J I x  =-(J K I x)=-(J I K x)        --> K+I+J+ninac+1
!            ! I K J x  =-(K I J x)                   --> K+I+J+ninac
!            !
!            if(k<i.and.k<j) jsgn1=-jsgn1
!            if(i<j.and.j<k) jsgn1=-jsgn1
            !
            if(w)print*,'icas5'
            call mula(aa3,'+ooo',elmat,n,6,jsgn2)
            if(ysp0)call mula(aa3,'-ooo',elmat,n,6,jsgn2,
     *      'J-','I-','K-','a-','b-')
            !
            if(w)print*,'icas6'
            call mula(aa3,'+ooo',elmat,n,6,jsgn2,'b-')
            if(ysp0)
     *      call mula(aa3,'-ooo',elmat,n,6,jsgn2,'J-','I-','K-','a-')
            !
            if(w)print*,'icas7'
            call mula(aa3,'+ooo',elmat,n,3,jsgn2,'a-')
            if(ysp0)
     *      call mula(aa3,'-ooo',elmat,n,3,jsgn2,'J-','I-','K-','b-')
            !
            if(w)print*,'icas8'
            call mula(aa3,'+ooo',elmat,n,6,jsgn2,'a-','b-')
            if(ysp0)call mula(aa3,'-ooo',elmat,n,6,jsgn2,'J-','I-','K-')
            !
            !==========================
            !
            aa3=aa2
            if(ysp1) aa3=aa3*2
            !
            if(w)print*,'icas9'
            call mula(aa3,'+ooo',elmat,n,6,jsgn3,'I-','J-')
            if(ysp0)call mula(aa3,'-ooo',elmat,n,6,jsgn3,'K-','a-','b-')
            !
            if(w)print*,'icasa'
            call mula(aa3,'+ooo',elmat,n,6,jsgn3,'I-','J-','b-')
            if(ysp0)call mula(aa3,'-ooo',elmat,n,6,jsgn3,'K-','a-')
            !
            if(w)print*,'icasb'
            call mula(aa3,'+ooo',elmat,n,3,jsgn3,'I-','J-','a-')
            if(ysp0)call mula(aa3,'-ooo',elmat,n,3,jsgn3,'K-','b-')
            !
            if(w)print*,'icasc'
            call mula(aa3,'+ooo',elmat,n,6,jsgn3,'I-','J-','a-','b-')
            if(ysp0)call mula(aa3,'-ooo',elmat,n,6,jsgn3,'K-')
         endif
         !
      endif
      return
      end
