CFPRIME AEXC8                                                           AEXC8       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 AEXC8(ISTATE,EPD,EPQ,MD,XAD)                           AEXC8       3
CD                                                                      AEXC8       4
CD    TO FORMULATE THE JACOBIAN MATRICES OF TYPE 8 EXCITER              AEXC8       5
CD    (IEEE TYPE ST3).                                                  AEXC8       6
CD                                                                      AEXC8       7
      INCLUDE 'PARX.INS'                                                AEXC8       8
      INCLUDE 'CNB8.INS'                                                AEXC8       9
      INCLUDE 'CNEXC.INS'                                               AEXC8      10
      INCLUDE 'CNPARX.INS'                                              AEXC8      11
      INCLUDE 'CNMDAT.INS'                                              AEXC8      12
      INCLUDE 'CNXSTA.INS'                                              AEXC8      13
      INCLUDE 'CNMSTA.INS'                                              AEXC8      14
C                                                                       AEXC8      15
      INCLUDE 'CNABAK.INS'                                              AEXC8      16
C                                                                       AEXC8      17
      DIMENSION FIELD(10),IFIELD(10)                                    AEXC8      18
      EQUIVALENCE (FIELD(1),IFIELD(1))                                  AEXC8      19
C                                                                       AEXC8      20
      DO 10 J=2,5                                                       AEXC8      21
         FIELD(J)=0.0                                                   AEXC8      22
  10  CONTINUE                                                          AEXC8      23
C                                                                       AEXC8      24
C     SUBSCRIPTS                                                        AEXC8      25
C                                                                       AEXC8      26
      ISUB1=ISTATE+1                                                    AEXC8      27
      ISUB2=ISTATE+2                                                    AEXC8      28
      ISUB3=ISTATE+3                                                    AEXC8      29
      ISUB4=ISTATE+4                                                    AEXC8      30
      ISUB5=ISTATE+5                                                    AEXC8      31
C                                                                       AEXC8      32
C     CALCULATE EXCITER CONSTANTS                                       AEXC8      33
C                                                                       AEXC8      34
      CPSIN=DDAT(JE+23)*SIN(DDAT(JE+24))                                AEXC8      35
      CPCOS=DDAT(JE+23)*COS(DDAT(JE+24))                                AEXC8      36
      CVR=CPCOS                                                         AEXC8      37
      CVI=CPSIN                                                         AEXC8      38
      CIR=-DDAT(JE+21)*CPSIN                                            AEXC8      39
      CII=DDAT(JE+22)+DDAT(JE+21)*CPCOS                                 AEXC8      40
      VER=CVR*EPD-CVI*EPQ+CIR*CDGN-CII*CQGN                             AEXC8      41
      VEI=CVI*EPD+CVR*EPQ+CII*CDGN+CIR*CQGN                             AEXC8      42
      VE=SQRT(VER*VER+VEI*VEI)                                          AEXC8      43
      IF (VE.EQ.0.0) THEN                                               AEXC8      44
         CIN=0.0                                                        AEXC8      45
      ELSE                                                              AEXC8      46
         CIN=DDAT(JE+9)*CFDN/VE                                         AEXC8      47
      END IF                                                            AEXC8      48
      IF (CIN.LE.0.433) THEN                                            AEXC8      49
         FEX=1.0-0.58*CIN                                               AEXC8      50
         GAMA=-0.58                                                     AEXC8      51
      ELSE IF (CIN.GE.0.75) THEN                                        AEXC8      52
         FEX=1.732-1.732*CIN                                            AEXC8      53
         GAMA=-1.732                                                    AEXC8      54
      ELSE                                                              AEXC8      55
         FEX=SQRT(0.75-CIN*CIN)                                         AEXC8      56
         GAMA=-CIN/FEX                                                  AEXC8      57
      END IF                                                            AEXC8      58
