      SUBROUTINE DGEFS (A,LDA,N,V,ITASK,IND,WORK,IWORK)
C***BEGIN PROLOGUE   DGEFS
C***REVISION   OCTOBER 1, 1980
C***CATEGORY             F4A
C***KEYWORD(S)           DOUBLE PRECISION LINEAR EQUATIONS, LINEAR
C                        EQUATIONS,GENERAL SYSTEM OF LINEAR EQUATIONS
C***AUTHOR               VOORHEES E. (LASL)
C***DATE WRITTEN         MARCH 26,1980
C
C***PURPOSE              DGEFS SOLVES A GENERAL DOUBLE PRECISION
C                        NXN SYSTEM OF LINEAR EQUATIONS.
C
C***DESCRIPTION
C
C    SUBROUTINE DGEFS SOLVES A GENERAL NXN SYSTEM OF DOUBLE
C    PRECISION LINEAR EQUATIONS USING LINPACK SUBROUTINES DGECO
C    AND DGESL.  THAT IS, IF A IS AN NXN DOUBLE PRECISION MATRIX
C    AND IF X AND B ARE DOUBLE PRECISION N-VECTORS, THEN DGEFS
C    SOLVES THE EQUATION
C
C                          A*X=B.
C
C    THE MATRIX A IS FIRST FACTORED INTO UPPER AND LOWER TRI-
C    ANGULAR MATRICES U AND L USING PARTIAL PIVOTING.  THESE
C    FACTORS AND THE PIVOTING INFORMATION ARE USED TO FIND THE
C    SOLUTION VECTOR X.  AN APPROXIMATE CONDITION NUMBER IS
C    CALCULATED TO PROVIDE A ROUGH ESTIMATE OF THE NUMBER OF
C    DIGITS OF ACCURACY IN THE COMPUTED SOLUTION.
C
C    IF THE EQUATION A*X=B IS TO BE SOLVED FOR MORE THAN ONE VECTOR
C    B, THE FACTORING OF A DOES NOT NEED TO BE PERFORMED AGAIN AND
C    THE OPTION TO ONLY SOLVE (ITASK.GT.1) WILL BE FASTER FOR
C    THE SUCCEEDING SOLUTIONS.  IN THIS CASE, THE CONTENTS OF A,
C    LDA, N AND IWORK MUST NOT HAVE BEEN ALTERED BY THE USER FOLLOW-
C    ING FACTORIZATION (ITASK=1).  IND WILL NOT BE CHANGED BY DGEFS
C    IN THIS CASE.
C
C  ARGUMENT DESCRIPTION ***
C
C    A      DOUBLE PRECISION(LDA,N)
C             ON ENTRY, THE DOUBLY SUBSCRIPTED ARRAY WITH DIMENSION
C               (LDA,N) WHICH CONTAINS THE COEFFICIENT MATRIX.
C             ON RETURN, AN UPPER TRIANGULAR MATRIX U AND THE
C               MULTIPLIERS NECESSARY TO CONSTRUCT A MATRIX L
C               SO THAT A=L*U.
C    LDA    INTEGER
C             THE LEADING DIMENSION OF THE ARRAY A.  LDA MUST BE GREAT-
C             ER THAN OR EQUAL TO N.  (TERMINAL ERROR MESSAGE IND=-1)
C    N      INTEGER
C             THE ORDER OF THE MATRIX A.  THE FIRST N ELEMENTS OF
C             THE ARRAY A ARE THE ELEMENTS OF THE FIRST COLUMN OF
C             THE MATRIX A.  N MUST BE GREATER THAN OR EQUAL TO 1.
C             (TERMINAL ERROR MESSAGE IND=-2)
C    V      DOUBLE PRECISION(N)
C             ON ENTRY, THE SINGLY SUBSCRIPTED ARRAY(VECTOR) OF DI-
C               MENSION N WHICH CONTAINS THE RIGHT HAND SIDE B OF A
C               SYSTEM OF SIMULTANEOUS LINEAR EQUATIONS A*X=B.
C             ON RETURN, V CONTAINS THE SOLUTION VECTOR, X .
C    ITASK  INTEGER
C             IF ITASK=1, THE MATRIX A IS FACTORED AND THEN THE
C               LINEAR EQUATION IS SOLVED.
C             IF ITASK.GT.1, THE EQUATION IS SOLVED USING THE EXISTING
C               FACTORED MATRIX A AND IWORK.
C             IF ITASK.LT.1, THEN TERMINAL ERROR MESSAGE IND=-3 IS
C               PRINTED.
C    IND    INTEGER
C             GT.0  IND IS A ROUGH ESTIMATE OF THE NUMBER OF DIGITS
C                     OF ACCURACY IN THE SOLUTION, X.
C             LT.0  SEE ERROR MESSAGE CORRESPONDING TO IND BELOW.
C    WORK   DOUBLE PRECISION(N)
C             A SINGLY SUBSCRIPTED ARRAY OF DIMENSION AT LEAST N.
C    IWORK  INTEGER(N)
C             A SINGLY SUBSCRIPTED ARRAY OF DIMENSION AT LEAST N.
C
C  ERROR MESSAGES PRINTED ***
C
C    IND=-1  TERMINAL   N IS GREATER THAN LDA.
C    IND=-2  TERMINAL   N IS LESS THAN 1.
C    IND=-3  TERMINAL   ITASK IS LESS THAN 1.
C    IND=-4  TERMINAL   THE MATRIX A IS COMPUTATIONALLY SINGULAR.
C                         A SOLUTION HAS NOT BEEN COMPUTED.
C    IND=-10 WARNING    THE SOLUTION HAS NO APPARENT SIGNIFICANCE.
C                         THE SOLUTION MAY BE INACCURATE OR THE MATRIX
C                         A MAY BE POORLY SCALED.
C
C               NOTE-  THE ABOVE TERMINAL(*FATAL*) ERROR MESSAGES ARE
C                      DESIGNED TO BE HANDLED BY XERRWV IN WHICH
C                      LEVEL=1 (RECOVERABLE) AND IFLAG=2 .  LEVEL=0
C                      FOR WARNING ERROR MESSAGES FROM XERROR.  UNLESS
C                      THE USER PROVIDES OTHERWISE, AN ERROR MESSAGE
C                      WILL BE PRINTED FOLLOWED BY AN ABORT.
C
C***REFERENCE(S)
C
C    SUBROUTINE DGEFS WAS DEVELOPED BY GROUP C-3, LOS ALAMOS SCIEN-
C    TIFIC LABORATORY, LOS ALAMOS, NM 87545.
C
C    THE LINPACK SUBROUTINES USED BY DGEFS ARE DESCRIBED IN DETAIL IN
C    THE *LINPACK USERS GUIDE* PUBLISHED BY THE SOCIETY FOR INDUS-
C    TRIAL AND APPLIED MATHEMATICS (SIAM) DATED 1979.
C
C***ROUTINES CALLED D1MACH,DGECO,DGESL,XERROR,XERRWV
C
C***END PROLOGUE
C
      INTEGER LDA,N,ITASK,IND,IWORK(N)
      DOUBLE PRECISION A(LDA,N),V(N),WORK(N),D1MACH
      DOUBLE PRECISION RCOND
