      subroutine v3v4(ab,v3,iadrr,mdet)
      parameter(maxsym=8)
      include 'maxorb.prm'
      IMPLICIT REAL*8(A-H,O-X,Z),logical*1(y)
      common/dim/iadri ; integer(8) iadri
      common /orb/ enuc,eref,norb,noca,nocb
     *,iorb(2*maxorb),ninac,nvirt,noca0
      dimension ab(iadri),iadrr(iadri),v3(iadri)
c
c    |-*-*-*-*-*-*-*-|-*-*-*-*-*-*-*-|-*-*-*-*-*-*-*-|-*-*-*-*-*-*-*-|
c    |       b       |       ab      |      v3       | iadrr |       | |
c                                                                 (ysgn)
c
      do k=1,mdet
         if(iadrr(k).gt.0) then
            ab(iadrr(k))=ab(iadrr(k))+v3(k)
         else if(iadrr(k).lt.0) then
            ab(-iadrr(k))=ab(-iadrr(k))-v3(k)
         endif
      enddo
      return
      end
       subroutine v3v4bis(ab,v3,iadrr,mdet1,back1)
      parameter(maxsym=8)
      include 'maxorb.prm'
      IMPLICIT REAL*8(A-H,O-X,Z),logical*1(y)
      logical back1
      common/dim/iadri ; integer(8) iadri
      common /orb/ enuc,eref,norb,noca,nocb
     *,iorb(2*maxorb),ninac,nvirt,noca0
      dimension ab(iadri),iadrr(2048),v3(iadri)
      common/ipoin76/ip76
      common /det/ndet,mdet(50),nbdet_cas
c
c    |-*-*-*-*-*-*-*-|-*-*-*-*-*-*-*-|-*-*-*-*-*-*-*-|-*-*-*-*-*-*-*-|
c    |       b       |       ab      |      v3       | iadrr |       | |
c                                                                 (ysgn)
c
c      print*,'v3v4bis mdet1',mdet1
      kk=2048
      if(back1)call back(76,mdet1)
c       do k=1,ndet
c          print*,'ab0',k,ab(k)
c       enddo
      do k=1,mdet1
         kk=kk+1
         if(kk.eq.2049) then
            kk=1
            read(76) iadrr
c             ip76=ip76+1
c             print*,'v3v4bis ip76',ip76
         endif
         if(iadrr(kk).gt.0) then
            ab(iadrr(kk))=ab(iadrr(kk))+v3(k)
         else if(iadrr(kk).lt.0) then
            ab(-iadrr(kk))=ab(-iadrr(kk))-v3(k)
         endif
      enddo
c       print*,'sortie V3V4bis'
c       do k=1,mdet1
c          print*,'v3',k,v3(k)
c       enddo
c       do k=1,ndet
c          print*,'ab',k,ab(k)
c       enddo
      return
      end
       subroutine v3v4ter(ab,v3,iadrr,mdet1,mdet2)
      parameter(maxsym=8)
      include 'maxorb.prm'
      IMPLICIT REAL*8(A-H,O-X,Z),logical*1(y)
      common/dim/iadri ; integer(8) iadri
      common /orb/ enuc,eref,norb,noca,nocb
     *,iorb(2*maxorb),ninac,nvirt,noca0
      dimension ab(iadri),iadrr(2048),v3(iadri)
      common/ipoin76/ip76
c
c    |-*-*-*-*-*-*-*-|-*-*-*-*-*-*-*-|-*-*-*-*-*-*-*-|-*-*-*-*-*-*-*-|
c    |       b       |       ab      |      v3       | iadrr |       | |
c                                                                 (ysgn)
c
c      print*,'v3v4bis mdet1,mdet2',mdet1,mdet2
      kk=2048
      call back(76,mdet1)
      call back(76,mdet2)
      do k=1,mdet1
         kk=kk+1
         if(kk.eq.2049) then
            kk=1
            read(76) iadrr