C                                                                       AEXC8      59
      VB=VE*FEX                                                         AEXC8      60
      GAINCR=(FEX-GAMA*CIN)/VE                                          AEXC8      61
      GAINCI=GAINCR*VEI                                                 AEXC8      62
      GAINCR=GAINCR*VER                                                 AEXC8      63
      X5=XSTATE(JSTATE+5)                                               AEXC8      64
      BVB1=X5*(GAINCR*CIR+GAINCI*CII)                                   AEXC8      65
      BVB2=X5*(GAINCI*CIR-GAINCR*CII)                                   AEXC8      66
      BVB3=X5*(GAINCR*CVR+GAINCI*CVI)                                   AEXC8      67
      BVB4=X5*(GAINCI*CVR-GAINCR*CVI)                                   AEXC8      68
      BVB5=X5*GAMA*DDAT(JE+9)                                           AEXC8      69
C                                                                       AEXC8      70
C     TF BLOCK                                                          AEXC8      71
C                                                                       AEXC8      72
      IF (IDDAT(JE+11).EQ.0) THEN                                       AEXC8      73
         CFTF=0.0                                                       AEXC8      74
      ELSE                                                              AEXC8      75
         TFI=1.0/DDAT(JE+11)                                            AEXC8      76
         CFTF=DDAT(JE+10)*TFI                                           AEXC8      77
         A(ISUB2,ISUB2)=-TFI                                            AEXC8      78
         A(ISUB2,ISUB5)=VB*TFI                                          AEXC8      79
C                                                                       AEXC8      80
         BC(ISUB2,1)=TFI*BVB1                                           AEXC8      81
         BC(ISUB2,2)=TFI*BVB2                                           AEXC8      82
         B(ISUB2,1)=TFI*BVB3                                            AEXC8      83
         B(ISUB2,2)=TFI*BVB4                                            AEXC8      84
C                                                                       AEXC8      85
         FIELD(2)=TFI*BVB5                                              AEXC8      86
C                                                                       AEXC8      87
      END IF                                                            AEXC8      88
C                                                                       AEXC8      89
C     TC, TB BLOCK                                                      AEXC8      90
C                                                                       AEXC8      91
      IF (IDDAT(JE+13).EQ.0) THEN                                       AEXC8      92
         TCTB=1.0                                                       AEXC8      93
      ELSE                                                              AEXC8      94
         TBI=1.0/DDAT(JE+13)                                            AEXC8      95
         TCTB=DDAT(JE+12)*TBI                                           AEXC8      96
         WS1=CFTF*TBI                                                   AEXC8      97
         A(ISUB3,ISUB2)=WS1                                             AEXC8      98
         A(ISUB3,ISUB3)=-TBI                                            AEXC8      99
         A(ISUB3,ISUB5)=-VB*WS1                                         AEXC8     100
C                                                                       AEXC8     101
         IF (INPUTR.EQ.0) THEN                                          AEXC8     102
            CALL BCBTEM(ISUB3,TBI)                                      AEXC8     103
         ELSE                                                           AEXC8     104
            A(ISUB3,ISUB1)=-TBI                                         AEXC8     105
         END IF                                                         AEXC8     106
         BC(ISUB3,1)=BC(ISUB3,1)-WS1*BVB1                               AEXC8     107
         BC(ISUB3,2)=BC(ISUB3,2)-WS1*BVB2                               AEXC8     108
         B(ISUB3,1)=B(ISUB3,1)-WS1*BVB3                                 AEXC8     109
         B(ISUB3,2)=B(ISUB3,2)-WS1*BVB4                                 AEXC8     110
C                                                                       AEXC8     111
         FIELD(3)=-WS1*BVB5                                             AEXC8     112
C                                                                       AEXC8     113
         IUST(1)=ISUB3                                                  AEXC8     114
         GUST(1)=TBI                                                    AEXC8     115
C                                                                       AEXC8     116
      END IF                                                            AEXC8     117
