!character(:) function get_dlf_home() bind(c)
!
!  return "~/home/dl_field/4.2/lib"
!
!endfunction
!character(:) function get_output_dir() bind(c)
!
!  return "_dl_field_output"
!
!endfunction
integer(c_int) function chemsh_get_nqmatoms() bind(c, name='chemsh_get_nqmatoms') result(c_nqmatoms)

    use, intrinsic :: iso_c_binding
    use ChemShellDLFieldModule, only : nqmatoms

    c_nqmatoms = nqmatoms

endfunction chemsh_get_nqmatoms
integer(c_int) function chemsh_get_nexcludes() bind(c, name='chemsh_get_nexcludes') result(c_nexcludes)

    use, intrinsic :: iso_c_binding
    use ChemShellDLFieldModule, only : nexcludes

    c_nexcludes = nexcludes

endfunction chemsh_get_nexcludes
integer(c_int) function chemsh_get_natoms() bind(c, name='chemsh_get_natoms') result(c_natoms)

    use, intrinsic :: iso_c_binding
    use DL_PY2F
    use ChemShellDLFieldModule, only : natoms

!    type(PyType)            :: fragPtr
!    type(dictType), pointer :: PyFrag
!    real(kind=8)            :: intbuff(natoms)
!
!    call PyOptions%get('frag', fragPtr)
!    allocate(PyFrag, source=ptr2dict(fragPtr))
!    call PyFrag%get('natoms', natoms)

    c_natoms = natoms

endfunction chemsh_get_natoms
integer(c_int) function chemsh_get_qmatoms(c_qmatoms) bind(c, name='chemsh_get_qmatoms') result(ierror)

    use, intrinsic :: iso_c_binding
    use ChemShellDLFieldModule, only : PyOptions, nqmatoms

    integer(c_int) :: c_qmatoms(nqmatoms)

    integer        :: intbuff(nqmatoms)

    ierror = 1

    if(nqmatoms.eq.0) then
        return
    endif

    call PyOptions%get('qmatoms', intbuff)

    ! YL: DL_POLY starts from 1 rather than 0
    c_qmatoms(:) = intbuff(:) + 1

    ierror = 0

endfunction chemsh_get_qmatoms
integer(c_int) function chemsh_get_exclude(c_iexclude, c_excludes) bind(c, name='chemsh_get_exclude') result(ierror)

    use, intrinsic :: iso_c_binding
    use ChemShellDLFieldModule, only : PyOptions, nexcludes

    integer(c_int), value :: c_iexclude
    integer(c_int)        :: c_excludes(2)

    integer        :: intbuff(2,nexcludes)

    ierror = 1

    if(nexcludes.eq.0) then
        return
    endif

    call PyOptions%get('exclude', intbuff)

    ! YL: DL_POLY starts from 1 rather than 0
    c_excludes(:) = intbuff(:,c_iexclude+1) + 1

    ierror = 0

endfunction chemsh_get_exclude
integer(c_int) function chemsh_get_charges(c_charges) bind(c, name='chemsh_get_charges') result(ierror)

    use, intrinsic :: iso_c_binding
    use DL_PY2F
    use ChemShellDLFieldModule, only : PyOptions, natoms

    real(c_double)          :: c_charges(natoms)

    type(PyType)  , pointer :: fragPtr
    type(dictType), pointer :: PyFrag
    real(kind=8)            :: dblbuff(natoms)

    integer :: intbuff

    call PyOptions%get('frag', fragPtr)
    allocate(PyFrag, source=ptr2dict(fragPtr))
    call PyFrag%get('charges', dblbuff)
    call PyFrag%get('npts', intbuff)

    c_charges(:) = dblbuff(:)

    deallocate(PyFrag)
    ierror = 0

endfunction chemsh_get_charges
logical(c_bool) function is_chemsh() bind(c, name='is_chemsh') result(ischemsh)

    use, intrinsic :: iso_c_binding

    ischemsh = .true.

endfunction is_chemsh
logical(c_bool) function chemsh_atom_in_qmatoms(iatom) bind(c, name='chemsh_atom_in_qmatoms') result(in_qmatoms)

    use, intrinsic :: iso_c_binding
    use ChemShellDLFieldModule, only : PyOptions, nqmatoms

    integer(c_int), value :: iatom
    integer               :: j, intbuff(nqmatoms)

    in_qmatoms = .false.

    if(nqmatoms.eq.0) then
        return
    endif

    call PyOptions%get('qmatoms', intbuff)

    ! YL: DL_POLY starts from 1 rather than 0
    intbuff(:) = intbuff(:) + 1

    do j = 1, nqmatoms
        if(intbuff(j).eq.iatom) then
            in_qmatoms = .true.
            return
        endif
    enddo

endfunction chemsh_atom_in_qmatoms
