      SUBROUTINE GNSOL(A,N,NDIM1,IDX,B)
*     Solution of matrix equation using LR decomposition, with   
*     arrays A and IDX from previous call to GNLRD.
*     B(N) is array of right-hand side, replaced by result.
      REAL A(NDIM1,N),B(N),SUM
      INTEGER IDX(N),NDIM1,N,I,J,K 
      DO I=1,N
       K=IDX(I)
       SUM=B(K)
       B(K)=B(I)
       DO J=1,I-1
        SUM=SUM-A(I,J)*B(J)
       END DO   
       B(I)=SUM
      END DO 
      DO I=N,1,-1
       SUM=B(I)
       DO J=I+1,N
        SUM=SUM-A(I,J)*B(J)
       END DO   
       B(I)=SUM/A(I,I)
      END DO  
      END
