CFPRIME AEXC4                                                           AEXC4       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 AEXC4(ISTATE,MD,XAD)                                   AEXC4       3
CD                                                                      AEXC4       4
CD    TO FORMULATE THE JACOBIAN MATRICES OF TYPE 4 EXCITER              AEXC4       5
CD    (IEEE TYPE AC3).                                                  AEXC4       6
CD                                                                      AEXC4       7
      INCLUDE 'PARX.INS'                                                AEXC4       8
      INCLUDE 'CNB8.INS'                                                AEXC4       9
      INCLUDE 'CNEXC.INS'                                               AEXC4      10
      INCLUDE 'CNPARX.INS'                                              AEXC4      11
      INCLUDE 'CNMDAT.INS'                                              AEXC4      12
      INCLUDE 'CNXSTA.INS'                                              AEXC4      13
      INCLUDE 'CNMSTA.INS'                                              AEXC4      14
      INCLUDE 'CNMYVA.INS'                                              AEXC4      15
      INCLUDE 'CNYVAR.INS'                                              AEXC4      16
      INCLUDE 'CNXDOT.INS'                                              AEXC4      17
C                                                                       AEXC4      18
      INCLUDE 'CNABAK.INS'                                              AEXC4      19
C                                                                       AEXC4      20
      DIMENSION FIELD(10),IFIELD(10)                                    AEXC4      21
      EQUIVALENCE (FIELD(1),IFIELD(1))                                  AEXC4      22
C                                                                       AEXC4      23
      DO 10 I=2,5                                                       AEXC4      24
         FIELD(I)=0.0                                                   AEXC4      25
  10  CONTINUE                                                          AEXC4      26
C                                                                       AEXC4      27
      JY=MYVAR(1,N)                                                     AEXC4      28
C                                                                       AEXC4      29
C     SUBSCRIPTS                                                        AEXC4      30
C                                                                       AEXC4      31
      ISUB1=ISTATE+1                                                    AEXC4      32
      ISUB2=ISTATE+2                                                    AEXC4      33
      ISUB3=ISTATE+3                                                    AEXC4      34
      ISUB4=ISTATE+4                                                    AEXC4      35
      ISUB5=ISTATE+5                                                    AEXC4      36
C                                                                       AEXC4      37
      ICASE=IDDAT(JE+29)                                                AEXC4      38
C                                                                       AEXC4      39
C     FIELD VOLTAGE                                                     AEXC4      40
C                                                                       AEXC4      41
      EFDN=EFD(JY+4)                                                    AEXC4      42
C                                                                       AEXC4      43
C     CALCULATE EXCITER CONSTANTS                                       AEXC4      44
C                                                                       AEXC4      45
      VE=XSTATE(JSTATE+5)                                               AEXC4      46
      BETA=DDAT(JE+4)+DDAT(JE+6)*DDAT(JE+7)                             AEXC4      47
     *     *EXP(DDAT(JE+7)*VE)                                          AEXC4      48
      XDEP=DDAT(JE+22)                                                  AEXC4      49
      ALP5=DDAT(JE+21)-XDEP                                             AEXC4      50
      VTH=VE-XDEP*CFDN                                                  AEXC4      51
      IF (VTH.EQ.0.0) THEN                                              AEXC4      52
         CIN=0.0                                                        AEXC4      53
      ELSE                                                              AEXC4      54
         CIN=DDAT(JE+9)*CFDN/VTH                                        AEXC4      55
      END IF                                                            AEXC4      56
      IF (CIN.LE.0.433) THEN                                            AEXC4      57
         FEX=1.0-0.58*CIN                                               AEXC4      58
         GAMA=-0.58                                                     AEXC4      59
      ELSE IF (CIN.GE.0.75) THEN                                        AEXC4      60
         FEX=1.732-1.732*CIN                                            AEXC4      61
         GAMA=-1.732                                                    AEXC4      62
      ELSE                                                              AEXC4      63
         FEX=SQRT(0.75-CIN*CIN)                                         AEXC4      64
         GAMA=-CIN/FEX                                                  AEXC4      65
      END IF                                                            AEXC4      66
