      SUBROUTINE CHSOL(W,N,B)
*     Solution of matrix equation using LR decomposition, with   
*     arrays W from previous call to CHLRD.
*     B(N) is array of right-hand side, replaced by result.
      REAL W(*),B(N)
      DO I=1,N      ! forward solution
       SUM=B(I)
       DO J=1,I-1  
        SUM=SUM-W(J+(I*I-I)/2)*B(J)
       END DO        
       B(I)=SUM/W((I*I+I)/2)
      END DO
      DO I=N,1,-1   ! backward solution
       SUM=B(I)
       DO J=I+1,N
        SUM=SUM-W(I+(J*J-J)/2)*B(J)
       END DO
       B(I)=SUM/W((I*I+I)/2)
      END DO        
      END  
