      SUBROUTINE KROUT(MO,N,M,A,KA,B,KB,IERR,INDEX,TEMP)
C     ******************************************************************
C     CROUT PROCEDURE FOR INVERTING MATRICES AND SOLVING EQUATIONS
C     ******************************************************************
C     A IS A MATRIX OF ORDER N WHERE N IS GREATER THAN OR EQUAL TO 1.
C     IF MO=0 THEN THE INVERSE OF A IS COMPUTED AND STORED IN A. IF MO
C     IS NOT 0 THEN THE INVERSE IS NOT COMPUTED.
C
C     IF M IS GREATER THAN 0 THEN B IS A MATRIX HAVING N ROWS AND M
C     COLUMNS. IN THIS CASE AX=B IS SOLVED AND THE SOLUTION X IS STORED
C     IN B. IF M=0 THEN THERE ARE NO EQUATIONS TO BE SOLVED.
C
C     KA = THE LENGTH OF THE COLUMNS OF THE ARRAY A
C     KB = THE LENGTH OF THE COLUMNS OF THE ARRAY B
C
C     IERR IS A VARIABLE THAT REPORTS THE STATUS OF THE RESULTS. WHEN
C     THE ROUTINE TERMINATES IERR HAS ONE OF THE FOLLOWING VALUES ...
C        IERR =  0   THE REQUESTED TASK WAS PERFORMED.
C        IERR = -1   EITHER N, KA, OR KB IS INCORRECT.
C        IERR =  K   THE K-TH PIVOT ELEMENT IS 0.
C
C     INDEX IS AN ARRAY OF DIMENSION N-1 OR LARGER THAT IS USED BY THE
C     ROUTINE FOR KEEPING TRACK OF THE ROW INTERCHANGES THAT ARE MADE.
C     IF MO IS NOT 0 THEN THIS ARRAY IS NOT NEEDED.
C
C     TEMP IS AN ARRAY OF DIMENSION N OR LARGER THAT IS USED WHEN A
C     IS INVERTED. IF MO IS NOT 0 THEN THIS ARRAY IS NOT NEEDED.
C     -------------------
      DIMENSION A(1),B(1),INDEX(1),TEMP(1)
C
C     *****  THE MATRIX A IS REFERENCED IN KROUT0 BY A AND Q.
C            THIS IS DONE FOR EFFICIENCY.
C
      IF (N .LT. 1 .OR. KA .LT. N) GO TO 20
      IF (M .LE. 0) GO TO 10
      IF (KB .LT. N) GO TO 20
   10 CALL KROUT0(MO,N,M,A,A,KA,B,KB,IERR,INDEX,TEMP)
      RETURN
C
C                      INPUT ERROR
C
   20 IERR = -1
      RETURN
      END