C***FIRST EXECUTABLE STATEMENT    DGEFS
      IF (LDA.LT.N)  GO TO 101
      IF (N.LE.0)  GO TO 102
      IF (ITASK.LT.1) GO TO 103
      IF (ITASK.GT.1) GO TO 20
C
C     FACTOR MATRIX A INTO LU
      CALL DGECO(A,LDA,N,IWORK,RCOND,WORK)
C
C     CHECK FOR COMPUTATIONALLY SINGULAR MATRIX
      IF (RCOND.EQ.0.0D0)  GO TO 104
C
C     COMPUTE IND (ESTIMATE OF NO. OF SIGNIFICANT DIGITS)
      IND=-IDINT(DLOG10(D1MACH(4)/RCOND))
C
C     CHECK FOR IND GREATER THAN ZERO
      IF (IND.GT.0)  GO TO 20
      IND=-10
      CALL XERROR(58HDGEFS ERROR (IND=-10) -- SOLUTION MAY HAVE NO SIGNI
     1FICANCE,58,-10,0)
C
C     SOLVE AFTER FACTORING
   20 CALL DGESL(A,LDA,N,IWORK,V,0)
      RETURN
C
C     IF LDA.LT.N, IND=-1, TERMINAL XERRWV MESSAGE
  101 IND=-1
      CALL XERRWV(48HDGEFS ERROR (IND=-1) -- LDA=I1 IS LESS THAN N=I2,
     148,-1,1,2,LDA,N,0,0,0)
      RETURN
C
C     IF N.LT.1, IND=-2, TERMINAL XERRWV MESSAGE
  102 IND=-2
      CALL XERRWV(43HDGEFS ERROR (IND=-2) -- N=I1 IS LESS THAN 1,
     143,-2,1,1,N,0,0,0,0)
      RETURN
C
C     IF ITASK.LT.1, IND=-3, TERMINAL XERRWV MESSAGE
  103 IND=-3
      CALL XERRWV(47HDGEFS ERROR (IND=-3) -- ITASK=I1 IS LESS THAN 1,
     147,-3,1,1,ITASK,0,0,0,0)
      RETURN
C
C     IF SINGULAR MATRIX, IND=-4, TERMINAL XERRWV MESSAGE
  104 IND=-4
      CALL XERRWV(55HDGEFS ERROR (IND=-4) -- SINGULAR MATRIX A - NO SOLU
     1TION,55,-4,1,0,0,0,0,0,0)
      RETURN
C
      END
