      subroutine venond(ne,ntv,npv,ierr,itest25)
      implicit real*8(a-h,o-x,z),logical*1(y)
      parameter(maxorbcas=16)
      dimension ntv(maxorbcas+2),npv(maxorbcas+2)
      if(itest25.eq.1) then
         call venond2(ne,ntv,npv,ierr)
         return
      endif
      ierr=0
      read(61,end=1) ne
      if(ne.ne.0) read(61)(ntv(k),k=1,ne),(npv(k),k=1,ne)
      return
 1    ierr=1
      return
      end
       subroutine venond2(ne,ntv,npv,ierr)
      IMPLICIT REAL*8(A-H,O-X,Z),logical*1(y)
      parameter(maxorbcas=16,lungo=100,maxne=maxorbcas+2)
      include 'maxorb.prm'
      character*1 ctps,cex,c256
      common/detsto/mdestod,ndestod,mdestod1,ndestod1,npie2,mpie2,
     *mpie256,mdestod256,mdestod2561,
     *ctps((maxne)*lungo*2),cex(lungo),c256((maxne/4+1)*lungo)
      common /orb/ enuc,eref,norb,noca,nocb
     *,iorb(2*maxorb),ninac,nvirt,noca0
      common /cs/ noac,nelac,numac(maxorbcas),itype(maxorb),is0,ms2
      dimension ntv(maxorbcas+2),npv(maxorbcas+2)
      dimension np1024(4)
      yw=.false.
      ierr=0
      ndestod1=ndestod1+1
      if(ndestod1.gt.ndestod) then
         read(61,end=1) mdestod,ndestod,(ctps(i),i=1,mdestod),
     *   (cex(i),i=1,ndestod)
     *   ,mdestod256,(c256(i),i=1,mdestod256)
         if(yw)print*,'venond2 lect ndestod,mdestod',ndestod,mdestod
c        print*,'venond2 ctps', (ichar(ctps(i)),i=1,mdestod)
c         print*,'c256',(ichar(c256(k)),k=1,mdestod256)
         ndestod1=1
         mdestod1=0
         mdestod2561=0
         if(yw)print*,'venond2 ndestod',ndestod
      endif
      if(yw)print*,'venond2 ndestod1',ndestod1
      nems=ichar(cex(ndestod1))
      call venond4(nems,ne,mst)
      if(yw)print*,'nems',nems
      msp=mst-(-ms2+1)/2
      if(yw)print*,'nems,ne,mst,msp',nems,ne,mst,msp
      if(yw)print*,'char',(ichar(ctps(k)),k=1,ne+ne)
      if(ne.eq.0) return
      do k=1,mst-1
         mdestod1=mdestod1+1
         it=ichar(ctps(mdestod1))
         if(yw)print*,'it',it
         if(it.le.0) it=it+256
         ntv(k)=it
      enddo
      do k=mst,ne
         mdestod1=mdestod1+1
         it=ichar(ctps(mdestod1))+norb
         if(yw)print*,'it',it,norb
         if(it.le.norb) it=it+256
         ntv(k)=it
      enddo
      do k=1,msp-1
         mdestod1=mdestod1+1
         it=ichar(ctps(mdestod1))
         if(it.le.0) it=it+256
         if(yw)print*,'pit',it
         npv(k)=it
      enddo
      do k=msp,ne
         mdestod1=mdestod1+1
         it=ichar(ctps(mdestod1))+norb
         if(it.le.norb) it=it+256
         if(yw)print*,'4it',it
         npv(k)=it
      enddo
      if(norb.gt.256) then
         do k=1,ne,4
            mdestod2561=mdestod2561+1
            iii=ichar(c256(mdestod2561))
            np1024(4)=iii/64
            np1024(3)=(iii-np1024(4)*64)/16
            np1024(1)=mod(iii,4)
            np1024(2)=mod((iii-np1024(1))/4,4)
            kkk=0
            do kk=k,min(k+3,ne)
               kkk=kkk+1
               npv(kk)=npv(kk)+np1024(kkk)*256
            enddo
         enddo
      endif
      if(yw)print*,'venond2 itv,ipv',(ntv(k),k=1,ne),(npv(k),k=1,ne)
      return
 1    ierr=1
      if(yw)print*,'venond2 lect fin fich',ndestod,ndestod1
      return
      end
       subroutine venond4(nems,ne,mst)
      logical yw
      yw=.false.
c--------------------------------------------------
c     on a la formule nems=ne*(ne+1)/2+mst
c     on doit trouver ne et mst a partir de nems
c     on peut demontrer que :
c--------------------------------------------------
      ne=(  int(dsqrt(8.d0*nems))   -1)/2
      if(yw)print*,'ne',ne
c     alors...
      mst=nems-ne*(ne+1)/2
      if(yw)print*,'nems,ne,mst',nems,ne,mst
      return
      end
       subroutine rew61
      implicit real*8(a-h,o-x,z),logical*1(y)
      parameter(lungo=100,maxorbcas=16,maxne=maxorbcas+2)
      character*1 ctps,cex,c256
      common/test/itest(100)
      common/detsto/mdestod,ndestod,mdestod1,ndestod1,npie2,mpie2,
     *mpie256,mdestod256,mdestod2561,
     *ctps((maxne)*lungo*2),cex(lungo),c256((maxne/4+1)*lungo)
      yw=.false.
      mdestod=0
      ndestod=0
      mdestod1=0
      ndestod1=0
      mdestod2561=0
      mdestod256=0
      if(yw)print*,'rew61'
      rewind 61
      return
      end
