CFPRIME AEXC3                                                           AEXC3       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 AEXC3(ISTATE,EPD,EPQ,MD,XAD)                           AEXC3       3
CD                                                                      AEXC3       4
CD    TO FORMULATE THE JACOBIAN MATRICES OF TYPES 3 AND 5 EXCITERS.     AEXC3       5
CD                                                                      AEXC3       6
      INCLUDE 'PARX.INS'                                                AEXC3       7
      INCLUDE 'CNB8.INS'                                                AEXC3       8
      INCLUDE 'CNB19.INS'                                               AEXC3       9
      INCLUDE 'CNEXC.INS'                                               AEXC3      10
      INCLUDE 'CNPARX.INS'                                              AEXC3      11
      INCLUDE 'CNMDAT.INS'                                              AEXC3      12
      INCLUDE 'CNXSTA.INS'                                              AEXC3      13
      INCLUDE 'CNMSTA.INS'                                              AEXC3      14
      INCLUDE 'CNPRGV.INS'                                              AEXC3      15
C                                                                       AEXC3      16
      INCLUDE 'CNABAK.INS'                                              AEXC3      17
C                                                                       AEXC3      18
      DIMENSION FIELD(10),IFIELD(10)                                    AEXC3      19
      EQUIVALENCE (FIELD(1),IFIELD(1))                                  AEXC3      20
C                                                                       AEXC3      21
      DO 10 I=4,8                                                       AEXC3      22
         FIELD(I)=0.0                                                   AEXC3      23
  10  CONTINUE                                                          AEXC3      24
C                                                                       AEXC3      25
C     SUBSCRIPTS                                                        AEXC3      26
C                                                                       AEXC3      27
      ISUB1=ISTATE+1                                                    AEXC3      28
      ISUB2=ISTATE+2                                                    AEXC3      29
      ISUB3=ISTATE+3                                                    AEXC3      30
      ISUB4=ISTATE+4                                                    AEXC3      31
      ISUB5=ISTATE+5                                                    AEXC3      32
      ISUB6=ISTATE+6                                                    AEXC3      33
      ISUB7=ISTATE+7                                                    AEXC3      34
      IF (IDDAT(JE+24).EQ.0) THEN                                       AEXC3      35
         TB1I=1.0                                                       AEXC3      36
         TC1TB1=1.0                                                     AEXC3      37
         ISUB8=0                                                        AEXC3      38
         IE=ISUB7                                                       AEXC3      39
      ELSE                                                              AEXC3      40
         TB1I=1.0/DDAT(JE+24)                                           AEXC3      41
         TC1TB1=DDAT(JE+23)*TB1I                                        AEXC3      42
         ISUB8=ISTATE+8                                                 AEXC3      43
         IE=ISUB8                                                       AEXC3      44
      END IF                                                            AEXC3      45
C                                                                       AEXC3      46
C     CALCULATE EXCITER CONSTANTS                                       AEXC3      47
C                                                                       AEXC3      48
      TEI=1.0/DDAT(JE+5)                                                AEXC3      49
      VE=XSTATE(JSTATE+7)                                               AEXC3      50
      XDEP=DDAT(JE+22)                                                  AEXC3      51
      VTH=VE-XDEP*CFDN                                                  AEXC3      52
      IF (VTH.EQ.0.0) THEN                                              AEXC3      53
         CIN=0.0                                                        AEXC3      54
      ELSE                                                              AEXC3      55
         CIN=DDAT(JE+9)*CFDN/VTH                                        AEXC3      56
      END IF                                                            AEXC3      57
      IF (CIN.LE.0.433) THEN                                            AEXC3      58
         FEX=1.0-0.58*CIN                                               AEXC3      59
         GAMA=-0.58                                                     AEXC3      60
      ELSE IF (CIN.GE.0.75) THEN                                        AEXC3      61
         FEX=1.732-1.732*CIN                                            AEXC3      62
         GAMA=-1.732                                                    AEXC3      63
      ELSE                                                              AEXC3      64
         FEX=SQRT(0.75-CIN*CIN)                                         AEXC3      65
         GAMA=-CIN/FEX                                                  AEXC3      66
      END IF                                                            AEXC3      67
C                                                                       AEXC3      68
      C15=FEX-GAMA*CIN                                                  AEXC3      69
      CF=GAMA*CIN*VE/CFDN-XDEP*FEX                                      AEXC3      70
