      SUBROUTINE CROUT0(MO,N,M,A,Q,KA,B,KB,D,INDEX,TEMP)
      DIMENSION A(1),Q(1),B(1),INDEX(1),TEMP(1)
      DOUBLE PRECISION DSUM
      IF (N .LT. 2) GO TO 200
      D = 1.0
      MAX = KA*N
      NM1 = N - 1
C
      K = 1
      KCOL = 0
      KK = 1
      DO 72 KLOOP = 1,NM1
C
C     SEARCH FOR THE K-TH PIVOT ELEMENT (K=1,...,N-1)
C
      S = ABS(A(KK))
      LK = KK
      IMIN = KK + 1
      IMAX = KCOL + N
      DO 10 IK = IMIN,IMAX
      C = ABS(A(IK))
      IF (S .GE. C) GO TO 10
      S = C
      LK = IK
   10 CONTINUE
C
      C = A(LK)
      D = C*D
      IF (D .EQ. 0.0) RETURN
      L = LK - KCOL
      IF (MO .EQ. 0) INDEX(K) = L
      IF (K .EQ. L) GO TO 40
      D = -D
C
C            INTERCHANGING ROWS K AND L
C
      KJ = K
      LJ = L
      DO 20 J = 1,N
      T = A(KJ)
      A(KJ) = Q(LJ)
      Q(LJ) = T
      KJ = KJ + KA
   20 LJ = LJ + KA
C
      IF (M .LE. 0) GO TO 40
      KJ = K
      LJ = L
      DO 30 J = 1,M
      T = B(KJ)
      B(KJ) = B(LJ)
      B(LJ) = T
      KJ = KJ + KB
   30 LJ = LJ + KB
C
C        COMPUTE THE K-TH ROW OF U (K=1,...,N-1)
C
   40 IF (K .GT. 1) GO TO 50
      KJ0 = KK + KA
      DO 41 KJ = KJ0,MAX,KA
   41 A(KJ) = A(KJ)/C
      GO TO 60
C
   50 KJ0 = KK + KA
      KKM1 = KK - KA
      DO 52 KJ = KJ0,MAX,KA
      DSUM = -A(KJ)
      LJ = KJ - K
        DO 51 KL = K,KKM1,KA
        LJ = LJ + 1
   51   DSUM = DSUM + DBLE(Q(KL))*DBLE(A(LJ))
   52 A(KJ) = SNGL(-DSUM)/C
C
C        COMPUTE THE K-TH COLUMN OF L (K=2,...,N)
C
   60 K = K + 1
      KCOL = KCOL + KA
      KK = KCOL + K
C
      LMIN = KCOL + 1
      LMAX = KK - 1
      DO 71 I = K,N
      IL = I
      DSUM = 0.D0
        DO 70 LK = LMIN,LMAX
        DSUM = DSUM + DBLE(A(IL))*DBLE(Q(LK))
   70   IL = IL + KA
   71 A(IL) = DBLE(A(IL)) - DSUM
   72 CONTINUE
C
C             CHECK THE N-TH PIVOT ELEMENT
C
      D = A(KK)*D
      IF (D .EQ. 0.0) RETURN
      NN = KK
      I = KA + 1
C
C             SOLVING THE EQUATION LY = B
C
      IF (M .LE. 0) GO TO 120
      MAXB = KB*M
      DO 102 LMIN = 1,MAXB,KB
      KJ = LMIN
      B(KJ) = B(KJ)/A(1)
        DO 101 K = 2,N
        LMAX = KJ
        KJ = KJ + 1
        DSUM = -B(KJ)
        KL = K
          DO 100 LJ = LMIN,LMAX
          DSUM = DSUM + DBLE(A(KL))*DBLE(B(LJ))
  100     KL = KL + KA
  101   B(KJ) = SNGL(-DSUM)/A(KL)
  102 CONTINUE
C
C             SOLVING THE EQUATION UX = Y
C
      DO 112 LMAX = N,MAXB,KB
      KJ = LMAX
      KKP1 = NN - 1
        DO 111 NMK = 1,NM1
        LMIN = KJ
        KJ = KJ - 1
        DSUM = -B(KJ)
        KL = KKP1
          DO 110 LJ = LMIN,LMAX
          DSUM = DSUM + DBLE(A(KL))*DBLE(B(LJ))
  110     KL = KL + KA
        B(KJ) = -DSUM
  111   KKP1 = KKP1 - I
  112 CONTINUE
C
C           REPLACE L WITH THE INVERSE OF L
C
  120 IF (MO .NE. 0) RETURN
      JJ = 1
      DO 132 JP1 = 2,N
      A(JJ) = 1.0/A(JJ)
      KJ = JJ
        DO 131 K = JP1,N
        LMAX = KJ
        KJ = KJ + 1
        DSUM = 0.D0
        KL = KJ
          DO 130 LJ = JJ,LMAX
          DSUM = DSUM + DBLE(A(KL))*DBLE(Q(LJ))
  130     KL = KL + KA
  131   A(KJ) = SNGL(-DSUM)/A(KL)
  132 JJ = JJ + I
      A(NN) = 1.0/A(NN)
C
C       SOLVE UX = Y WHERE Y IS THE INVERSE OF L
C
      KKP1 = NN - 1
      DO 152 NMK = 1,NM1
      K = N - NMK
      KP1 = K + 1
      KL = KKP1
        DO 140 L = KP1,N
        TEMP(L) = A(KL)
        A(KL) = 0.0
  140   KL = KL + KA
C
        DO 151 KJ = K,MAX,KA
        DSUM = -A(KJ)
        LJ = KJ
          DO 150 L = KP1,N
          LJ = LJ + 1
  150     DSUM = DSUM + DBLE(TEMP(L))*DBLE(A(LJ))
  151   A(KJ) = -DSUM
  152 KKP1 = KKP1 - I
C
C                COLUMN INTERCHANGES
C
      JCOL = MAX - KA
      DO 161 NMJ = 1,NM1
      J = N - NMJ
      JCOL = JCOL - KA
      K = INDEX(J)
      IF (J .EQ. K) GO TO 161
      IJ = JCOL
      IK = (K-1)*KA
        DO 160 I = 1,N
        IJ = IJ + 1
        IK = IK + 1
        T = A(IJ)
        A(IJ) = Q(IK)
  160   Q(IK) = T
  161 CONTINUE
      RETURN
C
C                  CASE WHEN N = 1
C
  200 D = A(1)
      IF (D .EQ. 0.0) RETURN
      IF (MO .EQ. 0) A(1) = 1.0/D
C
      IF (M .LE. 0) RETURN
      MAXB = KB*M
      DO 210 KJ = 1,MAXB,KB
  210 B(KJ) = B(KJ)/D
      RETURN
      END
