      subroutine sgn(v,ifil,ndet)
      parameter(maxal=56,maxsym=8,maxorbcas=16)
      include 'maxorb.prm'
      IMPLICIT REAL*8(A-H,O-X,Z),logical*1(y)
c
c    |-*-*-*-*-*-*-*-|-*-*-*-*-*-*-*-|-*-*-*-*-*-*-*-|-*-*-*-*-*-*-*-|
c    | |
c     ysgn
c
      common /cs/ noac,nelac,numac(maxorbcas),itype(maxorb),is0,ms2
      common/dim/ iadri
      COMMON/VER2/nelem
      common/sym/ itsym(maxorb*2),its(maxsym,maxsym),nsym
      common /orb/ enuc,eref,norb,noca,nocb
     *,iorb(2*maxorb),ninac,nvirt,noca0
      dimension ysgn(iadri)
      dimension v(ndet)
c     common/sg/ysgn(iadri)
      common/orb2/numina(maxorb),numvir(maxorb),iordo(maxorb*2)
     *,iodro(maxorb*2)
     *,numinb(maxorb),numvib(maxorb)
      common/infdav/ twcas,alam(maxal),tau,twvec,twess,sint,sh
     *,hab,Nbtots,nvec,ngao,niter,iprec,lvec(maxal),nfrag,ipresc,irest
     *,jrest
     *,iunit,ihprec,ihvec,ifiess,NESSAI,nf8,maxda2,bidia,ywvec,ytana
     *,yhmono,ydens,ywcas
      character*4 hab
      logical*1 bidia
      dimension ntv(maxorbcas+2),npv(maxorbcas+2)
      dimension ibid(maxorb*2)
      dimension jbid(maxorb*2)
c
c-----------------------------------------------------------
c     signe des determinants mode cipsi
c-----------------------------------------------------------
c
      iimpair=mod(iabs(ms2),2)
      yw=.false.
      if(yw)write(6,*)'entree sgn'
      if(yw)write(6,*)'iorb',(iorb(k),k=1,norb+norb+iimpair)
      mdestod=0
      ndestod=0
      mdestod1=0
      ndestod1=0
      rewind ifil
      do idet=1,ndet
c      yw=idet.eq.31
           if(ifil.eq.0)then
              print*,'ifil vale 0!!'
              stop
              end if
         call venond1(ifil,ne,ntv,npv,ierr)
         if(ierr.eq.1) goto 100
         if(yw)write(6,*)'sgn ntv,npv',(ntv(k),k=1,ne),(npv(k),k=1,ne)
         if(yw)write(6,*)'noca0',noca0
c      --on occupe jusqu'a noca0
         do k=1,noca0
            ibid(k)=k
            ibid(k+noca0)=k+norb
         enddo
c      --on place les part dans les trous (mode cipsi)
         nea=0
         do k=1,ne
            if(ntv(k).le.norb)ibid(ntv(k))=npv(k)
            if(ntv(k).le.norb) nea=nea+1
            if(ntv(k).gt.norb)ibid(iorb(ntv(k))+noca0)=npv(k)
         enddo
         neb=ne-nea
         if(yw)write(6,'(''ibid'',20i4)')(ibid(k),k=1,noca0+noca0)
c        if(yw)write(6,'(''ibidb'',20i4)')(ibidb(k),k=1,noca0)
c      --on renumerote en CAS occ virtuelles
         do k=1,noca0+noca0
            jbid(k)=iodro(ibid(k))
         enddo
         if(yw)write(6,'(''jbid'',20i4)')(jbid(k),k=1,noca0+noca0)
c      --on reordonne
         call reor(noca0+noca0,jbid,isgn)
         if(yw)write(6,'(''jbid'',20i4)')(jbid(k),k=1,noca0+noca0)
         if(yw)write(6,*)'isgn',isgn
         v(idet)=v(idet)*isgn
         if(yw)write(6,'('' signe vieux det'',l2,20i3)')
     *   ysgn(ndet),(ntv(k),k=1,ne),(npv(k),k=1,ne)
      enddo
 100  continue
      return
      end
