      subroutine sgn0(ysgn)
      parameter(maxal=56,maxsym=8,maxorb=500,maxorbcas=16)
      IMPLICIT REAL*8(A-H,O-X,Z),logical*1(y)
c
c    |-*-*-*-*-*-*-*-|-*-*-*-*-*-*-*-|-*-*-*-*-*-*-*-|-*-*-*-*-*-*-*-|
c    | |
c     ysgn
c
      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)
c     common/sg/ysgn(iadri)
      common/orb2/numina(maxorb),numvir(maxorb),iordo(maxorb*2)
     *,iodro(maxorb*2)
     *,numinb(maxorb),numvib(maxorb)
      common /det/ndet,mdet(50)
      common/infdav/ alam(maxal),tau,twvec,twess,sint,sh
     *,hab,Nbtots,nvec,ngao,niter,iprec,lvec(maxal),ipresc,irest
     *,iunit,ihprec,ihvec,ifiess,NESSAI,nf8,BIDIA,maxda2,ywvec,ytana
     *,yhmono,ydens,ywcas
      character*4 hab
      LOGICAL 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
      open(85,status='unknown',file='YSGN',form='UNFORMATTED')
      if(irest.eq.1.or.irest.eq.3) return
      yw=.false.
c     open(85,status='UNKNOWN',file='SGN0',form='UNFORMATTED')
      if(yw)write(6,*)'entree sgn0'
      if(yw)write(6,*)'iordo',(iordo(k),k=1,norb+norb)
      if(yw)write(6,*)'iorb',(iorb(k),k=1,norb+norb)
      ndet=0
      call rew61
 1    continue
c      read(61,end=100)ne
      call venond(ne,ntv,npv,ierr)
      if(ierr.eq.1) goto 100
      ndet=ndet+1
c     if(mod(ndet,1000).eq.0)write(6,*)'sgn0 ndet,ne',ndet,ne
c      if(ne.ne.0) read(61)(ntv(k),k=1,ne),(npv(k),k=1,ne)
      if(yw)write(6,*)'sgn0 ntv,npv',(ntv(k),k=1,ne),(npv(k),k=1,ne)
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'',40i3)')(ibid(k),k=1,noca0+noca0)
c     if(yw)write(6,'(''ibidb'',40i3)')(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'',40i3)')(jbid(k),k=1,noca0+noca0)
c   --on reordonne
      call reor(noca0+noca0,jbid,isgn)
      if(yw)write(6,'(''jbid'',40i3)')(jbid(k),k=1,noca0+noca0)
      if(yw)write(6,*)'isgn',isgn
      ysgn(ndet)=isgn.eq.1
      if(yw)write(6,'('' signe vieux det'',l2,20i3)')
     *ysgn(ndet),(ntv(k),k=1,ne),(npv(k),k=1,ne)
      goto 1
 100  continue
      call ecry(ysgn,ndet,85)
      if(yw) then
         do k=1,ndet
            print*,'sgn0 k,ysgn(k)',k,ysgn(k)
         enddo
      endif
c test suppression ysgn
      do k=1,ndet
         ysgn(k)=.false.
      enddo
c fin test
      write(6,*)'fin sgn0 ndet',ndet
      return
      end
