SUBROUTINE SGEFA( A, LDA, N, IPVT, INFO ) 1,3 c Factors a real matrix by Gaussian elimination. c Revision date: 8/1/82 c Author: Moler, C. B. (U. of New Mexico) c SGEFA is usually called by SGECO, but it can be called c directly with a saving in time if RCOND is not needed. c (time for SGECO) = (1 + 9/N) * (time for SGEFA) . c Input: same as SGECO c On return: c A,IPVT same as SGECO c INFO INTEGER c = 0 normal value. c = k if u(k,k) .eq. 0.0 . This is not an error c condition for this subroutine, but it does c indicate that SGESL or SGEDI will divide by zero c if called. Use RCOND in SGECO for a reliable c indication of singularity. c --------------------------------------------------------------------- c .. Scalar Arguments .. INTEGER INFO, LDA, N c .. c .. Array Arguments .. INTEGER IPVT( * ) REAL A( LDA, * ) c .. c .. Local Scalars .. INTEGER J, K, KP1, L, NM1 REAL T c .. c .. External Functions .. INTEGER ISAMAX EXTERNAL ISAMAX c .. c .. External Subroutines .. EXTERNAL SAXPY, SSCAL c .. c ** Gaussian elimination with partial pivoting INFO = 0 NM1 = N - 1 DO 20 K = 1, NM1 KP1 = K + 1 c ** find L = pivot index L = ISAMAX( N - K + 1, A( K,K ), 1 ) + K - 1 IPVT( K ) = L IF( A( L,K ).EQ.0.0E0 ) THEN c ** zero pivot implies this column c ** already triangularized INFO = K ELSE c ** interchange if necessary IF( L.NE.K ) THEN T = A( L, K ) A( L, K ) = A( K, K ) A( K, K ) = T END IF c ** compute multipliers T = -1.0E0 / A( K, K ) CALL SSCAL( N - K, T, A( K + 1,K ), 1 ) c ** row elimination with column indexing DO 10 J = KP1, N T = A( L, J ) IF( L.NE.K ) THEN A( L, J ) = A( K, J ) A( K, J ) = T END IF CALL SAXPY( N-K, T, A( K+1, K ), 1, A( K+1, J ), 1 ) 10 CONTINUE END IF 20 CONTINUE IPVT( N ) = N IF( A( N,N ) .EQ. 0.0E0 ) INFO = N END