CFPRIME AEXC31                                                          AEXC31      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 AEXC31(ISTATE,EPD,EPQ,VCOMP,MD,XAD)                    AEXC31      3
CD                                                                      AEXC31      4
CD    TO FORMULATE THE JACOBIAN MATRICES OF TYPE 31 EXCITER.            AEXC31      5
CD                                                                      AEXC31      6
      INCLUDE 'PARX.INS'                                                AEXC31      7
      INCLUDE 'CNB8.INS'                                                AEXC31      8
      INCLUDE 'CNEXC.INS'                                               AEXC31      9
      INCLUDE 'CNMYVA.INS'                                              AEXC31     10
      INCLUDE 'CNYVAR.INS'                                              AEXC31     11
      INCLUDE 'CNPARX.INS'                                              AEXC31     12
      INCLUDE 'CNMDAT.INS'                                              AEXC31     13
      INCLUDE 'CNXSTA.INS'                                              AEXC31     14
      INCLUDE 'CNMSTA.INS'                                              AEXC31     15
C                                                                       AEXC31     16
      INCLUDE 'CNABAK.INS'                                              AEXC31     17
C                                                                       AEXC31     18
      DIMENSION FIELD(10),IFIELD(10)                                    AEXC31     19
      EQUIVALENCE (FIELD(1),IFIELD(1))                                  AEXC31     20
C                                                                       AEXC31     21
      I3=0                                                              AEXC31     22
      JYE=MYVAR(2,N)                                                    AEXC31     23
C                                                                       AEXC31     24
      DO 10 I=1,3                                                       AEXC31     25
         FIELD(I)=0.0                                                   AEXC31     26
  10  CONTINUE                                                          AEXC31     27
C                                                                       AEXC31     28
C     SUBSCRIPTS                                                        AEXC31     29
C                                                                       AEXC31     30
      ISUB1=ISTATE+1                                                    AEXC31     31
      ISUB2=IDDAT(JE+26)                                                AEXC31     32
      ISUB3=IDDAT(JE+27)                                                AEXC31     33
      IE=ISUB1                                                          AEXC31     34
C                                                                       AEXC31     35
C     INPUT FROM TERMINAL VOLTAGE LIMITER                               AEXC31     36
C                                                                       AEXC31     37
      IF (ET.LE.DDAT(JE+24)) THEN                                       AEXC31     38
         CVD=0.0                                                        AEXC31     39
         CVQ=0.0                                                        AEXC31     40
         VDIFF=0.0                                                      AEXC31     41
      ELSE                                                              AEXC31     42
         CVD=EPD/ET                                                     AEXC31     43
         CVQ=EPQ/ET                                                     AEXC31     44
         VDIFF=ET-DDAT(JE+24)                                           AEXC31     45
      END IF                                                            AEXC31     46
C                                                                       AEXC31     47
C     INPUT FROM FIELD CURRENT LIMITER                                  AEXC31     48
C                                                                       AEXC31     49
      IF (CFDN.LE.DDAT(JE+16)) THEN                                     AEXC31     50
         CIFL=0.0                                                       AEXC31     51
      ELSE                                                              AEXC31     52
         CIFL=DDAT(JE+15)                                               AEXC31     53
      END IF                                                            AEXC31     54
C                                                                       AEXC31     55
C     TL1, TL2 BLOCK (OPTIONAL)                                         AEXC31     56
C                                                                       AEXC31     57
      CETL=DDAT(JE+21)                                                  AEXC31     58
      IF (ISUB2.EQ.0) THEN                                              AEXC31     59
         CVD=CVD*CETL                                                   AEXC31     60
         CVQ=CVQ*CETL                                                   AEXC31     61
         TL1TL2=1.0                                                     AEXC31     62
      ELSE                                                              AEXC31     63
         TL2I=1.0/DDAT(JE+23)                                           AEXC31     64
         TL1TL2=DDAT(JE+22)*TL2I                                        AEXC31     65
         CVD=CVD*CETL                                                   AEXC31     66
         CVQ=CVQ*CETL                                                   AEXC31     67
         A(ISUB2,ISUB2)=-TL2I                                           AEXC31     68
         B(ISUB2,1)=CVD*TL2I                                            AEXC31     69
         B(ISUB2,2)=CVQ*TL2I                                            AEXC31     70
         CVD=CVD*TL1TL2                                                 AEXC31     71
         CVQ=CVQ*TL1TL2                                                 AEXC31     72
         IE=ISUB2                                                       AEXC31     73
      END IF                                                            AEXC31     74