C                                                                       AEXC3      71
C     INPUT FROM TERMINAL VOLTAGE LIMITER                               AEXC3      72
C                                                                       AEXC3      73
      IF (ET.LE.DDAT(JE+29)) THEN                                       AEXC3      74
         CVD=0.0                                                        AEXC3      75
         CVQ=0.0                                                        AEXC3      76
      ELSE                                                              AEXC3      77
         CVD=EPD/ET                                                     AEXC3      78
         CVQ=EPQ/ET                                                     AEXC3      79
      END IF                                                            AEXC3      80
C                                                                       AEXC3      81
C     V/HZ BLOCK                                                        AEXC3      82
C                                                                       AEXC3      83
      WS1=-DDAT(JE+31)*WXBASE*XSPU                                      AEXC3      84
      A(ISUB2,1)=WS1*XSPU*XSTATE(JSTATE+1)                              AEXC3      85
      CZ2=DDAT(JE+32)                                                   AEXC3      86
C                                                                       AEXC3      87
      IF (INPUTR.EQ.0) THEN                                             AEXC3      88
         CALL BCBTEM(ISUB2,WS1)                                         AEXC3      89
      ELSE                                                              AEXC3      90
         A(ISUB2,ISUB1)=-WS1                                            AEXC3      91
      END IF                                                            AEXC3      92
C                                                                       AEXC3      93
C     TL1, TL2 BLOCK                                                    AEXC3      94
C                                                                       AEXC3      95
      CETL=DDAT(JE+26)                                                  AEXC3      96
      CVD=CVD*CETL                                                      AEXC3      97
      CVQ=CVQ*CETL                                                      AEXC3      98
      IF (IDDAT(JE+28).EQ.0) THEN                                       AEXC3      99
         TL1TL2=1.0                                                     AEXC3     100
      ELSE                                                              AEXC3     101
         TL2I=1.0/DDAT(JE+28)                                           AEXC3     102
         TL1TL2=DDAT(JE+27)*TL2I                                        AEXC3     103
         A(ISUB3,ISUB3)=-TL2I                                           AEXC3     104
         B(ISUB3,1)=CVD*TL2I                                            AEXC3     105
         B(ISUB3,2)=CVQ*TL2I                                            AEXC3     106
         CVD=CVD*TL1TL2                                                 AEXC3     107
         CVQ=CVQ*TL1TL2                                                 AEXC3     108
      END IF                                                            AEXC3     109
C                                                                       AEXC3     110
C     TF BLOCK                                                          AEXC3     111
C                                                                       AEXC3     112
      BETA=DDAT(JE+4)+DDAT(JE+6)*DDAT(JE+7)                             AEXC3     113
     *     *EXP(DDAT(JE+7)*VE)                                          AEXC3     114
      ALP5=DDAT(JE+21)-XDEP                                             AEXC3     115
C                                                                       AEXC3     116
      IF (IEXN.EQ.3) THEN                                               AEXC3     117
         COF1=C15                                                       AEXC3     118
         COF2=CF                                                        AEXC3     119
      ELSE                                                              AEXC3     120
         COF1=BETA                                                      AEXC3     121
         COF2=ALP5                                                      AEXC3     122
      END IF                                                            AEXC3     123
C                                                                       AEXC3     124
      IF (IDDAT(JE+11).EQ.0) THEN                                       AEXC3     125
         CFTF=0.0                                                       AEXC3     126
      ELSE                                                              AEXC3     127
         TFI=1.0/DDAT(JE+11)                                            AEXC3     128
         CFTF=DDAT(JE+10)*TFI                                           AEXC3     129
         A(ISUB4,ISUB4)=-TFI                                            AEXC3     130
         A(ISUB4,ISUB7)=COF1*TFI                                        AEXC3     131
C                                                                       AEXC3     132
         FIELD(4)=COF2*TFI                                              AEXC3     133
C                                                                       AEXC3     134
      END IF                                                            AEXC3     135
