      program oldorb
!
!-------------------------------------------------------------
! Lit un fichier d'orbitales de molcas, de nom INPORB
! - s'il est ecrit en vieux format, le recopie dans OUTORB
! - s'il est ecrit en nouveau format, le traduit en vieux
!   sortie dans OUTORB
!-------------------------------------------------------------
!
      character(80) a
      logical y
      l=0
      call titre('OLDORB#',60)
      open(1,file='INPORB',status='old')
      !
      read(1,'(a)') a
      rewind 1
      open(2,file='OUTORB',status='unknown')
!      open(3,file='ELIMORB',status='unknown')
      if(a(1:1)/='#') then
         print*,'input orbital fil INPORB is not in new format'
         print*,'INPORB is copied into OUTORB'
         do
            read(1,'(a)',end=10) a
            write(2,'(a)') trim(a)
         enddo
 10      continue
         stop
      endif
      !
      i=0
      y=.false. 
      rewind 1
      do
         i=i+1
         read(1,'(a)',end=2) a
         if(a(1:4)=='#ONE') y=.true.
         if(y.or.a(1:1)=='#'.or.(i>3.and.i<7)) then
            !print*,'elim1 ',trim(a)
!            write(3,'(i6,a)') i,trim(a)
            cycle
         endif
         write(2,'(a)') trim(a)
         l=l+1
         !print*,'kept ',trim(a)
      enddo
 2    continue
      rewind 1
!      i=0
!      do j=1,long
!         i=i+1
!         read(1,'(a)') a
!         if(a(1:1)=='#') then
!            print*,'elim2 ',trim(a)
!            write(3,'(i5,a)') i,trim(a)
!            cycle
!         else
!            exit
!         endif
!      enddo
!      write(2,'(a)') trim(a)
!      l=l+1
!      print*,'kept ',trim(a)
!      do
!         i=i+1
!         read(1,'(a)') a
!         print*,'elim2 ',trim(a)
!         write(3,'(i5,a)') i,trim(a)
!         if(a(1:4)=='#ORB') then
!            exit
!         endif
!      enddo
!      do
!      read(1,'(a)',end=1) a
!         i=i+1
!         if(a(1:1)=='#') then
!            print*,'elim3 ',trim(a)
!            write(3,'(i5,a)') i,trim(a)
!            cycle
!         endif
!         write(2,'(a)') trim(a)
!         l=l+1
!      enddo
 1    continue
      print*,'==========================================='
      print*,'oldorb ',l,' lignes recopiees'
      print*,'==========================================='
      end