C                                                                       AEXC31     75
C     TC, TB BLOCK (OPTIONAL)                                           AEXC31     76
C                                                                       AEXC31     77
      IF (ISUB3.EQ.0) THEN                                              AEXC31     78
         TCTB=1.0                                                       AEXC31     79
      ELSE                                                              AEXC31     80
         TBI=1.0/DDAT(JE+5)                                             AEXC31     81
         TCTB=DDAT(JE+4)*TBI                                            AEXC31     82
         A(ISUB3,ISUB3)=-TBI                                            AEXC31     83
         IF (ISUB2.NE.0) A(ISUB3,ISUB2)=-TBI*(1.0-TL1TL2)               AEXC31     84
C                                                                       AEXC31     85
         I3=ISUB3-ISTATE                                                AEXC31     86
         FIELD(I3)=-TBI*CIFL                                            AEXC31     87
         IF (INPUTR.EQ.0) THEN                                          AEXC31     88
            CALL BCBTEM(ISUB3,TBI)                                      AEXC31     89
         ELSE                                                           AEXC31     90
            A(ISUB3,ISUB1)=-TBI                                         AEXC31     91
         END IF                                                         AEXC31     92
         B(ISUB3,1)=B(ISUB3,1)+CVD*TBI                                  AEXC31     93
         B(ISUB3,2)=B(ISUB3,2)+CVQ*TBI                                  AEXC31     94
C                                                                       AEXC31     95
         IUST(1)=ISUB3                                                  AEXC31     96
         GUST(1)=TBI                                                    AEXC31     97
C                                                                       AEXC31     98
         IE=ISUB3                                                       AEXC31     99
C                                                                       AEXC31    100
      END IF                                                            AEXC31    101
C                                                                       AEXC31    102
C     ELIMINATE THE FIELD CURRENT TERM IN STATE EQUATION                AEXC31    103
C                                                                       AEXC31    104
      IF (ISUB3.EQ.0) GOTO 20                                           AEXC31    105
      IF (IFIELD(I3).EQ.0) GOTO 20                                      AEXC31    106
      WS1=XAD*FIELD(I3)                                                 AEXC31    107
C                                                                       AEXC31    108
      DO 30 J=1,MD+1                                                    AEXC31    109
         A(ISUB3,J+1)=WS1*FCTM(J)                                       AEXC31    110
  30  CONTINUE                                                          AEXC31    111
C                                                                       AEXC31    112
      BC(ISUB3,1)=BC(ISUB3,1)+WS1*FCTM(5)                               AEXC31    113
      BC(ISUB3,2)=BC(ISUB3,2)+WS1*FCTM(6)                               AEXC31    114
C                                                                       AEXC31    115
  20  CONTINUE                                                          AEXC31    116
C                                                                       AEXC31    117
C     INTERCONNECTION WITH GENERATOR (OUTPUT EQUATION)                  AEXC31    118
C                                                                       AEXC31    119
      BETA5=DDAT(JE+2)/DDAT(JE+3)                                       AEXC31    120
C                                                                       AEXC31    121
C     CALCULATE PHI                                                     AEXC31    122
C                                                                       AEXC31    123
      IF (ISUB3.NE.0.AND.IDDAT(JE+4).EQ.0) THEN                         AEXC31    124
C                                                                       AEXC31    125
         IWS1=JSTATE+ISUB3-ISTATE                                       AEXC31    126
         PHI=BETA5*XSTATE(IWS1)                                         AEXC31    127
         BETA5G=0.0                                                     AEXC31    128
C                                                                       AEXC31    129
      ELSE                                                              AEXC31    130
C                                                                       AEXC31    131
         PHI=-TL1TL2*CETL*ET-CIFL*CFDN+VREF(JYE+2)                      AEXC31    132
     *       +TL1TL2*CETL*DDAT(JE+24)+CIFL*DDAT(JE+16)                  AEXC31    133
C                                                                       AEXC31    134
         IF (INPUTR.EQ.0) THEN                                          AEXC31    135
            PHI=PHI-VCOMP                                               AEXC31    136
         ELSE                                                           AEXC31    137
            PHI=PHI-XSTATE(JSTATE+1)                                    AEXC31    138
         END IF                                                         AEXC31    139
C                                                                       AEXC31    140
         IF (ISUB2.EQ.0) THEN                                           AEXC31    141
            PHI=PHI-VDIFF                                               AEXC31    142
         ELSE                                                           AEXC31    143
            IWS1=JSTATE+ISUB2-ISTATE                                    AEXC31    144
            PHI=PHI-(1.0-TL1TL2)*XSTATE(IWS1)                           AEXC31    145
         END IF                                                         AEXC31    146
C                                                                       AEXC31    147
         IF (ISUB3.NE.0) THEN                                           AEXC31    148
            IWS1=JSTATE+ISUB3-ISTATE                                    AEXC31    149
            PHI=PHI+(1.0/TCTB-1.0)*XSTATE(IWS1)                         AEXC31    150
         END IF                                                         AEXC31    151
