      subroutine restart_oao(icas,s,norb,ok,is,workdir)
      parameter (maxsym=8)
      implicit real*8 (a-h,o-z)
      character(*) workdir
      character(10000) a1,a2
      character(80) a
      logical lex,ok
      dimension s(norb,norb)
      common/sym/ nsym,isym(maxsym),isymt(0:maxsym)
      character(8),allocatable :: orbi(:)
      allocate (orbi(norb))
      if(icas==1) then
!
!---------------------------------------
! le fichier RESTART_OAO existe ?
!---------------------------------------
!

! cle de reconnaissance du fichier :
         rewind 93
         call lecnam('&OAO ',a1,93,ierr,0)
         ifin=0
         do
            read(93,'(a80)') a
            l=len_trim(a)
            call fnormaligo(a,l)
            if(a(1:3)=='FIN') exit
            l=len_trim(a)
            ideb=ifin+1
            ifin=ifin+l
            a1(ideb:ifin+3)=trim(a)//' # '
            ifin=ifin+3
         enddo
         !print*, trim(a1)
         ok=.false.
         inquire(FILE=trim(workdir)//'RESTART_OAO',EXIST=lex)
         if(lex) then
! le fichier existe !
            open(99,form='unformatted',status='old',file=
     *      trim(workdir)//'RESTART_OAO')
            read(99,end=1) a2
            if(a1==a2) then
! c'est le bon fichier !
               if(is==1) print*,'I found an old OAO file. Restart'
               ok=.true.
            endif
         endif
         if(ok) then
! ouverture LOCOA
            open(1,file=trim(workdir)//'LOCOA',status='unknown')
! ecriture 1ere ligne de LOCOA
            write(1,'(A20)') '* Orbitales Hiersmud'
            do is=1,nsym
! ecriture des oao de chaque symetrie
               ndims=isym(is)
               ndims0=isymt(is-1)
               read(99,end=1) ndims,nsym_bid
               write(8) ndims,nsym_bid
               if(ndims==0) cycle
               read(99,end=1) ((s(k,l),k=1,ndims),l=1,ndims)
               write(8)((s(k,l),k=1,ndims),l=1,ndims)
               read(99,end=1) orbi(ndims0+1:ndims0+ndims)
               write(8) orbi(ndims0+1:ndims0+ndims)
               read(99,end=1) s(1:ndims,1:ndims)
               do k=1,ndims
                  write(1,'(''* ORBITAL'',2i5)') is,k
                  write(1,1000)(s(l,k),l=1,ndims)
               enddo
            enddo
         else
            open(99,form='unformatted',status='unknown',
     *      file=trim(workdir)//'RESTART_OAO')
            write(99) a1
         endif
      else if(icas==2) then
         write(99) s
      endif
 1000 format(4d18.12)
      deallocate (orbi)
      return
 1    continue
      ok=.false.
      return
      end
