hinv Subroutine

public subroutine hinv(h, ih, n, ipvt, info)

Matrix inversion routine author: Roger L. Crane, Kenneth E. Hillstrom, Michael Minkoff; Linpack author: P J Knight, CCFE, Culham Science Centre h(ih,ih) : input/output real array : On input, matrix to be inverted On output, the calculated inverse ih : input integer : array size n : input integer : order of H; n <= ih ipvt(n) : output integer array : pivot vector info : output integer : info flag = 1 normal return = 2 H matrix is singular This routine inverts the matrix H by use of linpack software. !

Arguments

Type IntentOptional AttributesName
real(kind=dp), intent(inout), dimension(:,:):: h
integer, intent(in) :: ih
integer, intent(in) :: n
integer, intent(out), dimension(:):: ipvt
integer, intent(out) :: info

Contents

Source Code


Source Code

  subroutine hinv(h,ih,n,ipvt,info)

    !! Matrix inversion routine
    !! author: Roger L. Crane, Kenneth E. Hillstrom, Michael Minkoff; Linpack
    !! author: P J Knight, CCFE, Culham Science Centre
    !! h(ih,ih) : input/output real array : On input, matrix to be inverted
    !! On output, the calculated inverse
    !! ih       : input integer : array size
    !! n        : input integer : order of H; n <= ih
    !! ipvt(n)  : output integer array : pivot vector
    !! info     : output integer : info flag
    !! = 1  normal return
    !! = 2  H matrix is singular
    !! This routine inverts the matrix H by use of linpack software.
    !!     !
    ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    use global_variables, only: verbose
    implicit none

    !  Arguments

    integer, intent(in) :: ih, n
    integer, intent(out) :: info
    integer, dimension(:), intent(out) :: ipvt
    real(dp), dimension(:,:), intent(inout) :: h

    !  Local variables

    real(dp), dimension(2) :: det

    ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

    !  Do LU decomposition of h

    call sgefa(h,ih,n,ipvt,info)

    if (info == 0) then  !  H is non-singular, so we can form its inverse
       call sgedi(h,ih,n,ipvt,det,1)
       info = 1
    else
       info = 2
       if (verbose == 1) then
          call sgedi(h,ih,n,ipvt,det,10)  !  Calculate determinant only
          write(*,*) 'Determinant = det(1) * 10.0**det(2)',det
          write(*,*) 'H matrix is singular in subroutine hinv'
       end if
    end if

  end subroutine hinv