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