C                                                                       AEXC3     136
C     TC, TB BLOCK                                                      AEXC3     137
C                                                                       AEXC3     138
      IF (IDDAT(JE+13).EQ.0) THEN                                       AEXC3     139
         TCTB=1.0                                                       AEXC3     140
      ELSE                                                              AEXC3     141
         TBI=1.0/DDAT(JE+13)                                            AEXC3     142
         TCTB=DDAT(JE+12)*TBI                                           AEXC3     143
         WS1=CFTF*TBI                                                   AEXC3     144
         A(ISUB5,ISUB2)=CZ2*TBI                                         AEXC3     145
         A(ISUB5,ISUB3)=-TBI*(1.0-TL1TL2)                               AEXC3     146
         A(ISUB5,ISUB4)=WS1                                             AEXC3     147
         A(ISUB5,ISUB5)=-TBI                                            AEXC3     148
         A(ISUB5,ISUB7)=-COF1*WS1                                       AEXC3     149
C                                                                       AEXC3     150
         IF (INPUTR.EQ.0) THEN                                          AEXC3     151
            CALL BCBTEM(ISUB5,TBI)                                      AEXC3     152
            B(ISUB5,1)=B(ISUB5,1)-CVD*TBI                               AEXC3     153
            B(ISUB5,2)=B(ISUB5,2)-CVQ*TBI                               AEXC3     154
         ELSE                                                           AEXC3     155
            A(ISUB5,ISUB1)=-TBI                                         AEXC3     156
            B(ISUB5,1)=-CVD*TBI                                         AEXC3     157
            B(ISUB5,2)=-CVQ*TBI                                         AEXC3     158
         END IF                                                         AEXC3     159
         CVD=CVD*TCTB                                                   AEXC3     160
         CVQ=CVQ*TCTB                                                   AEXC3     161
C                                                                       AEXC3     162
         FIELD(5)=-COF2*WS1                                             AEXC3     163
C                                                                       AEXC3     164
         IUST(1)=ISUB5                                                  AEXC3     165
         GUST(1)=TBI                                                    AEXC3     166
C                                                                       AEXC3     167
      END IF                                                            AEXC3     168
C                                                                       AEXC3     169
C     TK,TA BLOCK                                                       AEXC3     170
C                                                                       AEXC3     171
      CA=DDAT(JE+2)                                                     AEXC3     172
      IF (IDDAT(JE+3).EQ.0) THEN                                        AEXC3     173
         TKTA=1.0                                                       AEXC3     174
         CATKTA=CA                                                      AEXC3     175
         GAIN1=TCTB*CA                                                  AEXC3     176
         GAIN2=GAIN1*CFTF                                               AEXC3     177
         CVD=CVD*CA                                                     AEXC3     178
         CVQ=CVQ*CA                                                     AEXC3     179
      ELSE                                                              AEXC3     180
         TAI=1.0/DDAT(JE+3)                                             AEXC3     181
         TK=DDAT(JE+17)                                                 AEXC3     182
         CATA=CA*TAI                                                    AEXC3     183
         TKTA=TK*TAI                                                    AEXC3     184
         CATKTA=CA*TKTA                                                 AEXC3     185
         GAIN1=TCTB*CATA                                                AEXC3     186
         GAIN2=GAIN1*CFTF                                               AEXC3     187
         A(ISUB6,ISUB2)=CZ2*GAIN1                                       AEXC3     188
         A(ISUB6,ISUB3)=-GAIN1*(1.0-TL1TL2)                             AEXC3     189
         A(ISUB6,ISUB4)=GAIN2                                           AEXC3     190
         A(ISUB6,ISUB5)=CATA-GAIN1                                      AEXC3     191
         A(ISUB6,ISUB6)=-TAI                                            AEXC3     192
         A(ISUB6,ISUB7)=-COF1*GAIN2                                     AEXC3     193
C                                                                       AEXC3     194
         IF (INPUTR.EQ.0) THEN                                          AEXC3     195
            CALL BCBTEM(ISUB6,GAIN1)                                    AEXC3     196
            B(ISUB6,1)=B(ISUB6,1)-CVD*CATA                              AEXC3     197
            B(ISUB6,2)=B(ISUB6,2)-CVQ*CATA                              AEXC3     198
         ELSE                                                           AEXC3     199
            A(ISUB6,ISUB1)=-GAIN1                                       AEXC3     200
            B(ISUB6,1)=-CVD*CATA                                        AEXC3     201
            B(ISUB6,2)=-CVQ*CATA                                        AEXC3     202
         END IF                                                         AEXC3     203
         CATA=CATA*TK                                                   AEXC3     204
         CVD=CVD*CATA                                                   AEXC3     205
         CVQ=CVQ*CATA                                                   AEXC3     206
