d_inv Subroutine

public subroutine d_inv(mat, matinv)

Arguments

Type IntentOptional Attributes Name
real(kind=dp), intent(in) :: mat(:,:)
real(kind=dp), intent(out), dimension(size(mat, 1), size(mat, 2)) :: matinv

Contents

Source Code


Source Code

    SUBROUTINE d_inv(mat, matinv)
        implicit none
        real(dp), INTENT(IN) :: mat(:, :)
        real(dp), dimension(size(mat, 1), size(mat, 2)), intent(out) :: matinv
        real(dp), dimension(size(mat, 1), size(mat, 2)) :: matdum
        integer, dimension(size(mat, 1)) :: ipiv
        integer :: nsize, msize, i, info

        msize = size(mat, 1)
        nsize = size(mat, 2)
        matdum = mat
        matinv = 0.0_dp
        do i = 1, msize
            matinv(i, i) = 1.0_dp
        end do
        info = 0
        call dGETRF(msize, nsize, matdum, nsize, ipiv, info)
!        IF (INFO /= 0) STOP 'Error with d_inv 1'
        if (info /= 0) then
            write(stdout, *) 'Warning from d_inv 1', info
            call stop_all("d_inv", "Warning from d_inv 1")
        end if
        call dGETRS('n', msize, nsize, matdum, nsize, IPIV, matinv, msize, info)
        if (info /= 0) call stop_all("d_inv", 'Error with d_inv 2')

    END SUBROUTINE d_inv