subroutine wann_check_unitarity()
!========================================!
use w90_constants, only: dp, cmplx_1, cmplx_0, eps5
use w90_io, only: io_stopwatch, io_error, stdout
use w90_parameters, only: num_kpts, num_wann, &
u_matrix, timing_level
implicit none
integer :: nkp, i, j, m
complex(kind=dp) :: ctmp1, ctmp2
if (timing_level > 1 .and. on_root) call io_stopwatch('wann: check_unitarity', 1)
do nkp = 1, num_kpts
do i = 1, num_wann
do j = 1, num_wann
ctmp1 = cmplx_0
ctmp2 = cmplx_0
do m = 1, num_wann
ctmp1 = ctmp1 + u_matrix(i, m, nkp)*conjg(u_matrix(j, m, nkp))
ctmp2 = ctmp2 + u_matrix(m, j, nkp)*conjg(u_matrix(m, i, nkp))
enddo
if ((i .eq. j) .and. (abs(ctmp1 - cmplx_1) .gt. eps5)) &
then
if (on_root) write (stdout, *) ' ERROR: unitariety of final U', nkp, i, j, &
ctmp1
call io_error('wann_check_unitarity: error 1')
endif
if ((i .eq. j) .and. (abs(ctmp2 - cmplx_1) .gt. eps5)) &
then
if (on_root) write (stdout, *) ' ERROR: unitariety of final U', nkp, i, j, &
ctmp2
call io_error('wann_check_unitarity: error 2')
endif
if ((i .ne. j) .and. (abs(ctmp1) .gt. eps5)) then
if (on_root) write (stdout, *) ' ERROR: unitariety of final U', nkp, i, j, &
ctmp1
call io_error('wann_check_unitarity: error 3')
endif
if ((i .ne. j) .and. (abs(ctmp2) .gt. eps5)) then
if (on_root) write (stdout, *) ' ERROR: unitariety of final U', nkp, i, j, &
ctmp2
call io_error('wann_check_unitarity: error 4')
endif
enddo
enddo
enddo
if (timing_level > 1 .and. on_root) call io_stopwatch('wann: check_unitarity', 2)
return
end subroutine wann_check_unitarity