# diagonalise_tridiagonal Subroutine

## public subroutine diagonalise_tridiagonal(this, N, t_calc_eigenvectors)

### Arguments

Type IntentOptional Attributes Name
type(LanczosCalcType), intent(inout) :: this
integer, intent(in) :: N
logical, intent(in) :: t_calc_eigenvectors

## Source Code

    subroutine diagonalise_tridiagonal(this, N, t_calc_eigenvectors)
type(LanczosCalcType), intent(inout) :: this
integer, intent(in) :: N
logical, intent(in) :: t_calc_eigenvectors
integer :: lwork, info
real(dp), allocatable :: rwork(:)
character :: jobz

lwork = max(1, 3 * N + 1)
safe_malloc(rwork, (lwork))
if (t_calc_eigenvectors) then
jobz = 'V'
else
jobz = 'N'
end if

if (.not. t_calc_eigenvectors) then
this%ritz_values_old(1:this%n_states) = this%ritz_values(1:this%n_states)
this%super%projected_hamil_work(1:N, 1:N) = this%super%projected_hamil(1:N, 1:N)
end if

call dsyev( &
jobz, &
'U', &
N, &
this%super%projected_hamil_work(1:N, 1:N), &
N, &
this%ritz_values(1:N), &
rwork, &
lwork, &
info &
)
safe_free(rwork)

if (t_calc_eigenvectors) then
! move the eigenvectors out of the working array
#ifdef CMPLX_
this%T_eigenvectors(1:N, 1:this%n_states) = &
cmplx(this%super%projected_hamil_work(1:N, 1:this%n_states), kind=dp)
#else
this%T_eigenvectors(1:N, 1:this%n_states) = &
this%super%projected_hamil_work(1:N, 1:this%n_states)
#endif
end if
end subroutine diagonalise_tridiagonal