deigvalsh Function

function deigvalsh(A) result(lam)

Arguments

Type IntentOptional Attributes Name
real(kind=8), intent(in) :: A(:,:)

Return Value real(kind=8), (size(A,1))


Calls

proc~~deigvalsh~2~~CallsGraph proc~deigvalsh~2 deigvalsh assert_shape assert_shape proc~deigvalsh~2->assert_shape dsyevd dsyevd proc~deigvalsh~2->dsyevd

Source Code

function deigvalsh(A) result(lam)
  real(8), intent(in)  :: A(:, :)         ! matrix for eigenvalue compuation
  real(8)              :: lam(size(A,1))  ! eigenvalues: A c = lam c
  real(8), allocatable :: At(:,:),work(:),iwork(:)
  real(8)              :: lwork_guess(1),liwork_guess(1)
  integer              :: info,lda,lwork,liwork,n
  lda   = size(A(:,1))
  n     = size(A(1,:))
  call assert_shape(A,[n,n],"solve","A")
  allocate(At(n,n))
  !Copy the input Matrix
  At    = A
  !1st Call: Query the right size for the working array.
  call dsyevd('N','U', n, At, lda, lam, lwork_guess, -1, liwork_guess, -1, info )
  if(info /= 0) then
     print*, "dsyevd returned info = ",info
     stop
  endif
  lwork  = int(lwork_guess(1))  ;allocate(work(lwork))
  liwork = int(liwork_guess(1)) ;allocate(iwork(liwork))
  !2nd Call: Actual solution of the eigenproblem
  call dsyevd('N','U', n, At, lda, lam, work, lwork, iwork, liwork, info )
  if(info /= 0) then
     print *, "ssyevd returned info = ",info
     if (info < 0) then
        print*, "the",-info,"-th argument had an illegal value"
     else
        print*,"the algorithm failed to converge"
        print*,"the",info,"off-diagonal elements of an intermediate"
        print*,"tridiagonal form did not converge to zero"
     end if
     stop 'deigvalsh error: 2nd call dsyevd'
  end if
end function deigvalsh