      subroutine v1v2(b,iadrr,v2,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 b(iadri),iadrr(iadri),v2(iadri)
c
c    |-*-*-*-*-*-*-*-|-*-*-*-*-*-*-*-|-*-*-*-*-*-*-*-|-*-*-*-*-*-*-*-|
c    |       b       |       ab      | iadrr |       |      v2       | |
c                                                                 (ysgn)
c
c      print*,'v1v2 iadrr',(iadrr(k),k=1,mdet)
c      print*,'v1v2 mdet',mdet
      do k=1,mdet
         v2(k)=0.D0
      enddo
c      print*,'v1v2 iadrr',(iadrr(k),k=1,mdet)
      do k=1,mdet
c         print*,'k,iadrr(k)',k,iadrr(k)
c         if(iadrr(k).ne.0)v2(iadrr(k))=b(k)
         if(iadrr(k).gt.0) then
            v2(k)=b(iadrr(k))
         else if(iadrr(k).lt.0) then
            v2(k)=-b(-iadrr(k))
         endif
      enddo
      return
      end
       subroutine v1v2bis(b,iadrr,v2,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 b(iadri),iadrr(2048),v2(iadri)
      common/ipoin76/ip76
c
c    |-*-*-*-*-*-*-*-|-*-*-*-*-*-*-*-|-*-*-*-*-*-*-*-|-*-*-*-*-*-*-*-|
c    |       b       |       ab      | iadrr |       |      v2       | |
c                                                                 (ysgn)
c
c      print*,'v1v2 iadrr',(iadrr(k),k=1,mdet)
c      print*,'v1v2bis mdet',mdet
      do k=1,mdet
         v2(k)=0.D0
      enddo
c      print*,'v1v2 iadrr',(iadrr(k),k=1,mdet)
      kk=2048
      do k=1,mdet
         kk=kk+1
         if(kk.eq.2049) then
            kk=1
            read(76) iadrr
c             ip76=ip76+1
c             print*,'v1v2bis ip76',ip76
         endif
c         print*,'k,iadrr(k)',k,iadrr(kk)
c         if(iadrr(kk).ne.0)v2(iadrr(kk))=b(k)
         if(iadrr(kk).gt.0) then
            v2(k)=b(iadrr(kk))
         else if(iadrr(kk).lt.0) then
            v2(k)=-b(-iadrr(kk))
         endif
      enddo
      return
      end
       subroutine v1v2ter(b,iadrr,v2,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 b(iadri),iadrr(2048),v2(iadri)
      common/ipoin76/ip76
c
c    |-*-*-*-*-*-*-*-|-*-*-*-*-*-*-*-|-*-*-*-*-*-*-*-|-*-*-*-*-*-*-*-|
c    |       b       |       ab      | iadrr |       |      v2       | |
c                                                                 (ysgn)
c
c      print*,'v1v2 iadrr',(iadrr(k),k=1,mdet)
c      print*,'v1v2bis mdet1,mdet2',mdet1,mdet2
      do k=1,mdet1+mdet2
         v2(k)=0.D0
      enddo
c      print*,'v1v2 iadrr',(iadrr(k),k=1,mdet)
      kk=2048
      do k=1,mdet1
         kk=kk+1
         if(kk.eq.2049) then
            kk=1
            read(76) iadrr
c             ip76=ip76+1
c             print*,'v1v2ter ip76',ip76
         endif
c         print*,'k,iadrr(k)',k,iadrr(kk)
c         if(iadrr(kk).ne.0)v2(iadrr(kk))=b(k)
         if(iadrr(kk).gt.0) then
            v2(k)=b(iadrr(kk))
         else if(iadrr(kk).lt.0) then
            v2(k)=-b(-iadrr(kk))
         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*,'v1v2ter ip76',ip76
         endif
c         print*,'k,iadrr(k)',k,iadrr(kk)
c         if(iadrr(kk).ne.0)v2(iadrr(kk))=b(k)
         if(iadrr(kk).gt.0) then
            v2(k)=b(iadrr(kk))
         else if(iadrr(kk).lt.0) then
            v2(k)=-b(-iadrr(kk))
         endif
      enddo
      return
      end
 
       subroutine v1v2car(b,iadrr,v2,mdet,ipass,lim)
      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 b(iadri),iadrr(2048),v2(iadri)
      common/ipoin76/ip76
c
c    |-*-*-*-*-*-*-*-|-*-*-*-*-*-*-*-|-*-*-*-*-*-*-*-|-*-*-*-*-*-*-*-|
c    |       b       |       ab      | iadrr |       |      v2       | |
c                                                                 (ysgn)
c
      if(ipass.eq.1.or.ipass.eq.2) then
      do k=1,lim
         v2(k)=0.D0
      enddo
      kk=2048
      do k=1,lim
         kk=kk+1
         if(kk.eq.2049) then
            kk=1
            read(76) iadrr
         endif
c         print*,'k,kk,iadrr(kk)',k,kk,iadrr(kk)
         if(iadrr(kk).gt.0) then
            v2(k)=b(iadrr(kk))
         else if(iadrr(kk).lt.0) then
            v2(k)=-b(-iadrr(kk))
         endif
      enddo
      do k=lim+1,mdet
         kk=kk+1
         if(kk.eq.2049) then
            kk=1
            read(76)
         endif
      enddo
c      do k=1,lim
c         print*,'12k,v2(k)',k,v2(k)
c      enddo
 
 
      else
 
 
      do k=1,mdet-lim
         v2(k)=0.D0
      enddo
      do k=1,lim/2048
         read(76)
      enddo
      read(76) iadrr
      kk=mod(lim,2048)
      do k=1,mdet-lim
         kk=kk+1
         if(kk.eq.2049) then
            kk=1
            read(76) iadrr
         endif
c         print*,'2k,kk,iadrr(kk)',k,kk,iadrr(kk)
         if(iadrr(kk).gt.0) then
            v2(k)=b(iadrr(kk))
         else if(iadrr(kk).lt.0) then
            v2(k)=-b(-iadrr(kk))
         endif
      enddo
c      do k=1,mdet-lim
c         print*,'34k,v2(k)',k,v2(k)
c      enddo
 
 
      endif
 
      return
      end
