CFPRIME AEXC7                                                           AEXC7       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 AEXC7(ISTATE,EPD,EPQ,MD,XAD)                           AEXC7       3
CD                                                                      AEXC7       4
CD    TO FORMULATE THE JACOBIAN MATRICES OF TYPE 7 EXCITER              AEXC7       5
CD    (IEEE TYPE ST2).                                                  AEXC7       6
CD                                                                      AEXC7       7
      INCLUDE 'PARX.INS'                                                AEXC7       8
      INCLUDE 'CNB8.INS'                                                AEXC7       9
      INCLUDE 'CNEXC.INS'                                               AEXC7      10
      INCLUDE 'CNPARX.INS'                                              AEXC7      11
      INCLUDE 'CNMDAT.INS'                                              AEXC7      12
      INCLUDE 'CNXSTA.INS'                                              AEXC7      13
      INCLUDE 'CNMSTA.INS'                                              AEXC7      14
      INCLUDE 'CNXDOT.INS'                                              AEXC7      15
C                                                                       AEXC7      16
      INCLUDE 'CNABAK.INS'                                              AEXC7      17
C                                                                       AEXC7      18
      DIMENSION FIELD(10),IFIELD(10)                                    AEXC7      19
      EQUIVALENCE (FIELD(1),IFIELD(1))                                  AEXC7      20
C                                                                       AEXC7      21
C     SUBSCRIPTS                                                        AEXC7      22
C                                                                       AEXC7      23
      ISUB1=ISTATE+1                                                    AEXC7      24
      ISUB2=ISTATE+2                                                    AEXC7      25
      ISUB3=ISTATE+3                                                    AEXC7      26
      ISUB4=ISTATE+4                                                    AEXC7      27
      ISUB5=ISTATE+5                                                    AEXC7      28
C                                                                       AEXC7      29
C     CALCULATE COMPENSATION CONSTANTS                                  AEXC7      30
C                                                                       AEXC7      31
      CPP=DDAT(JE+21)                                                   AEXC7      32
      CII=DDAT(JE+22)                                                   AEXC7      33
      VER=CPP*EPD-CII*CQGN                                              AEXC7      34
      VEI=CPP*EPQ+CII*CDGN                                              AEXC7      35
      VE=SQRT(VER*VER+VEI*VEI)                                          AEXC7      36
      IF (VE.EQ.0.0) THEN                                               AEXC7      37
         CIN=0.0                                                        AEXC7      38
      ELSE                                                              AEXC7      39
         CIN=DDAT(JE+9)*CFDN/VE                                         AEXC7      40
      END IF                                                            AEXC7      41
      IF (CIN.LE.0.433) THEN                                            AEXC7      42
         FEX=1.0-0.58*CIN                                               AEXC7      43
         GAMA=-0.58                                                     AEXC7      44
      ELSE IF (CIN.GE.0.75) THEN                                        AEXC7      45
         FEX=1.732-1.732*CIN                                            AEXC7      46
         GAMA=-1.732                                                    AEXC7      47
      ELSE                                                              AEXC7      48
         FEX=SQRT(0.75-CIN*CIN)                                         AEXC7      49
         GAMA=-CIN/FEX                                                  AEXC7      50
      END IF                                                            AEXC7      51
      VB=VE*FEX                                                         AEXC7      52
C                                                                       AEXC7      53
      GAINC=FEX-GAMA*CIN                                                AEXC7      54
C                                                                       AEXC7      55
C     NOTE: TYPES ST2 AND ST2A ARE HANDLED DIFFERENTLY BY THE           AEXC7      56
C           FOLLOWING STATEMENT                                         AEXC7      57
C                                                                       AEXC7      58
      IF (DDAT(JE+6).LT.0.5) GOTO 100                                   AEXC7      59
C                                                                       AEXC7      60
C     FOR TYPE ST2                                                      AEXC7      61
C                                                                       AEXC7      62
C     TF BLOCK                                                          AEXC7      63
C                                                                       AEXC7      64
      IF (IDDAT(JE+11).EQ.0) THEN                                       AEXC7      65
         CFTF=0.0                                                       AEXC7      66
      ELSE                                                              AEXC7      67
         TFI=1.0/DDAT(JE+11)                                            AEXC7      68
         CFTF=DDAT(JE+10)*TFI                                           AEXC7      69
         A(ISUB2,ISUB2)=-TFI                                            AEXC7      70
         A(ISUB2,ISUB5)=TFI                                             AEXC7      71
      END IF                                                            AEXC7      72
