subroutine get_gauge_overlap_matrix(num_bands, num_wann, eigval, v_matrix, dis_manifold, ik_a, &
ns_a, ik_b, ns_b, S_o, have_disentangled, S, H)
!================================================
!
! Wannier-gauge overlap matrix S in the projected subspace
!
! TODO: Update this documentation of this routine and
! possibliy give it a better name. The routine has been
! generalized multiple times.
!
!================================================
use w90_types, only: dis_manifold_type
use w90_utility, only: utility_zgemmm
implicit none
! arguments
type(dis_manifold_type), intent(in) :: dis_manifold
real(kind=dp), intent(in) :: eigval(:, :)
complex(kind=dp), intent(in) :: S_o(:, :), v_matrix(:, :, :)
integer, intent(in) :: num_wann, num_bands, ik_a, ns_a, ik_b, ns_b
logical, intent(in) :: have_disentangled
complex(kind=dp), intent(out), optional :: S(:, :), H(:, :)
! local variables
integer :: wm_a, wm_b
call get_win_min(num_bands, dis_manifold, ik_a, wm_a, have_disentangled)
call get_win_min(num_bands, dis_manifold, ik_b, wm_b, have_disentangled)
call utility_zgemmm(v_matrix(1:ns_a, 1:num_wann, ik_a), 'C', &
S_o(wm_a:wm_a + ns_a - 1, wm_b:wm_b + ns_b - 1), 'N', &
v_matrix(1:ns_b, 1:num_wann, ik_b), 'N', &
S, eigval(wm_a:wm_a + ns_a - 1, ik_a), H)
end subroutine get_gauge_overlap_matrix