C                                                                       AEXC4      67
      C15=FEX-GAMA*CIN                                                  AEXC4      68
      CF=GAMA*CIN*VE/CFDN-XDEP*FEX                                      AEXC4      69
C                                                                       AEXC4      70
C     NOTE: TYPES AC3 AND AC3A ARE HANDLED DIFFERENTLY BY THE           AEXC4      71
C           FOLLOWING STATEMENT                                         AEXC4      72
C                                                                       AEXC4      73
      IF (DDAT(JE+28).LT.0.5) GOTO 100                                  AEXC4      74
C                                                                       AEXC4      75
C     FOR TYPE AC3                                                      AEXC4      76
C                                                                       AEXC4      77
C     TF BLOCK                                                          AEXC4      78
C                                                                       AEXC4      79
      IF (IDDAT(JE+11).EQ.0) THEN                                       AEXC4      80
         TFI=1.0                                                        AEXC4      81
         CFTF=0.0                                                       AEXC4      82
      ELSE                                                              AEXC4      83
         TFI=1.0/DDAT(JE+11)                                            AEXC4      84
C                                                                       AEXC4      85
C     DETERMINE PROPER GAIN FOR RATE FEEDBACK                           AEXC4      86
C                                                                       AEXC4      87
         IF (EFDN.LE.DDAT(JE+24)) THEN                                  AEXC4      88
            CFTF=DDAT(JE+10)*TFI                                        AEXC4      89
         ELSE                                                           AEXC4      90
            CFTF=DDAT(JE+23)*TFI                                        AEXC4      91
         END IF                                                         AEXC4      92
         A(ISUB2,ISUB2)=-TFI                                            AEXC4      93
         A(ISUB2,ISUB5)=C15*CFTF                                        AEXC4      94
C                                                                       AEXC4      95
         FIELD(2)=CF*CFTF                                               AEXC4      96
C                                                                       AEXC4      97
      END IF                                                            AEXC4      98
C                                                                       AEXC4      99
C     TC, TB BLOCK                                                      AEXC4     100
C                                                                       AEXC4     101
      IF (IDDAT(JE+13).EQ.0) THEN                                       AEXC4     102
         TCTB=1.0                                                       AEXC4     103
      ELSE                                                              AEXC4     104
         TBI=1.0/DDAT(JE+13)                                            AEXC4     105
         TCTB=DDAT(JE+12)*TBI                                           AEXC4     106
         WS1=CFTF*TBI                                                   AEXC4     107
         A(ISUB3,ISUB2)=TFI*TBI                                         AEXC4     108
         A(ISUB3,ISUB3)=-TBI                                            AEXC4     109
         A(ISUB3,ISUB5)=-C15*WS1                                        AEXC4     110
C                                                                       AEXC4     111
         IF (INPUTR.EQ.0) THEN                                          AEXC4     112
            CALL BCBTEM(ISUB3,TBI)                                      AEXC4     113
         ELSE                                                           AEXC4     114
            A(ISUB3,ISUB1)=-TBI                                         AEXC4     115
         END IF                                                         AEXC4     116
C                                                                       AEXC4     117
         FIELD(3)=-CF*WS1                                               AEXC4     118
C                                                                       AEXC4     119
         IUST(1)=ISUB3                                                  AEXC4     120
         GUST(1)=TBI                                                    AEXC4     121
C                                                                       AEXC4     122
      END IF                                                            AEXC4     123
C                                                                       AEXC4     124
C     TA AND TE BLOCKS                                                  AEXC4     125
C                                                                       AEXC4     126
      TEI=1.0/DDAT(JE+5)                                                AEXC4     127
      IF (IDDAT(JE+3).EQ.0) THEN                                        AEXC4     128
         IF (ICASE.EQ.1) THEN                                           AEXC4     129
            V3=DDAT(JE+12)*XDOT(ISUB3)+XSTATE(JSTATE+3)                 AEXC4     130
            GAIN1=DDAT(JE+2)*DDAT(JE+17)*EFDN*TCTB*TEI                  AEXC4     131
            GAIN2=GAIN1*CFTF                                            AEXC4     132
            GAIN3=DDAT(JE+2)*DDAT(JE+17)*V3*TEI                         AEXC4     133
            A(ISUB5,ISUB2)=TFI*GAIN1                                    AEXC4     134
            A(ISUB5,ISUB3)=GAIN1/TCTB-GAIN1                             AEXC4     135
            A(ISUB5,ISUB5)=-BETA*TEI+C15*(GAIN3-GAIN2)                  AEXC4     136