C                                                                       AEXC7      73
C     TC, TB BLOCK                                                      AEXC7      74
C                                                                       AEXC7      75
      IF (IDDAT(JE+13).EQ.0) THEN                                       AEXC7      76
         TCTB=1.0                                                       AEXC7      77
      ELSE                                                              AEXC7      78
         TBI=1.0/DDAT(JE+13)                                            AEXC7      79
         TCTB=DDAT(JE+12)*TBI                                           AEXC7      80
         WS1=CFTF*TBI                                                   AEXC7      81
         A(ISUB3,ISUB2)=WS1                                             AEXC7      82
         A(ISUB3,ISUB3)=-TBI                                            AEXC7      83
         A(ISUB3,ISUB5)=-WS1                                            AEXC7      84
C                                                                       AEXC7      85
         IF (INPUTR.EQ.0) THEN                                          AEXC7      86
            CALL BCBTEM(ISUB3,TBI)                                      AEXC7      87
         ELSE                                                           AEXC7      88
            A(ISUB3,ISUB1)=-TBI                                         AEXC7      89
         END IF                                                         AEXC7      90
C                                                                       AEXC7      91
         IUST(1)=ISUB3                                                  AEXC7      92
         GUST(1)=TBI                                                    AEXC7      93
C                                                                       AEXC7      94
      END IF                                                            AEXC7      95
C                                                                       AEXC7      96
C     TA AND TE BLOCKS                                                  AEXC7      97
C                                                                       AEXC7      98
      TEI=1.0/DDAT(JE+5)                                                AEXC7      99
      IF (IDDAT(JE+3).EQ.0) THEN                                        AEXC7     100
C                                                                       AEXC7     101
C     TA EQUAL TO ZERO                                                  AEXC7     102
C     TE BLOCK                                                          AEXC7     103
C                                                                       AEXC7     104
         GAIN1=TCTB*DDAT(JE+2)*TEI                                      AEXC7     105
         GAIN2=GAIN1*CFTF                                               AEXC7     106
         A(ISUB5,ISUB2)=GAIN2                                           AEXC7     107
         A(ISUB5,ISUB3)=DDAT(JE+2)*TEI-GAIN1                            AEXC7     108
         A(ISUB5,ISUB5)=-DDAT(JE+4)*TEI-GAIN2                           AEXC7     109
C                                                                       AEXC7     110
         IF (INPUTR.EQ.0) THEN                                          AEXC7     111
            CALL BCBTEM(ISUB5,GAIN1)                                    AEXC7     112
         ELSE                                                           AEXC7     113
            A(ISUB5,ISUB1)=-GAIN1                                       AEXC7     114
         END IF                                                         AEXC7     115
C                                                                       AEXC7     116
         IF (IUST(1).EQ.0) THEN                                         AEXC7     117
            IUST(1)=5                                                   AEXC7     118
            GUST(1)=GAIN1                                               AEXC7     119
         ELSE                                                           AEXC7     120
            IUST(2)=5                                                   AEXC7     121
            GUST(2)=GAIN1                                               AEXC7     122
         END IF                                                         AEXC7     123
C                                                                       AEXC7     124
      ELSE                                                              AEXC7     125
C                                                                       AEXC7     126
C     TA NOT EQUAL TO ZERO                                              AEXC7     127
C                                                                       AEXC7     128
         TAI=1.0/DDAT(JE+3)                                             AEXC7     129
         GAIN1=TCTB*DDAT(JE+2)*TAI                                      AEXC7     130
         GAIN2=GAIN1*CFTF                                               AEXC7     131
         A(ISUB4,ISUB2)=GAIN2                                           AEXC7     132
         A(ISUB4,ISUB3)=DDAT(JE+2)*TAI-GAIN1                            AEXC7     133
         A(ISUB4,ISUB4)=-TAI                                            AEXC7     134
         A(ISUB4,ISUB5)=-GAIN2                                          AEXC7     135
C                                                                       AEXC7     136
         IF (INPUTR.EQ.0) THEN                                          AEXC7     137
            CALL BCBTEM(ISUB4,GAIN1)                                    AEXC7     138
         ELSE                                                           AEXC7     139
            A(ISUB4,ISUB1)=-GAIN1                                       AEXC7     140
         END IF                                                         AEXC7     141
C                                                                       AEXC7     142
         IF (IUST(1).EQ.0) THEN                                         AEXC7     143
            IUST(1)=ISUB4                                               AEXC7     144
            GUST(1)=GAIN1                                               AEXC7     145
         ELSE                                                           AEXC7     146
            IUST(2)=ISUB4                                               AEXC7     147
            GUST(2)=GAIN1                                               AEXC7     148
         END IF                                                         AEXC7     149
C                                                                       AEXC7     150
C     TE BLOCK FOR NON-ZERO TA                                          AEXC7     151
C                                                                       AEXC7     152
         A(ISUB5,ISUB4)=TEI                                             AEXC7     153
         A(ISUB5,ISUB5)=-DDAT(JE+4)*TEI                                 AEXC7     154
