subroutine sitesym_symmetrize_rotation(sitesym, urot, num_kpts, num_wann, error, comm)
!================================================!
use w90_utility, only: utility_zgemm
use w90_wannier90_types, only: sitesym_type
use w90_error, only: w90_error_type, set_error_fatal
implicit none
! arguments
type(sitesym_type), intent(in) :: sitesym
type(w90_error_type), allocatable, intent(out) :: error
type(w90_comm_type), intent(in) :: comm
integer, intent(in) :: num_wann, num_kpts
complex(kind=dp), intent(inout) :: urot(num_wann, num_wann, num_kpts)
! local variables
integer :: ik, ir, isym, irk
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, sitesym%nkptirr
ik = sitesym%ir2ik(ir)
ldone(ik) = .true.
do isym = 2, sitesym%nsymmetry
irk = sitesym%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', &
sitesym%d_matrix_wann(:, :, isym, ir), 'C', num_wann)
! cmat1 = D(R,k)*cmat2
call utility_zgemm(cmat1, sitesym%d_matrix_wann(:, :, isym, ir), 'N', &
cmat2, 'N', num_wann)
urot(:, :, irk) = cmat1(:, :)
end do
end do
if (any(.not. ldone)) then
call set_error_fatal(error, 'error in sitesym_symmetrize_rotation', comm)
return
end if
return
end subroutine sitesym_symmetrize_rotation