C                                                                       AEXC4     137
            IF (INPUTR.EQ.0) THEN                                       AEXC4     138
               CALL BCBTEM(ISUB5,GAIN1)                                 AEXC4     139
            ELSE                                                        AEXC4     140
               A(ISUB5,ISUB1)=-GAIN1                                    AEXC4     141
            END IF                                                      AEXC4     142
C                                                                       AEXC4     143
            FIELD(5)=-ALP5*TEI+CF*(GAIN3-GAIN2)                         AEXC4     144
C                                                                       AEXC4     145
            IF (IUST(1).EQ.0) THEN                                      AEXC4     146
               IUST(1)=ISUB5                                            AEXC4     147
               GUST(1)=GAIN1                                            AEXC4     148
            ELSE                                                        AEXC4     149
               IUST(2)=ISUB5                                            AEXC4     150
               GUST(2)=GAIN1                                            AEXC4     151
            END IF                                                      AEXC4     152
C                                                                       AEXC4     153
         ELSE                                                           AEXC4     154
C                                                                       AEXC4     155
C     ICASE=2                                                           AEXC4     156
C                                                                       AEXC4     157
            GAIN1=TEI*DDAT(JE+2)*DDAT(JE+17)*DDAT(JE+25)*               AEXC4     158
     *            (DDAT(JE+26)-2.0*EFDN)                                AEXC4     159
            A(ISUB5,ISUB5)=-BETA*TEI+C15*GAIN1                          AEXC4     160
            FIELD(5)=-ALP5*TEI+CF*GAIN1                                 AEXC4     161
C                                                                       AEXC4     162
         END IF                                                         AEXC4     163
C                                                                       AEXC4     164
      ELSE                                                              AEXC4     165
C                                                                       AEXC4     166
C     TA NOT EQUAL TO ZERO                                              AEXC4     167
C                                                                       AEXC4     168
         TAI=1.0/DDAT(JE+3)                                             AEXC4     169
         IF (ICASE.EQ.1) THEN                                           AEXC4     170
            GAIN1=TCTB*DDAT(JE+2)*TAI                                   AEXC4     171
            GAIN2=GAIN1*CFTF                                            AEXC4     172
            A(ISUB4,ISUB2)=TFI*GAIN1                                    AEXC4     173
            A(ISUB4,ISUB3)=GAIN1/TCTB-GAIN1                             AEXC4     174
            A(ISUB4,ISUB4)=-TAI                                         AEXC4     175
            A(ISUB4,ISUB5)=-C15*GAIN2                                   AEXC4     176
C                                                                       AEXC4     177
            IF (INPUTR.EQ.0) THEN                                       AEXC4     178
               CALL BCBTEM(ISUB4,GAIN1)                                 AEXC4     179
            ELSE                                                        AEXC4     180
               A(ISUB4,ISUB1)=-GAIN1                                    AEXC4     181
            END IF                                                      AEXC4     182
C                                                                       AEXC4     183
            FIELD(4)=-CF*GAIN2                                          AEXC4     184
C                                                                       AEXC4     185
            IF (IUST(1).EQ.0) THEN                                      AEXC4     186
               IUST(1)=ISUB4                                            AEXC4     187
               GUST(1)=GAIN1                                            AEXC4     188
            ELSE                                                        AEXC4     189
               IUST(2)=ISUB4                                            AEXC4     190
               GUST(2)=GAIN1                                            AEXC4     191
            END IF                                                      AEXC4     192
C                                                                       AEXC4     193
         ELSE                                                           AEXC4     194
C                                                                       AEXC4     195
C     ICASE=2                                                           AEXC4     196
C                                                                       AEXC4     197
            GAIN1=DDAT(JE+25)*DDAT(JE+2)*TAI                            AEXC4     198
            A(ISUB4,ISUB4)=-TAI                                         AEXC4     199
            A(ISUB4,ISUB5)=-C15*GAIN1                                   AEXC4     200