C                                                                       AEXC7     155
      END IF                                                            AEXC7     156
C                                                                       AEXC7     157
C     BVB ARRAY FOR TE BLOCK (SAME IN ANY CASE)                         AEXC7     158
C                                                                       AEXC7     159
      GAINC=GAINC*TEI/VE                                                AEXC7     160
C                                                                       AEXC7     161
      BC(ISUB5,1)=BC(ISUB5,1)+GAINC*CII*VEI                             AEXC7     162
      BC(ISUB5,2)=BC(ISUB5,2)-GAINC*CII*VER                             AEXC7     163
      B(ISUB5,1)=B(ISUB5,1)+GAINC*CPP*VER                               AEXC7     164
      B(ISUB5,2)=B(ISUB5,2)+GAINC*CPP*VEI                               AEXC7     165
C                                                                       AEXC7     166
      FIELD(5)=GAMA*DDAT(JE+9)*TEI                                      AEXC7     167
      GOTO 110                                                          AEXC7     168
C                                                                       AEXC7     169
 100  CONTINUE                                                          AEXC7     170
C                                                                       AEXC7     171
C     FOR TYPE ST2A                                                     AEXC7     172
C                                                                       AEXC7     173
C     TF BLOCK                                                          AEXC7     174
C                                                                       AEXC7     175
      IF (IDDAT(JE+11).EQ.0) THEN                                       AEXC7     176
         CFTF=0.0                                                       AEXC7     177
      ELSE                                                              AEXC7     178
         TFI=1.0/DDAT(JE+11)                                            AEXC7     179
         CFTF=DDAT(JE+10)*TFI                                           AEXC7     180
         A(ISUB2,ISUB2)=-TFI                                            AEXC7     181
         A(ISUB2,ISUB5)=TFI                                             AEXC7     182
      END IF                                                            AEXC7     183
C                                                                       AEXC7     184
C     TC, TB BLOCK                                                      AEXC7     185
C                                                                       AEXC7     186
      IF (IDDAT(JE+13).EQ.0) THEN                                       AEXC7     187
         TCTB=1.0                                                       AEXC7     188
      ELSE                                                              AEXC7     189
         TBI=1.0/DDAT(JE+13)                                            AEXC7     190
         TCTB=DDAT(JE+12)*TBI                                           AEXC7     191
         WS1=CFTF*TBI                                                   AEXC7     192
         A(ISUB3,ISUB2)=WS1                                             AEXC7     193
         A(ISUB3,ISUB3)=-TBI                                            AEXC7     194
         A(ISUB3,ISUB5)=-WS1                                            AEXC7     195
C                                                                       AEXC7     196
         IF (INPUTR.EQ.0) THEN                                          AEXC7     197
            CALL BCBTEM(ISUB3,TBI)                                      AEXC7     198
         ELSE                                                           AEXC7     199
            A(ISUB3,ISUB1)=-TBI                                         AEXC7     200
         END IF                                                         AEXC7     201
C                                                                       AEXC7     202
         IUST(1)=ISUB3                                                  AEXC7     203
         GUST(1)=TBI                                                    AEXC7     204
C                                                                       AEXC7     205
      END IF                                                            AEXC7     206
C                                                                       AEXC7     207
C     TA AND TE BLOCKS                                                  AEXC7     208
C                                                                       AEXC7     209
      TEI=1.0/DDAT(JE+5)                                                AEXC7     210
      IF (IDDAT(JE+3).EQ.0) THEN                                        AEXC7     211
C                                                                       AEXC7     212
C     TA EQUAL TO ZERO                                                  AEXC7     213
C     TE BLOCK                                                          AEXC7     214
C                                                                       AEXC7     215
         GAIN1=TCTB*DDAT(JE+2)*TEI*VB                                   AEXC7     216
         GAIN2=GAIN1*CFTF                                               AEXC7     217
         A(ISUB5,ISUB2)=GAIN2                                           AEXC7     218
         A(ISUB5,ISUB3)=DDAT(JE+2)*TEI*VB-GAIN1                         AEXC7     219
         A(ISUB5,ISUB5)=-DDAT(JE+4)*TEI-GAIN2                           AEXC7     220
C                                                                       AEXC7     221
         IF (INPUTR.EQ.0) THEN                                          AEXC7     222
            CALL BCBTEM(ISUB5,GAIN1)                                    AEXC7     223
         ELSE                                                           AEXC7     224
            A(ISUB5,ISUB1)=-GAIN1                                       AEXC7     225
         END IF                                                         AEXC7     226