C                                                                       AEXC3     207
         FIELD(6)=-COF2*GAIN2                                           AEXC3     208
C                                                                       AEXC3     209
         IF (IUST(1).EQ.0) THEN                                         AEXC3     210
            IUST(1)=ISUB6                                               AEXC3     211
            GUST(1)=GAIN1                                               AEXC3     212
         ELSE                                                           AEXC3     213
            IUST(2)=ISUB6                                               AEXC3     214
            GUST(2)=GAIN1                                               AEXC3     215
         END IF                                                         AEXC3     216
C                                                                       AEXC3     217
         GAIN1=GAIN1*TK                                                 AEXC3     218
         GAIN2=GAIN2*TK                                                 AEXC3     219
C                                                                       AEXC3     220
      END IF                                                            AEXC3     221
C                                                                       AEXC3     222
C     TC1, TB1 BLOCK (OPTIONAL)                                         AEXC3     223
C                                                                       AEXC3     224
      IF (ISUB8.NE.0) THEN                                              AEXC3     225
         WS1=GAIN1*TB1I                                                 AEXC3     226
         WS2=GAIN2*TB1I                                                 AEXC3     227
         A(ISUB8,ISUB2)=CZ2*WS1                                         AEXC3     228
         A(ISUB8,ISUB3)=-WS1*(1.0-TL1TL2)                               AEXC3     229
         A(ISUB8,ISUB4)=WS2                                             AEXC3     230
         A(ISUB8,ISUB5)=CATKTA*(1.0-TCTB)                               AEXC3     231
         A(ISUB8,ISUB6)=TB1I*(1.0-TKTA)                                 AEXC3     232
         A(ISUB8,ISUB7)=-COF1*WS2                                       AEXC3     233
         A(ISUB8,ISUB8)=-TB1I                                           AEXC3     234
         A(ISUB7,ISUB8)=TEI*(1.0-TC1TB1)                                AEXC3     235
C                                                                       AEXC3     236
         IF (INPUTR.EQ.0) THEN                                          AEXC3     237
            CALL BCBTEM(ISUB8,WS1)                                      AEXC3     238
            B(ISUB8,1)=B(ISUB8,1)-CVD*TB1I                              AEXC3     239
            B(ISUB8,2)=B(ISUB8,2)-CVQ*TB1I                              AEXC3     240
         ELSE                                                           AEXC3     241
            A(ISUB8,ISUB1)=-WS1                                         AEXC3     242
            B(ISUB8,1)=-CVD*TB1I                                        AEXC3     243
            B(ISUB8,2)=-CVQ*TB1I                                        AEXC3     244
         END IF                                                         AEXC3     245
         CVD=CVD*TC1TB1                                                 AEXC3     246
         CVQ=CVQ*TC1TB1                                                 AEXC3     247
C                                                                       AEXC3     248
         FIELD(8)=-COF2*GAIN2                                           AEXC3     249
C                                                                       AEXC3     250
         IF (IUST(1).EQ.0) THEN                                         AEXC3     251
            IUST(1)=ISUB8                                               AEXC3     252
            GUST(1)=WS1                                                 AEXC3     253
         ELSE IF (IUST(2).EQ.0) THEN                                    AEXC3     254
            IUST(2)=ISUB8                                               AEXC3     255
            GUST(2)=WS1                                                 AEXC3     256
         ELSE                                                           AEXC3     257
            IUST(3)=ISUB8                                               AEXC3     258
            IUST(3)=WS1                                                 AEXC3     259
         END IF                                                         AEXC3     260
C                                                                       AEXC3     261
         GAIN1=GAIN1*TC1TB1                                             AEXC3     262
         GAIN2=GAIN2*TC1TB1                                             AEXC3     263
C                                                                       AEXC3     264
      END IF                                                            AEXC3     265
