      SUBROUTINE GNINV(A,AINV,N,NDIM1,IDX) 
*     Inverse of matrix AINV returned, using LR decomposition with   
*     arrays A and IDX from previous call to GNLRD.
      REAL A(NDIM1,N),AINV(NDIM1,N)
      INTEGER IDX(N),I,J,N,NDIM1
      DO J=1,N
       DO I=1,N
        AINV(I,J)=0.0 
       END DO 
       AINV(J,J)=1.0
      END DO
      DO J=1,N
       CALL GNSOL(A,N,NDIM1,IDX,AINV(1,J))
      END DO
      END
