! Returns the inverse of a matrix calculated by finding the LU! decomposition. Depends on LAPACK.function inv(A)result(Ainv)real(dp),dimension(:,:),intent(in)::Areal(dp),dimension(size(A,1),size(A,2))::Ainvreal(dp),dimension(size(A,1))::work! work array for LAPACKinteger,dimension(size(A,1))::ipiv! pivot indicesinteger::n,info! External procedures defined in LAPACKexternalDGETRFexternalDGETRI! Store A in Ainv to prevent it from being overwritten by LAPACKAinv=An=size(A,1)! DGETRF computes an LU factorization of a general M-by-N matrix A! using partial pivoting with row interchanges.callDGETRF(n,n,Ainv,n,ipiv,info)if(info/=0)thenstop'Matrix is numerically singular!'endif! DGETRI computes the inverse of a matrix using the LU factorization! computed by DGETRF.callDGETRI(n,Ainv,n,ipiv,work,n,info)if(info/=0)thenstop'Matrix inversion failed!'endifendfunction inv