subroutine get_gauge_overlap_matrix(ik_a, ns_a, ik_b, ns_b, S_o, 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_constants, only: dp, cmplx_0
use w90_postw90_common, only: v_matrix
use w90_parameters, only: num_wann, eigval
use w90_utility, only: utility_zgemmm
integer, intent(in) :: ik_a, ns_a, ik_b, ns_b
complex(kind=dp), dimension(:, :), intent(in) :: S_o
complex(kind=dp), dimension(:, :), intent(out), optional :: S, H
integer :: wm_a, wm_b
call get_win_min(ik_a, wm_a)
call get_win_min(ik_b, wm_b)
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