subroutine utility_rotate_new(mat, rot, N, reverse)
!==============================================================!
! !
! Rotates the N x N matrix 'mat' according to !
! * (rot)^dagger.mat.rot (reverse = .false. or not present) OR !
! * rot.mat.(rot)^dagger (reverse = .true.), !
! where 'rot' is a unitary matrix. !
! The matrix 'mat' is overwritten. !
! !
!==============================================================!
use w90_constants, only: dp
integer, intent(in) :: N
logical, optional, intent(in) :: reverse
complex(kind=dp), intent(inout) :: mat(N, N)
complex(kind=dp), intent(in) :: rot(N, N)
complex(kind=dp) :: tmp(N, N)
logical :: rev
if (.not. present(reverse)) then
rev = .false.
else
rev = reverse
end if
if (rev) then
call utility_zgemm_new(rot, mat, tmp, 'N', 'C')
call utility_zgemm_new(rot, tmp, mat, 'N', 'C')
else
call utility_zgemm_new(mat, rot, tmp, 'C', 'N')
call utility_zgemm_new(tmp, rot, mat, 'C', 'N')
end if
end subroutine utility_rotate_new