      SUBROUTINE BSLV(M0,A,KA,N,ML,MU,B,IWK,IERR)
C ----------------------------------------------------------------------
C     BSLV EMPLOYS GAUSS ELIMINATION WITH ROW INTERCHANGES TO SOLVE
C     THE NXN BANDED LINEAR SYSTEM AX = B. THE ARGUMENT M0 SPECIFIES
C     IF BSLV IS BEING CALLED FOR THE FIRST TIME, OR IF IT IS BEING
C     RECALLED WHERE A IS THE SAME MATRIX BUT B HAS BEEN MODIFIED.
C     ON AN INITIAL CALL TO THE ROUTINE (WHEN M0=0) AN LU DECOMPO-
C     SITION OF A IS OBTAINED AND THEN THE EQUATIONS ARE SOLVED.
C     ON SUBSEQUENT CALLS (WHEN M0.NE.0) THE EQUATIONS ARE SOLVED
C     USING THE DECOMPOSITION OBTAINED ON THE INITIAL CALL TO BSLV.
C
C
C     INPUT ARGUMENTS WHEN M0=0 ---
C
C     A,KA      2-DIMENSIONAL ARRAY OF DIMENSION (KA,M) WHERE
C               KA.GE.N AND M.GE.2*ML+MU+1. THE FIRST ML+MU+1
C               COLUMNS CONTAIN THE MATRIX A IN BANDED FORM.
C
C     N         NUMBER OF EQUATIONS AND UNKNOWNS.
C
C     ML        NUMBER OF DIAGONALS BELOW THE MAIN DIAGONAL.
C
C     MU        NUMBER OF DIAGONALS ABOVE THE MAIN DIAGONAL.
C
C     B         ARRAY OF N ENTRIES CONTAINING THE RIGHT HAND
C               SIDE DATA.
C
C
C     OUTPUT ARGUMENTS WHEN M0=0 ---
C
C     A         AN UPPER TIANGULAR MATRIX IN BAND STORAGE AND
C               THE MULTIPLIERS WHICH WERE USED TO OBTAIN IT.
C
C     B         THE SOLUTION OF THE EQUATIONS.
C
C     IWK       ARRAY OF LENGTH N CONTAINING THE PIVOT INDICES.
C
C     IERR      INTEGER SPECIFYING THE STATUS OF THE RESULTS.
C               IERR=0 IF THE SOLUTION OF AX = B IS OBTAINED.
C               OTHERWISE IERR.NE.0.
C
C
C     AFTER AN INITIAL CALL TO BSLV, THE ROUTINE MAY BE RECALLED
C     WITH M0.NE.0 FOR A NEW B. WHEN M0.NE.0 IT IS ASSUMED THAT
C     A,KA,N,ML,MU,IWK HAVE NOT BEEN MODIFIED. BSLV RETRIEVES THE
C     LU DECOMPOSITION WHICH WAS OBTAINED ON THE INITIAL CALL TO
C     BSLV AND SOLVES THE NEW EQUATIONS AX = B. IN THIS CASE IERR
C     IS NOT REFERENCED.
C ----------------------------------------------------------------------
      REAL A(KA,1),B(N)
      INTEGER IWK(N)
      IF (M0 .NE. 0) GO TO 10
C
C     ERROR CHECKING
C
      IF (N.LE.0 .OR. N.GT.KA) GO TO 100
      IF (ML.LT.0 .OR. ML.GE.N) GO TO 110
      IF (MU.LT.0 .OR. MU.GE.N) GO TO 120
C
C     OBTAIN AN LU DECOMPOSITION OF A
C
      CALL SNBFA(A,KA,N,ML,MU,IWK,IERR)
      IF (IERR .NE. 0) RETURN
C
C     SOLVE THE SYSTEM OF EQUATIONS
C
   10 CALL SNBSL(A,KA,N,ML,MU,IWK,B,0)
      RETURN
C
C     ERROR RETURN
C
  100 IERR = -1
      RETURN
  110 IERR = -2
      RETURN
  120 IERR = -3
      RETURN
      END
