      subroutine qcio2orb(if_orb)
      use mod_qcio
      use mod_script
      use mod_lirorb
      character(300) qciofile
      integer(4) error
      real(8),dimension(:,:),allocatable :: orbitals,orb2
      real(8),dimension(:),allocatable :: occupations,occ2
      integer(4),dimension(:),allocatable :: itsym
      integer,allocatable :: isym(:),isyms(:)
      scforb='QcioORB'
!
! init library, open
!
      qciofile=trim(workdir)//trim(prefix)//'qcio'
      
!
! Allocate
!
      allocate(orbitals(norb,norb))
      allocate(occupations(norb))
!
! Read symmetry
!
      call qcio_get_symmetry_num_sym(nsym)
      print*,'nsym',nsym
      allocate(isym(nsym))
      allocate(isyms(nsym))
      call qcio_get_ao_num_orb_sym(isym)
      print*,'isym',isym
      norb=sum(isym(1:nsym))
      do is=1,nsym
         isyms(is)=sum(isym(1:is-1))
      enddo
!!!!!!!!!!!!warning!!!!!!!! The symmetry AO's are supposed to be
!    ordered by symmetry!!!!!!!!!!!!!!
!
!     read MO symmetry
      allocate(itsym(norb))
      call Qcio_get_MO_symmetry (itsym)
!
! Read
!
      call Qcio_get_MO_matrix(orbitals)
      call Qcio_get_MO_occupation(occupations)
!
! Write
!
      open(12,form='unformatted',status='unknown',file='tmp_orb')
      open(13,form='unformatted',status='unknown',file='tmp_occ')
      print*,'Orbitals'
      call mscript(orbitals)
      do isy=1,nsym
         print*,'isym',isym
         allocate(orb2(isym(isy),isym(isy)))
         allocate(occ2(isym(isy)))
         kk=0
         do io=1,norb
            if(itsym(io)/=isy) cycle
            kk=kk+1
            orb2(:,kk)
     *      =orbitals(isyms(isy)+1:isyms(isy)+isym(isy),io)
            occ2(kk)=occupations(io)
         enddo
         write(12) orb2
         print*,'occupations',occ2
         call mscript(orb2)
         write(13) occ2
         deallocate(orb2,occ2)
      enddo
      rewind 12
      rewind 13
      print*,'avant ecriorb'
      !open(if_orb,file=trim(prefix)//'scforb',status='unknown')
      print*,'isym',isym(1:nsym)
      call ecriorb('Dolo-Q5 Orbitals',scforb1,nsym,isym,12,if_orb,
     *ifiloc=13,nolabels=.true.)
      close(12,status='delete')
      close(13,status='delete')
      deallocate(occupations,orbitals)
      close(if_orb)
      return
      end

    