C                                                                       AEXC31    152
         IF (ISTABN.GT.0) PHI=PHI+VSS(JYS+1)                            AEXC31    153
         IF ((IUALN.NE.0.AND.IUALN.LT.10).OR.IUALN.EQ.50)               AEXC31    154
     &      PHI=PHI+VUAL(JYU+1)                                         AEXC31    155
         IF (ITEBN.NE.0) PHI=PHI+TEB(JYTB+1)                            AEXC31    156
         IF (IMXLN.NE.0.AND.IMXLN.LE.10) PHI=PHI-VMXL(JYMX+1)           AEXC31    157
C                                                                       AEXC31    158
         BETA5G=BETA5*TCTB                                              AEXC31    159
         PHI=BETA5G*PHI                                                 AEXC31    160
C                                                                       AEXC31    161
      END IF                                                            AEXC31    162
C                                                                       AEXC31    163
      BETA1=COS(PHI)*(DDAT(JE+3)*ET-DDAT(JE+13)*CFDN)                   AEXC31    164
      SINPHI=SIN(PHI)                                                   AEXC31    165
      BETA4=-SINPHI*DDAT(JE+13)                                         AEXC31    166
      SINPHI=SINPHI*DDAT(JE+3)/ET                                       AEXC31    167
      BETA2=SINPHI*EPD                                                  AEXC31    168
      BETA3=SINPHI*EPQ                                                  AEXC31    169
C                                                                       AEXC31    170
C     CALCULATE CURRENT AND VOLTAGE COMPONENTS IN OUTPUT EQUATION       AEXC31    171
C                                                                       AEXC31    172
      BETA5G=BETA1*BETA5G                                               AEXC31    173
      CF=CFEXC*XAD                                                      AEXC31    174
      WS1=CF*BETA5G                                                     AEXC31    175
      IF (INPUTR.EQ.0) THEN                                             AEXC31    176
         BC(3,1)=BC(3,1)-WS1*ALP1                                       AEXC31    177
         BC(3,2)=BC(3,2)-WS1*ALP2                                       AEXC31    178
         B(3,KN-1)=B(3,KN-1)-WS1*ALP3                                   AEXC31    179
         B(3,KN)=B(3,KN)-WS1*ALP4                                       AEXC31    180
      ELSE                                                              AEXC31    181
         A(3,ISUB1)=-CFEXC*BETA5G                                       AEXC31    182
      END IF                                                            AEXC31    183
      B(3,1)=B(3,1)+CF*(BETA2-BETA5G*CVD)                               AEXC31    184
      B(3,2)=B(3,2)+CF*(BETA3-BETA5G*CVQ)                               AEXC31    185
C                                                                       AEXC31    186
C     CALCULATE FIELD CURRENT COMPONENT IN OUTPUT EQUATION              AEXC31    187
C                                                                       AEXC31    188
      FCURR=BETA4-BETA5G*CIFL                                           AEXC31    189
C                                                                       AEXC31    190
C     CALCULATE THE COUPLING ELEMENTS IN STATE EQUATION DUE TO          AEXC31    191
C     THE STATE COMPONENTS IN OUTPUT EQUATION. A(3,ISUB1) IS            AEXC31    192
C     ALREADY CALCULATED ABOVE                                          AEXC31    193
C                                                                       AEXC31    194
      IF (ISUB2.NE.0) A(3,ISUB2)=-CFEXC*BETA5G*(1.0-TL1TL2)             AEXC31    195
      IF (ISUB3.NE.0) A(3,ISUB3)=CFEXC*BETA1*BETA5*(1.0-TCTB)           AEXC31    196
C                                                                       AEXC31    197
C     ELIMINATE FIELD CURRENT COMPONENT IN OUTPUT EQUATION              AEXC31    198
C                                                                       AEXC31    199
      FCURR=CF*FCURR                                                    AEXC31    200
      DO 40 I=1,MD+1                                                    AEXC31    201
         A(3,I+1)=A(3,I+1)+FCURR*FCTM(I)                                AEXC31    202
  40  CONTINUE                                                          AEXC31    203
C                                                                       AEXC31    204
      BC(3,1)=BC(3,1)+FCURR*FCTM(5)                                     AEXC31    205
      BC(3,2)=BC(3,2)+FCURR*FCTM(6)                                     AEXC31    206
C                                                                       AEXC31    207
C     OBTAIN INPUT POSITION FROM OTHER CONTROLS                         AEXC31    208
C                                                                       AEXC31    209
      IF (IUST(1).EQ.0) THEN                                            AEXC31    210
         IUST(1)=3                                                      AEXC31    211
         GUST(1)=BETA5G                                                 AEXC31    212
      ELSE                                                              AEXC31    213
         IUST(2)=3                                                      AEXC31    214
         GUST(2)=BETA5G                                                 AEXC31    215
      END IF                                                            AEXC31    216
C                                                                       AEXC31    217
      ISTATE=IE                                                         AEXC31    218
C                                                                       AEXC31    219
      RETURN                                                            AEXC31    220
      END                                                               AEXC31    221