C                                                                       AEXC8     118
C     TA AND TM BLOCKS                                                  AEXC8     119
C                                                                       AEXC8     120
      TMI=1.0/DDAT(JE+3)                                                AEXC8     121
      CMTM=DDAT(JE+2)*TMI                                               AEXC8     122
      IF (IDDAT(JE+14).EQ.0) THEN                                       AEXC8     123
C                                                                       AEXC8     124
C     TA EQUAL TO ZERO                                                  AEXC8     125
C     TM BLOCK                                                          AEXC8     126
C                                                                       AEXC8     127
         GAIN1=TCTB*DDAT(JE+4)*CMTM                                     AEXC8     128
         GAIN2=GAIN1*CFTF                                               AEXC8     129
         WS1=GAIN2+CMTM*DDAT(JE+5)                                      AEXC8     130
         A(ISUB5,ISUB2)=GAIN2                                           AEXC8     131
         A(ISUB5,ISUB3)=GAIN1/TCTB-GAIN1                                AEXC8     132
         A(ISUB5,ISUB5)=-TMI-VB*WS1                                     AEXC8     133
C                                                                       AEXC8     134
         IF (INPUTR.EQ.0) THEN                                          AEXC8     135
            CALL BCBTEM(ISUB5,GAIN1)                                    AEXC8     136
         ELSE                                                           AEXC8     137
            A(ISUB5,ISUB1)=-GAIN1                                       AEXC8     138
         END IF                                                         AEXC8     139
         BC(ISUB5,1)=BC(ISUB5,1)-WS1*BVB1                               AEXC8     140
         BC(ISUB5,2)=BC(ISUB5,2)-WS1*BVB2                               AEXC8     141
         B(ISUB5,1)=B(ISUB5,1)-WS1*BVB3                                 AEXC8     142
         B(ISUB5,2)=B(ISUB5,2)-WS1*BVB4                                 AEXC8     143
C                                                                       AEXC8     144
         FIELD(5)=-WS1*BVB5                                             AEXC8     145
C                                                                       AEXC8     146
         IF (IUST(1).EQ.0) THEN                                         AEXC8     147
            IUST(1)=ISUB5                                               AEXC8     148
            GUST(1)=GAIN1                                               AEXC8     149
         ELSE                                                           AEXC8     150
            IUST(2)=ISUB5                                               AEXC8     151
            GUST(2)=GAIN1                                               AEXC8     152
         END IF                                                         AEXC8     153
C                                                                       AEXC8     154
      ELSE                                                              AEXC8     155
C                                                                       AEXC8     156
C     TA NOT EQUAL TO ZERO                                              AEXC8     157
C                                                                       AEXC8     158
         TAI=1.0/DDAT(JE+14)                                            AEXC8     159
         GAIN1=TCTB*DDAT(JE+4)*TAI                                      AEXC8     160
         GAIN2=GAIN1*CFTF                                               AEXC8     161
         A(ISUB4,ISUB2)=GAIN2                                           AEXC8     162
         A(ISUB4,ISUB3)=GAIN1/TCTB-GAIN1                                AEXC8     163
         A(ISUB4,ISUB4)=-TAI                                            AEXC8     164
         A(ISUB4,ISUB5)=-VB*GAIN2                                       AEXC8     165
C                                                                       AEXC8     166
         IF (INPUTR.EQ.0) THEN                                          AEXC8     167
            CALL BCBTEM(ISUB4,GAIN1)                                    AEXC8     168
         ELSE                                                           AEXC8     169
            A(ISUB4,ISUB1)=-GAIN1                                       AEXC8     170
         END IF                                                         AEXC8     171
         BC(ISUB4,1)=BC(ISUB4,1)-GAIN2*BVB1                             AEXC8     172
         BC(ISUB4,2)=BC(ISUB4,2)-GAIN2*BVB2                             AEXC8     173
         B(ISUB4,1)=B(ISUB4,1)-GAIN2*BVB3                               AEXC8     174
         B(ISUB4,2)=B(ISUB4,2)-GAIN2*BVB4                               AEXC8     175