C                                                                       AEXC3     266
C     TE BLOCK                                                          AEXC3     267
C                                                                       AEXC3     268
      GAIN1=GAIN1*TEI                                                   AEXC3     269
      GAIN2=GAIN2*TEI                                                   AEXC3     270
      A(ISUB7,ISUB2)=CZ2*GAIN1                                          AEXC3     271
      A(ISUB7,ISUB3)=-GAIN1*(1.0-TL1TL2)                                AEXC3     272
      A(ISUB7,ISUB4)=GAIN2                                              AEXC3     273
      A(ISUB7,ISUB5)=CATKTA*TC1TB1*TEI-GAIN1                            AEXC3     274
      A(ISUB7,ISUB6)=TC1TB1*TEI*(1.0-TKTA)                              AEXC3     275
      A(ISUB7,ISUB7)=-BETA*TEI-COF1*GAIN2                               AEXC3     276
C                                                                       AEXC3     277
      IF (INPUTR.EQ.0) THEN                                             AEXC3     278
         CALL BCBTEM(ISUB7,GAIN1)                                       AEXC3     279
         B(ISUB7,1)=B(ISUB7,1)-CVD*TEI                                  AEXC3     280
         B(ISUB7,2)=B(ISUB7,2)-CVQ*TEI                                  AEXC3     281
      ELSE                                                              AEXC3     282
         A(ISUB7,ISUB1)=-GAIN1                                          AEXC3     283
         B(ISUB7,1)=-CVD*TEI                                            AEXC3     284
         B(ISUB7,2)=-CVQ*TEI                                            AEXC3     285
      END IF                                                            AEXC3     286
C                                                                       AEXC3     287
      FIELD(7)=-ALP5*TEI-COF2*GAIN2                                     AEXC3     288
C                                                                       AEXC3     289
      IF (IUST(1).EQ.0) THEN                                            AEXC3     290
         IUST(1)=ISUB7                                                  AEXC3     291
         GUST(1)=GAIN1                                                  AEXC3     292
      ELSE IF (IUST(2).EQ.0) THEN                                       AEXC3     293
         IUST(2)=ISUB7                                                  AEXC3     294
         GUST(2)=GAIN1                                                  AEXC3     295
      ELSE IF (IUST(3).EQ.0) THEN                                       AEXC3     296
         IUST(3)=ISUB7                                                  AEXC3     297
         GUST(3)=GAIN1                                                  AEXC3     298
      ELSE                                                              AEXC3     299
         IUST(4)=ISUB7                                                  AEXC3     300
         GUST4=GAIN1                                                    AEXC3     301
      END IF                                                            AEXC3     302
C                                                                       AEXC3     303
C     ELIMINATE THE FIELD CURRENT TERM IN STATE EQUATION                AEXC3     304
C                                                                       AEXC3     305
      DO 20 I=4,8                                                       AEXC3     306
         IF (IFIELD(I).EQ.0) GOTO 20                                    AEXC3     307
         II=ISTATE+I                                                    AEXC3     308
         WS1=XAD*FIELD(I)                                               AEXC3     309
C                                                                       AEXC3     310
         DO 30 J=1,MD+1                                                 AEXC3     311
            A(II,J+1)=WS1*FCTM(J)                                       AEXC3     312
  30     CONTINUE                                                       AEXC3     313
C                                                                       AEXC3     314
         BC(II,1)=BC(II,1)+WS1*FCTM(5)                                  AEXC3     315
         BC(II,2)=BC(II,2)+WS1*FCTM(6)                                  AEXC3     316
C                                                                       AEXC3     317
  20  CONTINUE                                                          AEXC3     318
C                                                                       AEXC3     319
C     INTERCONNECTION WITH GENERATOR (OUTPUT EQUATION)                  AEXC3     320
C                                                                       AEXC3     321
      A(3,ISUB7)=CFEXC*C15                                              AEXC3     322
      CF=CF*CFEXC*XAD                                                   AEXC3     323
      DO 120 I=1,MD+1                                                   AEXC3     324
         A(3,I+1)=A(3,I+1)+CF*FCTM(I)                                   AEXC3     325
 120  CONTINUE                                                          AEXC3     326
      BC(3,1)=BC(3,1)+CF*FCTM(5)                                        AEXC3     327
      BC(3,2)=BC(3,2)+CF*FCTM(6)                                        AEXC3     328
C                                                                       AEXC3     329
      ISTATE=IE                                                         AEXC3     330
C                                                                       AEXC3     331
      RETURN                                                            AEXC3     332
      END                                                               AEXC3     333