c             ip76=ip76+1
c             print*,'v3v4bis ip76',ip76
         endif
         if(iadrr(kk).gt.0) then
            ab(iadrr(kk))=ab(iadrr(kk))+v3(k)
         else if(iadrr(kk).lt.0) then
            ab(-iadrr(kk))=ab(-iadrr(kk))-v3(k)
         endif
      enddo
      kk=2048
      do k=mdet1+1,mdet1+mdet2
         kk=kk+1
         if(kk.eq.2049) then
            kk=1
            read(76) iadrr
c             ip76=ip76+1
c             print*,'v3v4bis ip76',ip76
         endif
         if(iadrr(kk).gt.0) then
            ab(iadrr(kk))=ab(iadrr(kk))+v3(k)
         else if(iadrr(kk).lt.0) then
            ab(-iadrr(kk))=ab(-iadrr(kk))-v3(k)
         endif
      enddo
      return
      end
 
       subroutine v3v4car(ab,v3,iadrr,mdet1,back1,ipass,lim)
      parameter(maxsym=8)
      include 'maxorb.prm'
      IMPLICIT REAL*8(A-H,O-X,Z),logical*1(y)
      logical back1
      common/dim/iadri ; integer(8) iadri
      common /orb/ enuc,eref,norb,noca,nocb
     *,iorb(2*maxorb),ninac,nvirt,noca0
      dimension ab(iadri),iadrr(2048),v3(iadri)
      common/ipoin76/ip76
      common /det/ndet,mdet(50),nbdet_cas
c
c    |-*-*-*-*-*-*-*-|-*-*-*-*-*-*-*-|-*-*-*-*-*-*-*-|-*-*-*-*-*-*-*-|
c    |       b       |       ab      |      v3       | iadrr |       | |
c                                                                 (ysgn)
c
c      print*,'entree v3v4car',ipass
c      ktest=1755
      if(ipass.eq.1.or.ipass.eq.3) then
         kk=2048
         if(back1)call back(76,mdet1)
         do k=1,lim
            kk=kk+1
            if(kk.eq.2049) then
               kk=1
c               print*,'1avant lir76'
               read(76) iadrr
            endif
            if(iadrr(kk).gt.0) then
               ab(iadrr(kk))=ab(iadrr(kk))+v3(k)
c               if(iadrr(kk).eq.ktest)
c     *         print*,'1ktest',k,kk,v3(k),iadrr(kk),
c     *         ab(iadrr(kk))
            else if(iadrr(kk).lt.0) then
               ab(-iadrr(kk))=ab(-iadrr(kk))-v3(k)
c               if(-iadrr(kk).eq.ktest)
c     *         print*,'2ktest',k,kk,v3(k),-iadrr(kk),
c     *         ab(-iadrr(kk))
            endif
         enddo
         do k=lim+1,mdet1
            kk=kk+1
            if(kk.eq.2049) then
               kk=1
               read(76)
            endif
         enddo
 
 
      else
 
         if(back1)call back(76,mdet1)
         do k=1,lim/2048
            read(76)
         enddo
         read(76) iadrr
         kk=mod(lim,2048)
         do k=1,mdet1-lim
            kk=kk+1
            if(kk.eq.2049) then
               kk=1
c               print*,'2avant lir76'
               read(76) iadrr
            endif
            if(iadrr(kk).gt.0) then
               ab(iadrr(kk))=ab(iadrr(kk))+v3(k)
c               if(iadrr(kk).eq.ktest)
c     *         print*,'3ktest',k,kk,v3(k),iadrr(kk),
c     *         ab(iadrr(kk))
            else if(iadrr(kk).lt.0) then
               ab(-iadrr(kk))=ab(-iadrr(kk))-v3(k)
c               if(-iadrr(kk).eq.ktest)
c     *         print*,'4ktest',k,kk,v3(k),-iadrr(kk),
c     *         ab(-iadrr(kk))
            endif
         enddo
 
      endif
 
      return
      end
