C**********************************************************                  MATINV.2     
C             SUBROUTINE MATINV                                              MATINV.3     
C**********************************************************                  MATINV.4     
      SUBROUTINE MATINV(A,N,LDA,IWORK,WORK)                                  MATINV.5     
C                                                                            MATINV.6     
C     This subroutine calculates the inverse of NxN array A.                 MATINV.7     
C                                                                            MATINV.8     
C     Arguements:                                                            MATINV.9     
C                                                                            MATINV.10    
C       A     - Array of dimension (LDA,N). Contains inverse                 MATINV.11    
C               of A on exit.                                                MATINV.12    
C       N     - Number of rows and columns of A.                             MATINV.13    
C       LDA   - Leading dimension of A.                                      MATINV.14    
C       IWORK - Integer array contains the pivot indices of A.               MATINV.15    
C       WORK  - Real array used as workspace for SGETRI.                     MATINV.16    
C                                                                            MATINV.17    
C     This subroutine replaces the Cray specific subroutine                  MATINV.18    
C     MINV with portable LAPACK subroutines SGETRF and SGETRI.               MATINV.19    
C                                                                            MATINV.20    
      INTEGER N,LDA,IWORK(N),INFO                                            MATINV.21    
      REAL A(LDA,N),WORK(N)                                                  MATINV.22    
C                                                                            MATINV.23    
      CALL SGETRF(N,N,A,LDA,IWORK,INFO)                                      MATINV.24    
      IF (INFO.NE.0) THEN                                                    MATINV.25    
         WRITE(*,*) 'Error: SGETRF returned INFO = ',INFO                    MATINV.26    
         CALL ABORT                                                          MATINV.27    
      ENDIF                                                                  MATINV.28    
      CALL SGETRI(N,A,LDA,IWORK,WORK,N,INFO)                                 MATINV.29    
      IF (INFO.NE.0) THEN                                                    MATINV.30    
         WRITE(*,*) 'Error: SGETRI returned INFO = ',INFO                    MATINV.31    
         CALL ABORT                                                          MATINV.32    
      ENDIF                                                                  MATINV.33    
C                                                                            MATINV.34    
      END                                                                    MATINV.35    