C                                                                       AEXC8     176
         FIELD(4)=-GAIN2*BVB5                                           AEXC8     177
C                                                                       AEXC8     178
         IF (IUST(1).EQ.0) THEN                                         AEXC8     179
            IUST(1)=ISUB4                                               AEXC8     180
            GUST(1)=GAIN1                                               AEXC8     181
         ELSE                                                           AEXC8     182
            IUST(2)=ISUB4                                               AEXC8     183
            GUST(2)=GAIN1                                               AEXC8     184
         END IF                                                         AEXC8     185
C                                                                       AEXC8     186
C     TM BLOCK FOR NON-ZERO TA                                          AEXC8     187
C                                                                       AEXC8     188
         WS1=CMTM*DDAT(JE+5)                                            AEXC8     189
         A(ISUB5,ISUB4)=CMTM                                            AEXC8     190
         A(ISUB5,ISUB5)=-TMI-VB*WS1                                     AEXC8     191
C                                                                       AEXC8     192
         BC(ISUB4,1)=-WS1*BVB1                                          AEXC8     193
         BC(ISUB4,2)=-WS1*BVB2                                          AEXC8     194
         B(ISUB4,1)=-WS1*BVB3                                           AEXC8     195
         B(ISUB4,2)=-WS1*BVB4                                           AEXC8     196
C                                                                       AEXC8     197
         FIELD(5)=-WS1*BVB5                                             AEXC8     198
C                                                                       AEXC8     199
      END IF                                                            AEXC8     200
C                                                                       AEXC8     201
C     ELIMINATE THE FIELD CURRENT TERM IN STATE EQUATION                AEXC8     202
C                                                                       AEXC8     203
      DO 20 I=2,5                                                       AEXC8     204
         IF (IFIELD(I).EQ.0) GOTO 20                                    AEXC8     205
         II=ISTATE+I                                                    AEXC8     206
         WS1=XAD*FIELD(I)                                               AEXC8     207
C                                                                       AEXC8     208
         DO 30 J=1,MD+1                                                 AEXC8     209
            A(II,J+1)=WS1*FCTM(J)                                       AEXC8     210
  30     CONTINUE                                                       AEXC8     211
C                                                                       AEXC8     212
         BC(II,1)=BC(II,1)+WS1*FCTM(5)                                  AEXC8     213
         BC(II,2)=BC(II,2)+WS1*FCTM(6)                                  AEXC8     214
C                                                                       AEXC8     215
  20  CONTINUE                                                          AEXC8     216
C                                                                       AEXC8     217
C     INTERCONNECTION WITH GENERATOR (OUTPUT EQUATION)                  AEXC8     218
C                                                                       AEXC8     219
      A(3,ISUB5)=CFEXC*VB                                               AEXC8     220
      CF=CFEXC*XAD                                                      AEXC8     221
      BVB5=CF*BVB5                                                      AEXC8     222
      DO 120 I=1,MD+1                                                   AEXC8     223
         A(3,I+1)=A(3,I+1)+BVB5*FCTM(I)                                 AEXC8     224
 120  CONTINUE                                                          AEXC8     225
      BC(3,1)=BC(3,1)+BVB5*FCTM(5)+CFEXC*BVB1                           AEXC8     226
      BC(3,2)=BC(3,2)+BVB5*FCTM(6)+CFEXC*BVB2                           AEXC8     227
C                                                                       AEXC8     228
      B(3,1)=B(3,1)+CFEXC*BVB3                                          AEXC8     229
      B(3,2)=B(3,2)+CFEXC*BVB4                                          AEXC8     230
C                                                                       AEXC8     231
      ISTATE=ISUB5                                                      AEXC8     232
C                                                                       AEXC8     233
      RETURN                                                            AEXC8     234
      END                                                               AEXC8     235
