subroutine plot_calc_projection(num_bands, num_wann, num_kpts, u_matrix_opt, eigval, lwindow, &
timing_level, iprint, stdout, timer)
!================================================!
!
! Calculates and writes the projection of each Wannier function
! on the original bands within the outer window.
!
!================================================!
use w90_comms, only: w90_comm_type
use w90_constants, only: dp
use w90_error, only: w90_error_type
use w90_io, only: io_stopwatch_start, io_stopwatch_stop
use w90_types, only: timer_list_type
implicit none
! arguments
type(timer_list_type), intent(inout) :: timer
integer, intent(in) :: num_bands
integer, intent(in) :: num_kpts
integer, intent(in) :: num_wann
integer, intent(in) :: stdout
integer, intent(in) :: timing_level, iprint
logical, intent(in) :: lwindow(:, :)
complex(kind=dp), intent(in) :: u_matrix_opt(:, :, :)
real(kind=dp), intent(in) :: eigval(:, :)
! local variables
integer :: nw, nb, nkp, counter
real(kind=dp) :: summ
if (timing_level > 1 .and. iprint > 0) call io_stopwatch_start('wann: calc_projection', timer)
if (iprint > 0) then
write (stdout, '(/1x,a78)') repeat('-', 78)
write (stdout, '(1x,9x,a)') &
'Projection of Bands in Outer Window on all Wannier Functions'
write (stdout, '(1x,8x,62a)') repeat('-', 62)
write (stdout, '(1x,16x,a)') ' Kpt Band Eigval |Projection|^2'
write (stdout, '(1x,16x,a47)') repeat('-', 47)
end if
do nkp = 1, num_kpts
counter = 0
do nb = 1, num_bands
if (lwindow(nb, nkp)) then
counter = counter + 1
summ = 0.0_dp
do nw = 1, num_wann
summ = summ + abs(u_matrix_opt(counter, nw, nkp))**2
end do
if (iprint > 0) write (stdout, '(1x,16x,i5,1x,i5,1x,f14.6,2x,f14.8)') &
nkp, nb, eigval(nb, nkp), summ
end if
end do
end do
if (iprint > 0) write (stdout, '(1x,a78/)') repeat('-', 78)
if (timing_level > 1 .and. iprint > 0) call io_stopwatch_stop('wann: calc_projection', timer)
return
end subroutine plot_calc_projection