C                                                                       AEXC4     201
            FIELD(4)=-CF*GAIN1                                          AEXC4     202
C                                                                       AEXC4     203
         END IF                                                         AEXC4     204
C                                                                       AEXC4     205
C     TE BLOCK FOR NON-ZERO TA                                          AEXC4     206
C                                                                       AEXC4     207
         GAIN1=DDAT(JE+17)*XSTATE(JSTATE+4)                             AEXC4     208
         A(ISUB5,ISUB4)=EFDN*DDAT(JE+17)*TEI                            AEXC4     209
         A(ISUB5,ISUB5)=-TEI*(BETA-C15*GAIN1)                           AEXC4     210
C                                                                       AEXC4     211
         FIELD(5)=-TEI*(ALP5-CF*GAIN1)                                  AEXC4     212
C                                                                       AEXC4     213
      END IF                                                            AEXC4     214
      GOTO 110                                                          AEXC4     215
C                                                                       AEXC4     216
 100  CONTINUE                                                          AEXC4     217
C                                                                       AEXC4     218
C     FOR TYPE AC3A                                                     AEXC4     219
C                                                                       AEXC4     220
C                                                                       AEXC4     221
C     TF BLOCK                                                          AEXC4     222
C                                                                       AEXC4     223
      IF (IDDAT(JE+11).EQ.0) THEN                                       AEXC4     224
         TFI=1.0                                                        AEXC4     225
         CFTF=0.0                                                       AEXC4     226
      ELSE                                                              AEXC4     227
         TFI=1.0/DDAT(JE+11)                                            AEXC4     228
C                                                                       AEXC4     229
C     DETERMINE PROPER GAIN FOR RATE FEEDBACK                           AEXC4     230
C                                                                       AEXC4     231
         IF (EFDN.LE.DDAT(JE+24)) THEN                                  AEXC4     232
            CFTF=DDAT(JE+10)*TFI                                        AEXC4     233
         ELSE                                                           AEXC4     234
            CFTF=DDAT(JE+23)*TFI                                        AEXC4     235
         END IF                                                         AEXC4     236
         A(ISUB2,ISUB2)=-TFI                                            AEXC4     237
         A(ISUB2,ISUB5)=C15*CFTF                                        AEXC4     238
C                                                                       AEXC4     239
         FIELD(2)=CF*CFTF                                               AEXC4     240
C                                                                       AEXC4     241
      END IF                                                            AEXC4     242
C                                                                       AEXC4     243
C     TC, TB BLOCK                                                      AEXC4     244
C                                                                       AEXC4     245
      IF (IDDAT(JE+13).EQ.0) THEN                                       AEXC4     246
         TCTB=1.0                                                       AEXC4     247
      ELSE                                                              AEXC4     248
         TBI=1.0/DDAT(JE+13)                                            AEXC4     249
         TCTB=DDAT(JE+12)*TBI                                           AEXC4     250
         WS1=CFTF*TBI                                                   AEXC4     251
         A(ISUB3,ISUB3)=-TBI                                            AEXC4     252
C                                                                       AEXC4     253
         IF (INPUTR.EQ.0) THEN                                          AEXC4     254
            CALL BCBTEM(ISUB3,TBI)                                      AEXC4     255
         ELSE                                                           AEXC4     256
            A(ISUB3,ISUB1)=-TBI                                         AEXC4     257
         END IF                                                         AEXC4     258
C                                                                       AEXC4     259
         IUST(1)=ISUB3                                                  AEXC4     260
         GUST(1)=TBI                                                    AEXC4     261
C                                                                       AEXC4     262
      END IF                                                            AEXC4     263
