!      character(300) prefix,mono1
! 
! 
!  Prefix
! 
! 
!      call system('echo $Project>COST_PROJECT')
!      open(1,status='old',file='COST_PROJECT')
!      read(1,'(a)'),prefix
!      prefix=trim(prefix)//'.'
!      print*,prefix
!      mono1=' '
!      call q52mono(prefix,mono1)
!      end
! 
! 
      subroutine q52mono(if_mono,ante)
      use mod_q5
      use q5cost
! declarations q5
      character(2) ante
      character(300) q5file
      integer(hid_t) file_id
      integer(4) error
      integer(4) howmany,offset
! declarations program
      real(8),allocatable,dimension(:,:) :: overlap
      real(8),allocatable,dimension(:) :: value
      integer(4),allocatable :: isym(:),idx(:,:)

!
! init
!
      if(mono1==' ')mono1=trim(prefix)//'MONO'
      cote=''''
      q5file=trim(workdir)//trim(prefix)//'q5'
!
! init library, open
!
      call q5cost_init(error)
      call q5cost_file_open(q5file,file_id,error)
!
!
! Read symmetry
!
      call Q5Cost_Sys_Symmetry_get_num_sym(file_id,nsym,error)
      allocate(isym(nsym))
      call q5cost_ao_get_num_orb_sym(file_id,isym,error)
      norb=sum(isym(1:nsym))
      allocate(value(norb*(norb+1)/2))
      allocate(overlap(norb,norb))
      allocate(idx(norb*(norb+1)/2,2))
      print*,'isym',isym
      print*,'norb',norb
!
! Read overlap
!
      howmany=norb*(norb+1)/2
      offset=0
      call Q5Cost_AOOverlap_read 
     *( file_id, offset, howmany, idx, value,
     * error )
      overlap=0.d0
      do k=1,howmany
         overlap(idx(k,1),idx(k,2))=value(k)
         overlap(idx(k,2),idx(k,1))=value(k)
      enddo
      print*,'overlap'
      call script(overlap,norb,norb,norb,norb)
      call ecriS(if_mono,overlap,norb,mono1,'Q5',.true.,nsym,isym,
     *(/(k,k=1,norb)/))



      if(ante=='MO') then
            call Q5Cost_MOOneInt_read
     *      (file_id,offset,howmany,idx,value,
     *      error)
         overlap=0.d0
         do k=1,howmany
            overlap(idx(k,1),idx(k,2))=value(k)
            overlap(idx(k,2),idx(k,1))=value(k)
         enddo
         print*,'OneInt'
         call script(overlap,norb,norb,norb,norb)
         call ecriS(-if_mono,overlap,norb,mono1,'Q5',.false.,nsym,isym,
     *   (/(k,k=1,norb)/))
         rewind if_mono
      endif
      call q5cost_file_close(file_id,error)
      call q5cost_deinit(error)
      return
      end