C                                                                       AEXC7     227
         IF (IUST(1).EQ.0) THEN                                         AEXC7     228
            IUST(1)=5                                                   AEXC7     229
            GUST(1)=GAIN1                                               AEXC7     230
         ELSE                                                           AEXC7     231
            IUST(2)=5                                                   AEXC7     232
            GUST(2)=GAIN1                                               AEXC7     233
         END IF                                                         AEXC7     234
         X4=DDAT(JE+2)*(DDAT(JE+12)*XDOT(JSTATE+3)+XSTATE(JSTATE+3))    AEXC7     235
C                                                                       AEXC7     236
      ELSE                                                              AEXC7     237
C                                                                       AEXC7     238
C     TA NOT EQUAL TO ZERO                                              AEXC7     239
C                                                                       AEXC7     240
         TAI=1.0/DDAT(JE+3)                                             AEXC7     241
         GAIN1=TCTB*DDAT(JE+2)*TAI                                      AEXC7     242
         GAIN2=GAIN1*CFTF                                               AEXC7     243
         A(ISUB4,ISUB2)=GAIN2                                           AEXC7     244
         A(ISUB4,ISUB3)=DDAT(JE+2)*TAI-GAIN1                            AEXC7     245
         A(ISUB4,ISUB4)=-TAI                                            AEXC7     246
         A(ISUB4,ISUB5)=-GAIN2                                          AEXC7     247
C                                                                       AEXC7     248
         IF (INPUTR.EQ.0) THEN                                          AEXC7     249
            CALL BCBTEM(ISUB4,GAIN1)                                    AEXC7     250
         ELSE                                                           AEXC7     251
            A(ISUB4,ISUB1)=-GAIN1                                       AEXC7     252
         END IF                                                         AEXC7     253
C                                                                       AEXC7     254
         IF (IUST(1).EQ.0) THEN                                         AEXC7     255
            IUST(1)=ISUB4                                               AEXC7     256
            GUST(1)=GAIN1                                               AEXC7     257
         ELSE                                                           AEXC7     258
            IUST(2)=ISUB4                                               AEXC7     259
            GUST(2)=GAIN1                                               AEXC7     260
         END IF                                                         AEXC7     261
C                                                                       AEXC7     262
C     TE BLOCK FOR NON-ZERO TA                                          AEXC7     263
C                                                                       AEXC7     264
         A(ISUB5,ISUB4)=VB*TEI                                          AEXC7     265
         A(ISUB5,ISUB5)=-DDAT(JE+4)*TEI                                 AEXC7     266
         X4=XSTATE(JSTATE+4)                                            AEXC7     267
C                                                                       AEXC7     268
      END IF                                                            AEXC7     269
C                                                                       AEXC7     270
C     BVB ARRAY FOR TE BLOCK (SAME IN ANY CASE)                         AEXC7     271
C                                                                       AEXC7     272
      GAINC=X4*GAINC*TEI/VE                                             AEXC7     273
C                                                                       AEXC7     274
      BC(ISUB5,1)=BC(ISUB5,1)+GAINC*CII*VEI                             AEXC7     275
      BC(ISUB5,2)=BC(ISUB5,2)-GAINC*CII*VER                             AEXC7     276
      B(ISUB5,1)=B(ISUB5,1)+GAINC*CPP*VER                               AEXC7     277
      B(ISUB5,2)=B(ISUB5,2)+GAINC*CPP*VEI                               AEXC7     278
C                                                                       AEXC7     279
      FIELD(5)=X4*GAMA*DDAT(JE+9)*TEI                                   AEXC7     280
C                                                                       AEXC7     281
 110  CONTINUE                                                          AEXC7     282
C                                                                       AEXC7     283
C     ELIMINATE THE FIELD CURRENT TERM IN STATE EQUATION                AEXC7     284
C                                                                       AEXC7     285
      IF (IFIELD(5).NE.0) THEN                                          AEXC7     286
         WS1=XAD*FIELD(5)                                               AEXC7     287
C                                                                       AEXC7     288
         DO 30 J=1,MD+1                                                 AEXC7     289
            A(ISUB5,J+1)=WS1*FCTM(J)                                    AEXC7     290
  30     CONTINUE                                                       AEXC7     291
C                                                                       AEXC7     292
         BC(ISUB5,1)=BC(ISUB5,1)+WS1*FCTM(5)                            AEXC7     293
         BC(ISUB5,2)=BC(ISUB5,2)+WS1*FCTM(6)                            AEXC7     294
C                                                                       AEXC7     295
      END IF                                                            AEXC7     296
C                                                                       AEXC7     297
C     INTERCONNECTION WITH GENERATOR (OUTPUT EQUATION)                  AEXC7     298
C                                                                       AEXC7     299
      A(3,ISUB5)=CFEXC                                                  AEXC7     300
C                                                                       AEXC7     301
      ISTATE=ISUB5                                                      AEXC7     302
C                                                                       AEXC7     303
      RETURN                                                            AEXC7     304
      END                                                               AEXC7     305