C                                                                       AEXC4     264
C     TA AND TE BLOCKS                                                  AEXC4     265
C                                                                       AEXC4     266
      TEI=1.0/DDAT(JE+5)                                                AEXC4     267
      IF (IDDAT(JE+3).EQ.0) THEN                                        AEXC4     268
         IF (ICASE.EQ.1) THEN                                           AEXC4     269
            V2=XDOT(ISUB2)                                              AEXC4     270
            V3=DDAT(JE+12)*XDOT(ISUB3)+XSTATE(JSTATE+3)                 AEXC4     271
            GAIN1=DDAT(JE+2)*DDAT(JE+17)*EFDN*TEI                       AEXC4     272
            GAIN2=GAIN1*CFTF                                            AEXC4     273
            GAIN3=DDAT(JE+2)*DDAT(JE+17)*TEI*(V3-V2)                    AEXC4     274
            A(ISUB5,ISUB2)=TFI*GAIN1                                    AEXC4     275
            A(ISUB5,ISUB3)=GAIN1*(1.0-TCTB)                             AEXC4     276
            A(ISUB5,ISUB5)=-BETA*TEI+C15*(GAIN3-GAIN2)                  AEXC4     277
C                                                                       AEXC4     278
            GAIN1=GAIN1*TCTB                                            AEXC4     279
            IF (INPUTR.EQ.0) THEN                                       AEXC4     280
               CALL BCBTEM(ISUB5,GAIN1)                                 AEXC4     281
            ELSE                                                        AEXC4     282
               A(ISUB5,ISUB1)=-GAIN1                                    AEXC4     283
            END IF                                                      AEXC4     284
C                                                                       AEXC4     285
            FIELD(5)=-ALP5*TEI+CF*(GAIN3-GAIN2)                         AEXC4     286
C                                                                       AEXC4     287
            IF (IUST(1).EQ.0) THEN                                      AEXC4     288
               IUST(1)=ISUB5                                            AEXC4     289
               GUST(1)=GAIN1                                            AEXC4     290
            ELSE                                                        AEXC4     291
               IUST(2)=ISUB5                                            AEXC4     292
               GUST(2)=GAIN1                                            AEXC4     293
            END IF                                                      AEXC4     294
C                                                                       AEXC4     295
         ELSE                                                           AEXC4     296
C                                                                       AEXC4     297
C     ICASE=2                                                           AEXC4     298
C                                                                       AEXC4     299
            V2=XDOT(ISUB2)                                              AEXC4     300
            GAIN1=DDAT(JE+2)*DDAT(JE+17)*TEI                            AEXC4     301
            GAIN2=GAIN1*DDAT(JE+25)*(DDAT(JE+26)-2.0*EFDN)              AEXC4     302
            GAIN3=GAIN1*(EFDN*CFTF+V2)                                  AEXC4     303
            GAIN1=GAIN1*EFDN*TFI                                        AEXC4     304
            A(ISUB5,ISUB2)=GAIN1                                        AEXC4     305
            A(ISUB5,ISUB5)=-BETA*TEI+C15*(GAIN2-GAIN3)                  AEXC4     306
            FIELD(5)=-ALP5*TEI+CF*(GAIN2-GAIN3)                         AEXC4     307
C                                                                       AEXC4     308
         END IF                                                         AEXC4     309
C                                                                       AEXC4     310
      ELSE                                                              AEXC4     311
C                                                                       AEXC4     312
C     TA NOT EQUAL TO ZERO                                              AEXC4     313
C                                                                       AEXC4     314
         TAI=1.0/DDAT(JE+3)                                             AEXC4     315
         CATA=DDAT(JE+2)*TAI                                            AEXC4     316
         IF (ICASE.EQ.1) THEN                                           AEXC4     317
            GAIN1=TCTB*CATA                                             AEXC4     318
            GAIN2=CFTF*CATA*(TCTB+1.0)                                  AEXC4     319
            A(ISUB4,ISUB2)=TFI*CATA*(TCTB+1.0)                          AEXC4     320
            A(ISUB4,ISUB3)=CATA*(1.0-TCTB)                              AEXC4     321
            A(ISUB4,ISUB4)=-TAI                                         AEXC4     322
            A(ISUB4,ISUB5)=-C15*GAIN2                                   AEXC4     323
