CFPRIME MINVRS                                                          MINVRS      1
C***********************************************************************RIGHTE      1
C*                                                                     *RIGHTE      2
C*        Extended Transient-Midterm Stability Program (ETMSP)         *RIGHTE      3
C*        ====================================================         *RIGHTE      4
C*                                                                     *RIGHTE      5
C*       Copyright (C) (1993) Electric Power Research Institute        *RIGHTE      6
C*                                                                     *RIGHTE      7
C* EPRI reserves all rights in the software and associated             *RIGHTE      8
C* documentation as delivered. The software and its associated         *RIGHTE      9
C* documention or any portion thereof may not be reproduced in any form*RIGHTE     10
C* whatsoever without the consent of EPRI, except as explicity provided*RIGHTE     11
C* for by license. Licensee shall submit a detailed description to EPRI*RIGHTE     12
C* of any changes or modifications to the software within two (2)      *RIGHTE     13
C* months after such changes or modifications are made. At EPRI's sole *RIGHTE     14
C* discretion, the software, as changed or modified, shall be given a  *RIGHTE     15
C* new designation sufficiently different from its then current        *RIGHTE     16
C* designation as to prevent mistake,confusion, or deception as between*RIGHTE     17
C* the current software as changed or modified.                        *RIGHTE     18
C*                                                                     *RIGHTE     19
C* A license under EPRI's rights in the software can be obtained       *RIGHTE     20
C* directly from EPRI.                                                 *RIGHTE     21
C*                                                                     *RIGHTE     22
C* This program and supporting materials may be independently available*RIGHTE     23
C* from Electric Power Software centre (EPSC) for an appropriate       *RIGHTE     24
C* distribution fee. The EPSC is a service of                          *RIGHTE     25
C*                                                                     *RIGHTE     26
C*                    Power Computing Company                          *RIGHTE     27
C*                    1930 Hi Line                                     *RIGHTE     28
C*                    Dallas, Tx 75207                                 *RIGHTE     29
C*                                                                     *RIGHTE     30
C* NEITHER EPRI, ANY MEMBER OF EPRI, NOR ANY PERSON OR  ORGANIZATION   *RIGHTE     31
C* ACTING ON BEHAVE OF THEM:                                           *RIGHTE     32
C*                                                                     *RIGHTE     33
C* 1. MAKE ANY WARRANTY OR REPRESENTATION WHATSOEVER, EXPRESS OR       *RIGHTE     34
C*    IMPLIED, INCLUDING ANY WARRANTY OF MERCHANTABILITY OR FITNESS OR *RIGHTE     35
C*    ANY PURPOSE WITH RESPECT TO THE SOFTWARE OR ITS ASSOCIATED       *RIGHTE     36
C*    DOCUMENTATION; OR                                                *RIGHTE     37
C*                                                                     *RIGHTE     38
C* 2. ASSUMES ANY LIABILITY WHATSOEVER WITH RESPECT TO ANY USE OF THE  *RIGHTE     39
C*    SOFTWARE OR ITS ASSOCIATED DOCUMENTATION OR ANY PORTION THEREOF  *RIGHTE     40
C*    OR WITH RESPECT TO ANY DAMAGES WHICH MAY RESULT FROM SUCH USE.   *RIGHTE     41
C*                                                                     *RIGHTE     42
C* THIS NOTICE MAY NOT BE REMOVED FROM THE SOFTWARE BY ANY USER        *RIGHTE     43
C* THEREOF.                                                            *RIGHTE     44
C*                                                                     *RIGHTE     45
C***********************************************************************RIGHTE     46
      SUBROUTINE MINVRS(A,IA,MA,DETA,IER,IR,IC)                         MINVRS      3
CD                                                                      MINVRS      4
CD    TO INVERT A MATRIX OF SMALL SIZE.                                 MINVRS      5
CD                                                                      MINVRS      6
      INCLUDE 'CNUNIT.INS'                                              MINVRS      7
C                                                                       MINVRS      8
      DIMENSION A(IA,IA),IR(IA),IC(IA)                                  MINVRS      9
      IER=0                                                             MINVRS     10
      DO 1 I=1,MA                                                       MINVRS     11
      IR(I)=0                                                           MINVRS     12
    1 IC(I)=0                                                           MINVRS     13
      DETA=1.0                                                          MINVRS     14
      DO 123 IJKL=1,MA                                                  MINVRS     15
      CALL SUBMXS (A,IA,IA,MA,MA,IR,IC,I,J)                             MINVRS     16
      PIV=A(I,J)                                                        MINVRS     17
      ABSP=ABS(PIV)                                                     MINVRS     18
      IF(ABSP.LT.1.0E-8)GO TO 17                                        MINVRS     19
      IR(I)=J                                                           MINVRS     20
      IC(J)=I                                                           MINVRS     21
      PIV=1.0/PIV                                                       MINVRS     22
      A(I,J)=PIV                                                        MINVRS     23
      DO 5 K=1,MA                                                       MINVRS     24
    5 IF(K.NE.J) A(I,K)=A(I,K)*PIV                                      MINVRS     25
      DO 9 K=1,MA                                                       MINVRS     26
      IF(K.EQ.I)GO TO 9                                                 MINVRS     27
      PIV1=A(K,J)                                                       MINVRS     28
      DO 8 L=1,MA                                                       MINVRS     29
    8 A(K,L)=A(K,L)-PIV1*A(I,L)                                         MINVRS     30
      A(K,J)=PIV1                                                       MINVRS     31
    9 CONTINUE                                                          MINVRS     32
      PIV1=A(I,J)                                                       MINVRS     33
      DO 11 K=1,MA                                                      MINVRS     34
   11 A(K,J)=-PIV*A(K,J)                                                MINVRS     35
      A(I,J)=PIV1                                                       MINVRS     36
  123 CONTINUE                                                          MINVRS     37
      DO 16 I=1,MA                                                      MINVRS     38
      K=IC(I)                                                           MINVRS     39
      M=IR(I)                                                           MINVRS     40
      IF(K.EQ.I)GO TO 16                                                MINVRS     41
      DETA=-DETA                                                        MINVRS     42
      DO 14 L=1,MA                                                      MINVRS     43
      TEMP=A(K,L)                                                       MINVRS     44
      A(K,L)=A(I,L)                                                     MINVRS     45
   14 A(I,L)=TEMP                                                       MINVRS     46
      DO 15 L=1,MA                                                      MINVRS     47
      TEMP=A(L,M)                                                       MINVRS     48
      A(L,M)=A(L,I)                                                     MINVRS     49
   15 A(L,I)=TEMP                                                       MINVRS     50
      IC(M)=K                                                           MINVRS     51
      IR(K)=M                                                           MINVRS     52
   16 CONTINUE                                                          MINVRS     53
      RETURN                                                            MINVRS     54
   17 IER=1                                                             MINVRS     55
      WRITE(IU16,20)                                                    MINVRS     56
   20 FORMAT('1',25(/),10X,'**** SINGULAR MATRIX IN MINVRS ****',25(/)) MINVRS     57
      RETURN                                                            MINVRS     58
      END                                                               MINVRS     59
