# internal_set_kmesh Subroutine

## private subroutine internal_set_kmesh(spacing, reclat, mesh)

This routines returns the three integers that define the interpolation k-mesh, satisfying the condition that the spacing between two neighboring points along each of the three k_x, k_y and k_z directions is at smaller than a given spacing.

The reclat is defined as: * 'b_1' = (recip_lattice(1,I), i=1,3) * 'b_2' = (recip_lattice(2,I), i=1,3) * 'b_3' = (recip_lattice(3,I), i=1,3)

spacing must be > 0 (and in particular different from zero). We don't check this here.

### Arguments

Type IntentOptional AttributesName
real(kind=dp), intent(in) :: spacing

Minimum spacing between neighboring points, in angstrom^(-1)

real(kind=dp), intent(in), dimension(3, 3):: reclat

Matrix of the reciprocal lattice vectors in cartesian coordinates, in angstrom^(-1)

integer, intent(out), dimension(3):: mesh

Will contain the three integers defining the interpolation k-mesh

## Source Code

  subroutine internal_set_kmesh(spacing, reclat, mesh)
!! This routines returns the three integers that define the interpolation k-mesh, satisfying
!! the condition that the spacing between two neighboring points along each of the three
!! k_x, k_y and k_z directions is at smaller than a given spacing.
!!
!! The reclat is defined as:
!!   * 'b_1' = (recip_lattice(1,I), i=1,3)
!!   * 'b_2' = (recip_lattice(2,I), i=1,3)
!!   * 'b_3' = (recip_lattice(3,I), i=1,3)
!!
!!  spacing must be > 0 (and in particular different from zero). We don't check this here.
!!
implicit none
real(kind=dp), intent(in) :: spacing
!! Minimum spacing between neighboring points, in angstrom^(-1)
real(kind=dp), dimension(3, 3), intent(in) :: reclat
!! Matrix of the reciprocal lattice vectors in cartesian coordinates, in angstrom^(-1)
integer, dimension(3), intent(out) :: mesh
!! Will contain the three integers defining the interpolation k-mesh

real(kind=dp), dimension(3) :: blen
integer :: i

do i = 1, 3
blen(i) = sqrt(sum(reclat(i, :)**2))
end do

do i = 1, 3
mesh(i) = int(floor(blen(i)/spacing)) + 1
end do

end subroutine internal_set_kmesh