C                                                                       AEXC4     324
            IF (INPUTR.EQ.0) THEN                                       AEXC4     325
               CALL BCBTEM(ISUB4,GAIN1)                                 AEXC4     326
            ELSE                                                        AEXC4     327
               A(ISUB4,ISUB1)=-GAIN1                                    AEXC4     328
            END IF                                                      AEXC4     329
C                                                                       AEXC4     330
            FIELD(4)=-CF*GAIN2                                          AEXC4     331
C                                                                       AEXC4     332
            IF (IUST(1).EQ.0) THEN                                      AEXC4     333
               IUST(1)=ISUB4                                            AEXC4     334
               GUST(1)=GAIN1                                            AEXC4     335
            ELSE                                                        AEXC4     336
               IUST(2)=ISUB4                                            AEXC4     337
               GUST(2)=GAIN1                                            AEXC4     338
            END IF                                                      AEXC4     339
C                                                                       AEXC4     340
         ELSE                                                           AEXC4     341
C                                                                       AEXC4     342
C     ICASE=2                                                           AEXC4     343
C                                                                       AEXC4     344
            GAIN1=CATA*(DDAT(JE+25)+CFTF)                               AEXC4     345
            A(ISUB4,ISUB2)=CATA*TFI                                     AEXC4     346
            A(ISUB4,ISUB4)=-TAI                                         AEXC4     347
            A(ISUB4,ISUB5)=-C15*GAIN1                                   AEXC4     348
C                                                                       AEXC4     349
            FIELD(4)=-CF*GAIN1                                          AEXC4     350
C                                                                       AEXC4     351
         END IF                                                         AEXC4     352
C                                                                       AEXC4     353
C     TE BLOCK FOR NON-ZERO TA                                          AEXC4     354
C                                                                       AEXC4     355
         GAIN1=DDAT(JE+17)*XSTATE(JSTATE+4)                             AEXC4     356
         A(ISUB5,ISUB4)=EFDN*DDAT(JE+17)*TEI                            AEXC4     357
         A(ISUB5,ISUB5)=-TEI*(BETA-C15*GAIN1)                           AEXC4     358
C                                                                       AEXC4     359
         FIELD(5)=-TEI*(ALP5-CF*GAIN1)                                  AEXC4     360
C                                                                       AEXC4     361
      END IF                                                            AEXC4     362
C                                                                       AEXC4     363
C     ELIMINATE THE FIELD CURRENT TERM IN STATE EQUATION                AEXC4     364
C                                                                       AEXC4     365
 110  DO 20 I=2,5                                                       AEXC4     366
         IF (IFIELD(I).EQ.0) GOTO 20                                    AEXC4     367
         II=ISTATE+I                                                    AEXC4     368
         WS1=XAD*FIELD(I)                                               AEXC4     369
C                                                                       AEXC4     370
         DO 30 J=1,MD+1                                                 AEXC4     371
            A(II,J+1)=WS1*FCTM(J)                                       AEXC4     372
  30     CONTINUE                                                       AEXC4     373
C                                                                       AEXC4     374
         BC(II,1)=BC(II,1)+WS1*FCTM(5)                                  AEXC4     375
         BC(II,2)=BC(II,2)+WS1*FCTM(6)                                  AEXC4     376
C                                                                       AEXC4     377
  20  CONTINUE                                                          AEXC4     378
C                                                                       AEXC4     379
C     INTERCONNECTION WITH GENERATOR (OUTPUT EQUATION)                  AEXC4     380
C                                                                       AEXC4     381
      A(3,ISUB5)=CFEXC*C15                                              AEXC4     382
      CF=CF*CFEXC*XAD                                                   AEXC4     383
      DO 120 I=1,MD+1                                                   AEXC4     384
         A(3,I+1)=A(3,I+1)+CF*FCTM(I)                                   AEXC4     385
 120  CONTINUE                                                          AEXC4     386
      BC(3,1)=BC(3,1)+CF*FCTM(5)                                        AEXC4     387
      BC(3,2)=BC(3,2)+CF*FCTM(6)                                        AEXC4     388
C                                                                       AEXC4     389
      ISTATE=ISUB5                                                      AEXC4     390
C                                                                       AEXC4     391
      RETURN                                                            AEXC4     392
      END                                                               AEXC4     393
