subroutine sitesym_symmetrize_rotation(urot)
!==================================================================!
use w90_parameters, only: num_wann, num_kpts, u_matrix
use w90_utility, only: utility_zgemm
implicit none
integer :: ik, ir, isym, irk
complex(kind=dp), intent(inout) :: urot(num_wann, num_wann, num_kpts)
complex(kind=dp) :: cmat1(num_wann, num_wann)
complex(kind=dp) :: cmat2(num_wann, num_wann)
logical :: ldone(num_kpts)
ldone = .false.
do ir = 1, nkptirr
ik = ir2ik(ir)
ldone(ik) = .true.
do isym = 2, nsymmetry
irk = kptsym(isym, ir)
if (irk .eq. ik) cycle
if (ldone(irk)) cycle
ldone(irk) = .true.
! cmat2 = UROT(k)*D(R,k)^{\dagger}
call utility_zgemm(cmat2, urot(:, :, ik), 'N', &
d_matrix_wann(:, :, isym, ir), 'C', num_wann)
! cmat1 = D(R,k)*cmat2
call utility_zgemm(cmat1, d_matrix_wann(:, :, isym, ir), 'N', &
cmat2, 'N', num_wann)
urot(:, :, irk) = cmat1(:, :)
enddo
enddo
if (any(.not. ldone)) call io_error('error in sitesym_symmetrize_rotation')
return
end subroutine sitesym_symmetrize_rotation