FUNCTION CALCT2(NI, NEL, G1, ALAT, CST)
use constants, only: dp
use SystemData, only: BasisFN, kvec, k_lattice_constant, TUEG2
IMPLICIT NONE
INTEGER NEL, NI(NEL), I, J
TYPE(BasisFN) G1(*)
real(dp) ALAT(4), CST, TMAT, CALCT2
CALCT2 = 0.0_dp
!===============================
if(TUEG2) then
DO J = 1, NEL
I = NI(J)
TMAT = real(kvec(I, 1)**2 + kvec(I, 2)**2 + kvec(I, 3)**2, dp)
TMAT = 0.5_dp * TMAT * k_lattice_constant**2
CALCT2 = CALCT2 + TMAT
end do
return
end if ! TUEG2
!===============================
DO J = 1, NEL
I = NI(J)
TMAT = ((ALAT(1)**2) * ((G1(I)%K(1)**2) / (ALAT(1)**2) + &
(G1(I)%K(2)**2) / (ALAT(2)**2) + &
(G1(I)%K(3)**2) / (ALAT(3)**2)))
TMAT = TMAT * CST
CALCT2 = CALCT2 + TMAT
end do
RETURN
END FUNCTION CALCT2