CFPRIME DE3N5                                                           DE3N5       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 DE3N5(H)                                               DE3N5       3
CD                                                                      DE3N5       4
CD    TO CALCULATE THE DERIVATIVES OF THE STATES OF TYPES 3 AND 5       DE3N5       5
CD    EXCITER, USED BY BOTH RUNGE-KUTTA AND TRAPEZOIDAL METHOD.         DE3N5       6
CD                                                                      DE3N5       7
CD    THE DATA STRUCTURES FOR THESE TYPES OF EXCITERS ARE GIVEN BELOW.  DE3N5       8
CD                                                                      DE3N5       9
CD   3.2 Exciter type 3                                                 DE3N5      10
CD                                                                      DE3N5      11
CD     Exciter data                                                     DE3N5      12
CD                                                                      DE3N5      13
CD     IDDAT(JE+ 1)   = IVTN         : sensing bus number               DE3N5      14
CD     DDAT(JE+ 2)    = KA                                              DE3N5      15
CD     DDAT(JE+ 3)    = TA                                              DE3N5      16
CD     DDAT(JE+ 4)    = KE                                              DE3N5      17
CD     DDAT(JE+ 5)    = TE                                              DE3N5      18
CD     DDAT(JE+ 6)    = SE(VSAT) or AEX                                 DE3N5      19
CD     DDAT(JE+ 7)    = SE(0.75VSAT) or BEX                             DE3N5      20
CD     DDAT(JE+ 8)    = VSAT                                            DE3N5      21
CD     DDAT(JE+ 9)    = KC                                              DE3N5      22
CD     DDAT(JE+10)    = KF                                              DE3N5      23
CD     DDAT(JE+11)    = TF                                              DE3N5      24
CD     DDAT(JE+12)    = TC                                              DE3N5      25
CD     DDAT(JE+13)    = TB                                              DE3N5      26
CD     DDAT(JE+14)    = VRMAX                                           DE3N5      27
CD     DDAT(JE+15)    = VRMIN                                           DE3N5      28
CD     DDAT(JE+16)    = VEMIN                                           DE3N5      29
CD     DDAT(JE+17)    = TK                                              DE3N5      30
CD     DDAT(JE+18)    = TR                                              DE3N5      31
CD     DDAT(JE+19)    = RC                                              DE3N5      32
CD     DDAT(JE+20)    = XC                                              DE3N5      33
CD     DDAT(JE+21)    = XDE                                             DE3N5      34
CD     DDAT(JE+22)    = X'DE                                            DE3N5      35
CD     DDAT(JE+23)    = TC1                                             DE3N5      36
CD     DDAT(JE+24)    = TB1                                             DE3N5      37
CD     DDAT(JE+25)    = (reserved for future use)                       DE3N5      38
CD     DDAT(JE+26)    = KETL                                            DE3N5      39
CD     DDAT(JE+27)    = TL1                                             DE3N5      40
CD     DDAT(JE+28)    = TL2                                             DE3N5      41
CD     DDAT(JE+29)    = ETLMT                                           DE3N5      42
CD     DDAT(JE+30)    = VOMX                                            DE3N5      43
CD     DDAT(JE+31)    = K21                                             DE3N5      44
CD     DDAT(JE+32)    = K22                                             DE3N5      45
CD                                                                      DE3N5      46
CD     Exciter states                                                   DE3N5      47
CD                                                                      DE3N5      48
CD     XSTATE(JES+1)  = TR block     : compulsory                       DE3N5      49
CD     XSTATE(JES+2)  = K22 block    : compulsory                       DE3N5      50
CD     XSTATE(JES+3)  = TL2 block    : compulsory                       DE3N5      51
CD     XSTATE(JES+4)  = TF block     : compulsory                       DE3N5      52
CD     XSTATE(JES+5)  = TB block     : compulsory                       DE3N5      53
CD     XSTATE(JES+6)  = TA block     : compulsory                       DE3N5      54
CD     XSTATE(JES+7)  = TE block     : compulsory                       DE3N5      55
CD     XSTATE(JES+8)  = TB1 block    : optional                         DE3N5      56
CD                                                                      DE3N5      57
CD     Exciter Y-variables                                              DE3N5      58
CD                                                                      DE3N5      59
CD     VREG(JYE+1)    = VC (input to the TR block)                      DE3N5      60
CD     VREF(JYE+2)    = reference value                                 DE3N5      61
CD                                                                      DE3N5      62
CD   3.4 Exciter type 5                                                 DE3N5      63
CD                                                                      DE3N5      64
CD     Exciter data                                                     DE3N5      65
CD                                                                      DE3N5      66
CD     IDDAT(JE+ 1)   = IVTN         : sensing bus number               DE3N5      67
CD     DDAT(JE+ 2)    = KA                                              DE3N5      68
CD     DDAT(JE+ 3)    = TA                                              DE3N5      69
CD     DDAT(JE+ 4)    = KE                                              DE3N5      70
CD     DDAT(JE+ 5)    = TE                                              DE3N5      71
CD     DDAT(JE+ 6)    = SE(VSAT) or AEX                                 DE3N5      72
CD     DDAT(JE+ 7)    = SE(0.75VSAT) or BEX                             DE3N5      73
CD     DDAT(JE+ 8)    = VSAT                                            DE3N5      74
CD     DDAT(JE+ 9)    = KC                                              DE3N5      75
CD     DDAT(JE+10)    = KF                                              DE3N5      76
CD     DDAT(JE+11)    = TF                                              DE3N5      77
CD     DDAT(JE+12)    = TC                                              DE3N5      78
CD     DDAT(JE+13)    = TB                                              DE3N5      79
CD     DDAT(JE+14)    = VRMAX                                           DE3N5      80
CD     DDAT(JE+15)    = VRMIN                                           DE3N5      81
CD     DDAT(JE+16)    = VEMIN                                           DE3N5      82
CD     DDAT(JE+17)    = T6                                              DE3N5      83
CD     DDAT(JE+18)    = TR                                              DE3N5      84
CD     DDAT(JE+19)    = RC                                              DE3N5      85
CD     DDAT(JE+20)    = XC                                              DE3N5      86
CD     DDAT(JE+21)    = XDE                                             DE3N5      87
CD     DDAT(JE+22)    = X'DE                                            DE3N5      88
CD     DDAT(JE+23)    = TC2                                             DE3N5      89
CD     DDAT(JE+24)    = TB2                                             DE3N5      90
CD     DDAT(JE+25)    = VAMAX                                           DE3N5      91
CD     DDAT(JE+26)    = KETL                                            DE3N5      92
CD     DDAT(JE+27)    = TL1                                             DE3N5      93
CD     DDAT(JE+28)    = TL2                                             DE3N5      94
CD     DDAT(JE+29)    = ETLMT                                           DE3N5      95
CD     DDAT(JE+30)    = VOMX                                            DE3N5      96
CD     DDAT(JE+31)    = K21                                             DE3N5      97
CD     DDAT(JE+32)    = K22                                             DE3N5      98
CD     DDAT(JE+33)    = VAMIN                                           DE3N5      99
CD                                                                      DE3N5     100
CD                                                                      DE3N5     101
CD     Exciter states                                                   DE3N5     102
CD                                                                      DE3N5     103
CD     XSTATE(JES+1)  = TR block     : compulsory                       DE3N5     104
CD     XSTATE(JES+2)  = K22 block    : compulsory                       DE3N5     105
CD     XSTATE(JES+3)  = TL2 block    : compulsory                       DE3N5     106
CD     XSTATE(JES+4)  = TF block     : compulsory                       DE3N5     107
CD     XSTATE(JES+5)  = TB block     : compulsory                       DE3N5     108
CD     XSTATE(JES+6)  = TA block     : compulsory                       DE3N5     109
CD     XSTATE(JES+7)  = TE block     : compulsory                       DE3N5     110
CD     XSTATE(JES+8)  = TB2 block    : optional                         DE3N5     111
CD                                                                      DE3N5     112
CD     Exciter Y-variables                                              DE3N5     113
CD                                                                      DE3N5     114
CD     VREG(JYE+1)    = VC (input to the TR block)                      DE3N5     115
CD     VREF(JYE+2)    = reference value                                 DE3N5     116
CD                                                                      DE3N5     117
      INCLUDE 'PARX.INS'                                                DE3N5     118
      INCLUDE 'CNPT.INS'                                                DE3N5     119
      INCLUDE 'CNVOLT.INS'                                              DE3N5     120
      INCLUDE 'CNIPTR.INS'                                              DE3N5     121
      INCLUDE 'CNMDAT.INS'                                              DE3N5     122
      INCLUDE 'CNB3.INS'                                                DE3N5     123
      INCLUDE 'CNB5.INS'                                                DE3N5     124
      INCLUDE 'CNB8.INS'                                                DE3N5     125
      INCLUDE 'CNB9.INS'                                                DE3N5     126
      INCLUDE 'CNB10.INS'                                               DE3N5     127
      INCLUDE 'CNB19.INS'                                               DE3N5     128
      INCLUDE 'CNEXC.INS'                                               DE3N5     129
      INCLUDE 'CNXSTA.INS'                                              DE3N5     130
      INCLUDE 'CNQSTA.INS'                                              DE3N5     131
      INCLUDE 'CNMYVA.INS'                                              DE3N5     132
      INCLUDE 'CNYVAR.INS'                                              DE3N5     133
      INCLUDE 'CNPRGV.INS'                                              DE3N5     134
      INCLUDE 'CNPREV.INS'                                              DE3N5     135
      INCLUDE 'CNIMPR.INS'                                              DE3N5     136
C                                                                       DE3N5     137
      LOGICAL SLOGIC                                                    DE3N5     138
C                                                                       DE3N5     139
C     DECIDE IF SMALLER TIME STEP SHOULD BE TAKEN                       DE3N5     140
C                                                                       DE3N5     141
      DELT=0.0                                                          DE3N5     142
      IF (IDDAT(JE+35).NE.0) THEN                                       DE3N5     143
         IF (H.LE.DDAT(JE+36)) THEN                                     DE3N5     144
            SLOGIC=.FALSE.                                              DE3N5     145
            KTM=1                                                       DE3N5     146
         ELSE                                                           DE3N5     147
            SLOGIC=.TRUE.                                               DE3N5     148
            KTM=INT(H/DDAT(JE+36)/KSBINT)+1                             DE3N5     149
            DELT=H/KTM/KSBINT                                           DE3N5     150
         END IF                                                         DE3N5     151
      ELSE                                                              DE3N5     152
         SLOGIC=.FALSE.                                                 DE3N5     153
         KTM=1                                                          DE3N5     154
      END IF                                                            DE3N5     155
C                                                                       DE3N5     156
      NXS=7                                                             DE3N5     157
      VRMAX=DDAT(JE+14)                                                 DE3N5     158
      VRMIN=DDAT(JE+15)                                                 DE3N5     159
      VEMIN=DDAT(JE+16)                                                 DE3N5     160
C                                                                       DE3N5     161
C     V/HZ LIMIT                                                        DE3N5     162
C                                                                       DE3N5     163
      VHZ=DDAT(JE+31)*(XSTATE(JSTATE+1)/XSPU-DDAT(JE+34))               DE3N5     164
      IF (VHZ.GT.0.0) THEN                                              DE3N5     165
         VHZ=0.0                                                        DE3N5     166
      ELSE IF (VHZ.LT.-1.0) THEN                                        DE3N5     167
         VHZ=-1.0                                                       DE3N5     168
      END IF                                                            DE3N5     169
      DSTATE(LSTATE+2)=VHZ                                              DE3N5     170
      VHZ=DDAT(JE+32)*XSTATE(JSTATE+2)                                  DE3N5     171
C                                                                       DE3N5     172
C     TERMINAL VOLTAGE LIMITER                                          DE3N5     173
C                                                                       DE3N5     174
      IF (IDDAT(JE+26).EQ.0) THEN                                       DE3N5     175
         V2=0.0                                                         DE3N5     176
         DSTATE(LSTATE+3)=0.0                                           DE3N5     177
      ELSE                                                              DE3N5     178
         XETD=ET-DDAT(JE+29)                                            DE3N5     179
         IF (XETD.LT.0.0) XETD=0.0                                      DE3N5     180
         V2=DDAT(JE+26)*XETD                                            DE3N5     181
         IF (IDDAT(JE+28).NE.0) THEN                                    DE3N5     182
            DSTATE(LSTATE+3)=(V2-XSTATE(JSTATE+3))/DDAT(JE+28)          DE3N5     183
            IF (XSTATE(JSTATE+3).GE.DDAT(JE+30).AND.                    DE3N5     184
     *          DSTATE(LSTATE+3).GT.0.0) THEN                           DE3N5     185
                DSTATE(LSTATE+3)=0.0                                    DE3N5     186
                QSTATE(JSTATE+3)=0.0                                    DE3N5     187
            END IF                                                      DE3N5     188
            V2=XSTATE(JSTATE+3)+DDAT(JE+27)*DSTATE(LSTATE+3)            DE3N5     189
         ELSE                                                           DE3N5     190
            DSTATE(LSTATE+3)=0.0                                        DE3N5     191
            XSTATE(JSTATE+3)=V2                                         DE3N5     192
         END IF                                                         DE3N5     193
         IF (V2.GT.DDAT(JE+30)) V2=DDAT(JE+30)                          DE3N5     194
      END IF                                                            DE3N5     195
C                                                                       DE3N5     196
      DO 500 ITM=1,KTM                                                  DE3N5     197
C                                                                       DE3N5     198
      SEKX=DDAT(JE+4)*XSTATE(JSTATE+7)                                  DE3N5     199
      SEKX=SEKX+DDAT(JE+6)*EXP(DDAT(JE+7)*XSTATE(JSTATE+7))             DE3N5     200
      SEKX=SEKX+CFDN*(DDAT(JE+21)-DDAT(JE+22))                          DE3N5     201
      IF (IEXN.EQ.5) THEN                                               DE3N5     202
         XRATE=SEKX                                                     DE3N5     203
      ELSE                                                              DE3N5     204
         XRATE=EFDN                                                     DE3N5     205
      END IF                                                            DE3N5     206
C                                                                       DE3N5     207
C     RATE FEEDBACK BLOCK                                               DE3N5     208
C                                                                       DE3N5     209
      V4=V2                                                             DE3N5     210
      IF (IDDAT(JE+11).NE.0) THEN                                       DE3N5     211
         DSTATE(LSTATE+4)=(XRATE-XSTATE(JSTATE+4))/DDAT(JE+11)          DE3N5     212
         V4=V4+DSTATE(LSTATE+4)*DDAT(JE+10)                             DE3N5     213
      ELSE                                                              DE3N5     214
         DSTATE(LSTATE+4)=0.0                                           DE3N5     215
         XSTATE(JSTATE+4)=XRATE                                         DE3N5     216
      END IF                                                            DE3N5     217
      VSUM=VREF(JYE+2)-V1-V4+VHZ                                        DE3N5     218
C                                                                       DE3N5     219
      IF (ISTABN.GT.0) VSUM=VSUM+VSS(JYS+1)                             DE3N5     220
      IF (IUALN.NE.0.AND.LVUEL.EQ.1) VSUM=VSUM+VUAL(JYU+1)              DE3N5     221
      IF (ITEBN.NE.0) VSUM=VSUM+TEB(JYTB+1)                             DE3N5     222
      IF (IMXLN.NE.0.AND.LVOEL.EQ.1) VSUM=VSUM-VMXL(JYMX+1)             DE3N5     223
C                                                                       DE3N5     224
C     FIRST LEAD/LAG BLOCK                                              DE3N5     225
C                                                                       DE3N5     226
      IF (IDDAT(JE+13).NE.0) THEN                                       DE3N5     227
         DSTATE(LSTATE+5)=(VSUM-XSTATE(JSTATE+5))/DDAT(JE+13)           DE3N5     228
         V3=XSTATE(JSTATE+5)+DDAT(JE+12)*DSTATE(LSTATE+5)               DE3N5     229
      ELSE                                                              DE3N5     230
         V3=VSUM                                                        DE3N5     231
         DSTATE(LSTATE+5)=0.0                                           DE3N5     232
         XSTATE(JSTATE+5)=V3                                            DE3N5     233
      END IF                                                            DE3N5     234
C                                                                       DE3N5     235
C     AMPILIFIER BLOCK (TA)                                             DE3N5     236
C                                                                       DE3N5     237
      IF (IDDAT(JE+3).NE.0) THEN                                        DE3N5     238
         IF (IDDAT(JE+17).NE.0) THEN                                    DE3N5     239
            RATIO=DDAT(JE+17)/DDAT(JE+3)                                DE3N5     240
            VR=RATIO*DDAT(JE+2)*V3+(1-RATIO)*XSTATE(JSTATE+6)           DE3N5     241
            IF (VR.GT.VRMAX) THEN                                       DE3N5     242
               VR=VRMAX                                                 DE3N5     243
            ELSE IF (VR.LT.VRMIN) THEN                                  DE3N5     244
               VR=VRMIN                                                 DE3N5     245
            END IF                                                      DE3N5     246
            DSTATE(LSTATE+6)=(VR-XSTATE(JSTATE+6))/DDAT(JE+17)          DE3N5     247
         ELSE                                                           DE3N5     248
            DSTATE(LSTATE+6)=(DDAT(JE+2)*V3-XSTATE(JSTATE+6))           DE3N5     249
     *                       /DDAT(JE+3)                                DE3N5     250
            VR=XSTATE(JSTATE+6)                                         DE3N5     251
         END IF                                                         DE3N5     252
      ELSE                                                              DE3N5     253
         VR=DDAT(JE+2)*V3                                               DE3N5     254
         DSTATE(LSTATE+6)=0.0                                           DE3N5     255
         XSTATE(JSTATE+6)=VR                                            DE3N5     256
      END IF                                                            DE3N5     257
C                                                                       DE3N5     258
C     NON-WINDUP LIMIT ON TA BLOCK                                      DE3N5     259
C                                                                       DE3N5     260
      IF (IDDAT(JE+17).EQ.0) THEN                                       DE3N5     261
         IF (VR.GE.VRMAX) THEN                                          DE3N5     262
            VR=VRMAX                                                    DE3N5     263
            IF (DSTATE(LSTATE+6).GT.0.0) THEN                           DE3N5     264
               DSTATE(LSTATE+6)=0.0                                     DE3N5     265
               QSTATE(JSTATE+6)=0.0                                     DE3N5     266
            END IF                                                      DE3N5     267
         ELSE IF (VR.LE.VRMIN) THEN                                     DE3N5     268
            VR=VRMIN                                                    DE3N5     269
            IF (DSTATE(LSTATE+6).LT.0.0) THEN                           DE3N5     270
               DSTATE(LSTATE+6)=0.0                                     DE3N5     271
               QSTATE(JSTATE+6)=0.0                                     DE3N5     272
            END IF                                                      DE3N5     273
         END IF                                                         DE3N5     274
      END IF                                                            DE3N5     275
C                                                                       DE3N5     276
C     SECOND LEAD/LAG BLOCK                                             DE3N5     277
C                                                                       DE3N5     278
      IF (IDDAT(JE+24).NE.0) THEN                                       DE3N5     279
         NXS=8                                                          DE3N5     280
         DSTATE(LSTATE+8)=(VR-XSTATE(JSTATE+8))/DDAT(JE+24)             DE3N5     281
         VINPT=XSTATE(JSTATE+8)+DDAT(JE+23)*DSTATE(LSTATE+8)            DE3N5     282
      ELSE                                                              DE3N5     283
         VINPT=VR                                                       DE3N5     284
      END IF                                                            DE3N5     285
C                                                                       DE3N5     286
C     FOR TYPE 5 EXCITER ONLY.                                          DE3N5     287
C     ALTERNATE VUAL CONNECTION POINT AND WINDUP LIMITER                DE3N5     288
C                                                                       DE3N5     289
      IF (IEXN.EQ.5) THEN                                               DE3N5     290
         IF (IUALN.NE.0.AND.LVUEL.EQ.2) THEN                            DE3N5     291
            IF (VINPT.LT.VUAL(JYU+1)) VINPT=VUAL(JYU+1)                 DE3N5     292
         END IF                                                         DE3N5     293
         IF (IMXLN.NE.0.AND.LVOEL.EQ.2) THEN                            DE3N5     294
            IF (VINPT.GT.VMXL(JYMX+1)) VINPT=VMXL(JYMX+1)               DE3N5     295
         END IF                                                         DE3N5     296
         IF (VINPT.GT.DDAT(JE+25)) THEN                                 DE3N5     297
            VINPT=DDAT(JE+25)                                           DE3N5     298
         ELSE IF (VINPT.LT.DDAT(JE+33)) THEN                            DE3N5     299
            VINPT=DDAT(JE+33)                                           DE3N5     300
         END IF                                                         DE3N5     301
      END IF                                                            DE3N5     302
      VEIN=VINPT-SEKX                                                   DE3N5     303
C                                                                       DE3N5     304
C     TE BLOCK                                                          DE3N5     305
C                                                                       DE3N5     306
      DSTATE(LSTATE+7)=VEIN/DDAT(JE+5)                                  DE3N5     307
C                                                                       DE3N5     308
C     NON-WINDUP LIMIT ON VE                                            DE3N5     309
C                                                                       DE3N5     310
      IF (XSTATE(JSTATE+7).LE.VEMIN) THEN                               DE3N5     311
         IF (DSTATE(LSTATE+7).LT.0.0) THEN                              DE3N5     312
            DSTATE(LSTATE+7)=0.0                                        DE3N5     313
            QSTATE(JSTATE+7)=0.0                                        DE3N5     314
         END IF                                                         DE3N5     315
         VE=VEMIN                                                       DE3N5     316
      ELSE                                                              DE3N5     317
         VE=XSTATE(JSTATE+7)                                            DE3N5     318
      END IF                                                            DE3N5     319
C                                                                       DE3N5     320
C     EULER FORWARD METHOD                                              DE3N5     321
C                                                                       DE3N5     322
      IF (SLOGIC) THEN                                                  DE3N5     323
         DO 310 JX=4,NXS                                                DE3N5     324
            XSTATE(JSTATE+JX)=XSTATE(JSTATE+JX)+DELT*DSTATE(LSTATE+JX)  DE3N5     325
  310    CONTINUE                                                       DE3N5     326
         IF (XSTATE(JSTATE+6).GT.VRMAX) THEN                            DE3N5     327
            XSTATE(JSTATE+6)=VRMAX                                      DE3N5     328
         ELSE IF (XSTATE(JSTATE+6).LT.VRMIN) THEN                       DE3N5     329
            XSTATE(JSTATE+6)=VRMIN                                      DE3N5     330
         END IF                                                         DE3N5     331
         IF (XSTATE(JSTATE+7).LT.VEMIN) THEN                            DE3N5     332
            XSTATE(JSTATE+7)=VEMIN                                      DE3N5     333
         END IF                                                         DE3N5     334
         VE=XSTATE(JSTATE+7)                                            DE3N5     335
         IF (IEXN.EQ.3) THEN                                            DE3N5     336
C                                                                       DE3N5     337
C     ACCOUNT FOR THE RECTIFIER LOADING EFFECT FOR                      DE3N5     338
C     TYPE 3 EXCITER ONLY.                                              DE3N5     339
C                                                                       DE3N5     340
            VTH=VE-CFDN*DDAT(JE+22)                                     DE3N5     341
            EFDN=VTH                                                    DE3N5     342
            IF (IDDAT(JE+9).NE.0) THEN                                  DE3N5     343
               IF (VTH.GT.0.0) THEN                                     DE3N5     344
                  FACT=DDAT(JE+9)*CFDN/VTH                              DE3N5     345
                  IF (FACT.GE.0.75) THEN                                DE3N5     346
                     EFDN=VTH*1.732*(1.0-FACT)                          DE3N5     347
                  ELSE IF (FACT.GE.0.433) THEN                          DE3N5     348
                     EFDN=VTH*SQRT(0.75-FACT*FACT)                      DE3N5     349
                  ELSE                                                  DE3N5     350
                     EFDN=VTH*(1.0-0.577*FACT)                          DE3N5     351
                  END IF                                                DE3N5     352
               END IF                                                   DE3N5     353
            END IF                                                      DE3N5     354
            IF (EFDN.LT.0.0) EFDN=0.0                                   DE3N5     355
         END IF                                                         DE3N5     356
      END IF                                                            DE3N5     357
C                                                                       DE3N5     358
  500 CONTINUE                                                          DE3N5     359
C                                                                       DE3N5     360
C     IF STATES ARE UPDATED BY INNER LOOP, FOOL THE RKG                 DE3N5     361
C                                                                       DE3N5     362
      IF (SLOGIC) THEN                                                  DE3N5     363
         DO 320 JX=4,NXS                                                DE3N5     364
            DSTATE(LSTATE+JX)=0.0                                       DE3N5     365
  320    CONTINUE                                                       DE3N5     366
      END IF                                                            DE3N5     367
C                                                                       DE3N5     368
C     RECTIFIER LOADING EFFECT                                          DE3N5     369
C                                                                       DE3N5     370
      IF (SLOGIC.AND.IEXN.EQ.3) THEN                                    DE3N5     371
         EFD(JYG+4)=EFDN                                                DE3N5     372
      ELSE                                                              DE3N5     373
         VTH=VE-CFDN*DDAT(JE+22)                                        DE3N5     374
         EFD(JYG+4)=VTH                                                 DE3N5     375
         IF (IDDAT(JE+9).NE.0) THEN                                     DE3N5     376
            IF (VTH.GT.0.0) THEN                                        DE3N5     377
               FACT=DDAT(JE+9)*CFDN/VTH                                 DE3N5     378
               IF (FACT.GE.0.75) THEN                                   DE3N5     379
                  EFD(JYG+4)=VTH*1.732*(1.0-FACT)                       DE3N5     380
               ELSE IF (FACT.GE.0.433) THEN                             DE3N5     381
                  EFD(JYG+4)=VTH*SQRT(0.75-FACT*FACT)                   DE3N5     382
               ELSE                                                     DE3N5     383
                  EFD(JYG+4)=VTH*(1.0-0.577*FACT)                       DE3N5     384
               END IF                                                   DE3N5     385
            END IF                                                      DE3N5     386
         END IF                                                         DE3N5     387
         IF (EFD(JYG+4).LT.0.0) EFD(JYG+4)=0.0                          DE3N5     388
      END IF                                                            DE3N5     389
C                                                                       DE3N5     390
C     EXTR VARIABLE FOR TSEC                                            DE3N5     391
C                                                                       DE3N5     392
      XVARB=XSTATE(JSTATE+6)                                            DE3N5     393
      REFMX=0.99*VRMAX                                                  DE3N5     394
C                                                                       DE3N5     395
      LSTATE=LSTATE+NXS                                                 DE3N5     396
C                                                                       DE3N5     397
      RETURN                                                            DE3N5     398
C                                                                       DE3N5     399
      ENTRY DEI3N5(H)                                                   DE3N5     400
CD                                                                      DE3N5     401
CD    TO CALCULATE THE DERIVATIVES OF THE STATES OF TYPES 3 AND         DE3N5     402
CD    5 EXCITER, USED BY TRAPEZOIDAL METHOD.                            DE3N5     403
CD                                                                      DE3N5     404
C                                                                       DE3N5     405
C     DECIDE IF SMALLER TIME STEP SHOULD BE TAKEN                       DE3N5     406
C                                                                       DE3N5     407
      DELT=0.0                                                          DE3N5     408
      IF (IDDAT(JE+35).NE.0) THEN                                       DE3N5     409
         IF (H.LE.DDAT(JE+36)) THEN                                     DE3N5     410
            SLOGIC=.FALSE.                                              DE3N5     411
            KTM=1                                                       DE3N5     412
         ELSE                                                           DE3N5     413
            SLOGIC=.TRUE.                                               DE3N5     414
            KTM=INT(H/DDAT(JE+36))+1                                    DE3N5     415
            DELT=H/KTM                                                  DE3N5     416
            IF (NITER.EQ.0) THEN                                        DE3N5     417
               IWS1=7                                                   DE3N5     418
               IF (IDDAT(JE+24).NE.0) IWS1=8                            DE3N5     419
               DO 90 JX=4,IWS1                                          DE3N5     420
                  XSTATE(JSTATE+JX)=XPREV(1,JSTATE+JX)                  DE3N5     421
   90          CONTINUE                                                 DE3N5     422
            END IF                                                      DE3N5     423
         END IF                                                         DE3N5     424
      ELSE                                                              DE3N5     425
         SLOGIC=.FALSE.                                                 DE3N5     426
         KTM=1                                                          DE3N5     427
      END IF                                                            DE3N5     428
C                                                                       DE3N5     429
      NXS=7                                                             DE3N5     430
C                                                                       DE3N5     431
C     BYPASS IF SUBDIVISION IS ON AND NITER > 0                         DE3N5     432
C                                                                       DE3N5     433
      IF (SLOGIC.AND.NITER.GT.0) THEN                                   DE3N5     434
         IF (IDDAT(JE+24).NE.0) NXS=8                                   DE3N5     435
         VE=XSTATE(JSTATE+7)                                            DE3N5     436
         GOTO 130                                                       DE3N5     437
      END IF                                                            DE3N5     438
C                                                                       DE3N5     439
      VRMAX=DDAT(JE+14)                                                 DE3N5     440
      VRMIN=DDAT(JE+15)                                                 DE3N5     441
      VEMIN=DDAT(JE+16)                                                 DE3N5     442
C                                                                       DE3N5     443
C     V/HZ LIMIT                                                        DE3N5     444
C                                                                       DE3N5     445
      VHZ=DDAT(JE+31)*(XSTATE(JSTATE+1)/XSPU-DDAT(JE+34))               DE3N5     446
      IF (VHZ.GT.0.0) THEN                                              DE3N5     447
         VHZ=0.0                                                        DE3N5     448
      ELSE IF (VHZ.LT.-1.0) THEN                                        DE3N5     449
         VHZ=-1.0                                                       DE3N5     450
      END IF                                                            DE3N5     451
      DSTATE(LSTATE+2)=VHZ                                              DE3N5     452
      VHZ=DDAT(JE+32)*XSTATE(JSTATE+2)                                  DE3N5     453
C                                                                       DE3N5     454
C     TERMINAL VOLTAGE LIMITER                                          DE3N5     455
C                                                                       DE3N5     456
      IF (IDDAT(JE+26).EQ.0) THEN                                       DE3N5     457
         V2=0.0                                                         DE3N5     458
         DSTATE(LSTATE+3)=0.0                                           DE3N5     459
      ELSE                                                              DE3N5     460
         XETD=ET-DDAT(JE+29)                                            DE3N5     461
         IF (XETD.LT.0.0) XETD=0.0                                      DE3N5     462
         V2=DDAT(JE+26)*XETD                                            DE3N5     463
         IF (IDDAT(JE+28).NE.0) THEN                                    DE3N5     464
            DSTATE(LSTATE+3)=(V2-XSTATE(JSTATE+3))/DDAT(JE+28)          DE3N5     465
            IF (XSTATE(JSTATE+3).GE.DDAT(JE+30).AND.                    DE3N5     466
     *          DSTATE(LSTATE+3).GT.0.0) DSTATE(LSTATE+3)=0.0           DE3N5     467
            V2=XSTATE(JSTATE+3)+DDAT(JE+27)*DSTATE(LSTATE+3)            DE3N5     468
         ELSE                                                           DE3N5     469
            DSTATE(LSTATE+3)=0.0                                        DE3N5     470
            XSTATE(JSTATE+3)=V2                                         DE3N5     471
         END IF                                                         DE3N5     472
         IF (V2.GT.DDAT(JE+30)) V2=DDAT(JE+30)                          DE3N5     473
      END IF                                                            DE3N5     474
C                                                                       DE3N5     475
      DO 100 ITM=1,KTM                                                  DE3N5     476
C                                                                       DE3N5     477
      SEKX=DDAT(JE+4)*XSTATE(JSTATE+7)                                  DE3N5     478
      SEKX=SEKX+DDAT(JE+6)*EXP(DDAT(JE+7)*XSTATE(JSTATE+7))             DE3N5     479
      SEKX=SEKX+CFDN*(DDAT(JE+21)-DDAT(JE+22))                          DE3N5     480
      IF (IEXN.EQ.5) THEN                                               DE3N5     481
         XRATE=SEKX                                                     DE3N5     482
      ELSE                                                              DE3N5     483
         XRATE=EFDN                                                     DE3N5     484
      END IF                                                            DE3N5     485
C                                                                       DE3N5     486
C     RATE FEEDBACK BLOCK                                               DE3N5     487
C                                                                       DE3N5     488
      V4=V2                                                             DE3N5     489
      IF (IDDAT(JE+11).NE.0) THEN                                       DE3N5     490
         DSTATE(LSTATE+4)=(XRATE-XSTATE(JSTATE+4))/DDAT(JE+11)          DE3N5     491
         V4=V4+DSTATE(LSTATE+4)*DDAT(JE+10)                             DE3N5     492
      ELSE                                                              DE3N5     493
         DSTATE(LSTATE+4)=0.0                                           DE3N5     494
         XSTATE(JSTATE+4)=XRATE                                         DE3N5     495
      END IF                                                            DE3N5     496
      VSUM=VREF(JYE+2)-V1-V4+VHZ                                        DE3N5     497
C                                                                       DE3N5     498
      IF (ISTABN.GT.0) VSUM=VSUM+VSS(JYS+1)                             DE3N5     499
      IF (IUALN.NE.0.AND.LVUEL.EQ.1) VSUM=VSUM+VUAL(JYU+1)              DE3N5     500
      IF (ITEBN.NE.0) VSUM=VSUM+TEB(JYTB+1)                             DE3N5     501
      IF (IMXLN.NE.0.AND.LVOEL.EQ.1) VSUM=VSUM-VMXL(JYMX+1)             DE3N5     502
C                                                                       DE3N5     503
C     FIRST LEAD/LAG BLOCK                                              DE3N5     504
C                                                                       DE3N5     505
      IF (IDDAT(JE+13).NE.0) THEN                                       DE3N5     506
         DSTATE(LSTATE+5)=(VSUM-XSTATE(JSTATE+5))/DDAT(JE+13)           DE3N5     507
         V3=XSTATE(JSTATE+5)+DDAT(JE+12)*DSTATE(LSTATE+5)               DE3N5     508
      ELSE                                                              DE3N5     509
         V3=VSUM                                                        DE3N5     510
         DSTATE(LSTATE+5)=0.0                                           DE3N5     511
         XSTATE(JSTATE+5)=V3                                            DE3N5     512
      END IF                                                            DE3N5     513
C                                                                       DE3N5     514
C     AMPILIFIER BLOCK (TA)                                             DE3N5     515
C                                                                       DE3N5     516
      IF (IDDAT(JE+3).NE.0) THEN                                        DE3N5     517
         IF (IDDAT(JE+17).NE.0) THEN                                    DE3N5     518
            RATIO=DDAT(JE+17)/DDAT(JE+3)                                DE3N5     519
            VR=RATIO*DDAT(JE+2)*V3+(1-RATIO)*XSTATE(JSTATE+6)           DE3N5     520
            IF (VR.GT.VRMAX) THEN                                       DE3N5     521
               VR=VRMAX                                                 DE3N5     522
            ELSE IF (VR.LT.VRMIN) THEN                                  DE3N5     523
               VR=VRMIN                                                 DE3N5     524
            END IF                                                      DE3N5     525
            DSTATE(LSTATE+6)=(VR-XSTATE(JSTATE+6))/DDAT(JE+17)          DE3N5     526
         ELSE                                                           DE3N5     527
            DSTATE(LSTATE+6)=(DDAT(JE+2)*V3-XSTATE(JSTATE+6))           DE3N5     528
     *                       /DDAT(JE+3)                                DE3N5     529
            VR=XSTATE(JSTATE+6)                                         DE3N5     530
         END IF                                                         DE3N5     531
      ELSE                                                              DE3N5     532
         VR=DDAT(JE+2)*V3                                               DE3N5     533
         DSTATE(LSTATE+6)=0.0                                           DE3N5     534
         XSTATE(JSTATE+6)=VR                                            DE3N5     535
      END IF                                                            DE3N5     536
C                                                                       DE3N5     537
C     NON-WINDUP LIMIT ON TA BLOCK                                      DE3N5     538
C                                                                       DE3N5     539
      IF (IDDAT(JE+17).EQ.0) THEN                                       DE3N5     540
         IF (VR.GE.VRMAX) THEN                                          DE3N5     541
            VR=VRMAX                                                    DE3N5     542
            IF (DSTATE(LSTATE+6).GT.0.0) DSTATE(LSTATE+6)=0.0           DE3N5     543
         ELSE IF (VR.LE.VRMIN) THEN                                     DE3N5     544
            VR=VRMIN                                                    DE3N5     545
            IF (DSTATE(LSTATE+6).LT.0.0) DSTATE(LSTATE+6)=0.0           DE3N5     546
         END IF                                                         DE3N5     547
      END IF                                                            DE3N5     548
C                                                                       DE3N5     549
C     SECOND LEAD/LAG BLOCK                                             DE3N5     550
C                                                                       DE3N5     551
      IF (IDDAT(JE+24).NE.0) THEN                                       DE3N5     552
         NXS=8                                                          DE3N5     553
         DSTATE(LSTATE+8)=(VR-XSTATE(JSTATE+8))/DDAT(JE+24)             DE3N5     554
         VINPT=XSTATE(JSTATE+8)+DDAT(JE+23)*DSTATE(LSTATE+8)            DE3N5     555
      ELSE                                                              DE3N5     556
         VINPT=VR                                                       DE3N5     557
      END IF                                                            DE3N5     558
C                                                                       DE3N5     559
C     FOR TYPE 5 EXCITER ONLY.                                          DE3N5     560
C     ALTERNATE VUAL CONNECTION POINT AND WINDUP LIMITER                DE3N5     561
C                                                                       DE3N5     562
      IF (IEXN.EQ.5) THEN                                               DE3N5     563
         IF (IUALN.NE.0.AND.LVUEL.EQ.2) THEN                            DE3N5     564
            IF (VINPT.LT.VUAL(JYU+1)) VINPT=VUAL(JYU+1)                 DE3N5     565
         END IF                                                         DE3N5     566
         IF (IMXLN.NE.0.AND.LVOEL.EQ.2) THEN                            DE3N5     567
            IF (VINPT.GT.VMXL(JYMX+1)) VINPT=VMXL(JYMX+1)               DE3N5     568
         END IF                                                         DE3N5     569
         IF (VINPT.GT.DDAT(JE+25)) THEN                                 DE3N5     570
            VINPT=DDAT(JE+25)                                           DE3N5     571
         ELSE IF (VINPT.LT.DDAT(JE+33)) THEN                            DE3N5     572
            VINPT=DDAT(JE+33)                                           DE3N5     573
         END IF                                                         DE3N5     574
      END IF                                                            DE3N5     575
      VEIN=VINPT-SEKX                                                   DE3N5     576
C                                                                       DE3N5     577
C     TE BLOCK                                                          DE3N5     578
C                                                                       DE3N5     579
      DSTATE(LSTATE+7)=VEIN/DDAT(JE+5)                                  DE3N5     580
C                                                                       DE3N5     581
C     NON-WINDUP LIMIT ON VE                                            DE3N5     582
C                                                                       DE3N5     583
      IF (XSTATE(JSTATE+7).LE.VEMIN) THEN                               DE3N5     584
         IF (DSTATE(LSTATE+7).LT.0.0) DSTATE(LSTATE+7)=0.0              DE3N5     585
         VE=VEMIN                                                       DE3N5     586
      ELSE                                                              DE3N5     587
         VE=XSTATE(JSTATE+7)                                            DE3N5     588
      END IF                                                            DE3N5     589
C                                                                       DE3N5     590
C     EULER FORWARD METHOD                                              DE3N5     591
C                                                                       DE3N5     592
      IF (SLOGIC) THEN                                                  DE3N5     593
         DO 110 JX=4,NXS                                                DE3N5     594
            XSTATE(JSTATE+JX)=XSTATE(JSTATE+JX)+DELT*DSTATE(LSTATE+JX)  DE3N5     595
  110    CONTINUE                                                       DE3N5     596
         IF (XSTATE(JSTATE+6).GT.VRMAX) THEN                            DE3N5     597
            XSTATE(JSTATE+6)=VRMAX                                      DE3N5     598
         ELSE IF (XSTATE(JSTATE+6).LT.VRMIN) THEN                       DE3N5     599
            XSTATE(JSTATE+6)=VRMIN                                      DE3N5     600
         END IF                                                         DE3N5     601
         IF (XSTATE(JSTATE+7).LT.VEMIN) THEN                            DE3N5     602
            XSTATE(JSTATE+7)=VEMIN                                      DE3N5     603
         END IF                                                         DE3N5     604
         VE=XSTATE(JSTATE+7)                                            DE3N5     605
         IF (IEXN.EQ.3) THEN                                            DE3N5     606
C                                                                       DE3N5     607
C     ACCOUNT FOR THE RECTIFIER LOADING EFFECT FOR                      DE3N5     608
C     TYPE 3 EXCITER ONLY.                                              DE3N5     609
C                                                                       DE3N5     610
            VTH=VE-CFDN*DDAT(JE+22)                                     DE3N5     611
            EFDN=VTH                                                    DE3N5     612
            IF (IDDAT(JE+9).NE.0) THEN                                  DE3N5     613
               IF (VTH.GT.0.0) THEN                                     DE3N5     614
                  FACT=DDAT(JE+9)*CFDN/VTH                              DE3N5     615
                  IF (FACT.GE.0.75) THEN                                DE3N5     616
                     EFDN=VTH*1.732*(1.0-FACT)                          DE3N5     617
                  ELSE IF (FACT.GE.0.433) THEN                          DE3N5     618
                     EFDN=VTH*SQRT(0.75-FACT*FACT)                      DE3N5     619
                  ELSE                                                  DE3N5     620
                     EFDN=VTH*(1.0-0.577*FACT)                          DE3N5     621
                  END IF                                                DE3N5     622
               END IF                                                   DE3N5     623
            END IF                                                      DE3N5     624
            IF (EFDN.LT.0.0) EFDN=0.0                                   DE3N5     625
         END IF                                                         DE3N5     626
      END IF                                                            DE3N5     627
C                                                                       DE3N5     628
  100 CONTINUE                                                          DE3N5     629
C                                                                       DE3N5     630
C     IF STATES ARE UPDATED BY INNER LOOP, FOOL THE RKG                 DE3N5     631
C                                                                       DE3N5     632
  130 IF (SLOGIC) THEN                                                  DE3N5     633
         DO 140 JX=4,NXS                                                DE3N5     634
            DSTATE(LSTATE+JX)=0.0                                       DE3N5     635
  140    CONTINUE                                                       DE3N5     636
      END IF                                                            DE3N5     637
C                                                                       DE3N5     638
C     RECTIFIER LOADING EFFECT                                          DE3N5     639
C                                                                       DE3N5     640
      IF (SLOGIC.AND.IEXN.EQ.3) THEN                                    DE3N5     641
         EFD(JYG+4)=EFDN                                                DE3N5     642
      ELSE                                                              DE3N5     643
         VTH=VE-CFDN*DDAT(JE+22)                                        DE3N5     644
         EFD(JYG+4)=VTH                                                 DE3N5     645
         IF (IDDAT(JE+9).NE.0) THEN                                     DE3N5     646
            IF (VTH.GT.0.0) THEN                                        DE3N5     647
               FACT=DDAT(JE+9)*CFDN/VTH                                 DE3N5     648
               IF (FACT.GE.0.75) THEN                                   DE3N5     649
                  EFD(JYG+4)=VTH*1.732*(1.-FACT)                        DE3N5     650
               ELSE IF (FACT.GE.0.433) THEN                             DE3N5     651
                  EFD(JYG+4)=VTH*SQRT(0.75-FACT*FACT)                   DE3N5     652
               ELSE                                                     DE3N5     653
                  EFD(JYG+4)=VTH*(1.-0.577*FACT)                        DE3N5     654
               END IF                                                   DE3N5     655
            END IF                                                      DE3N5     656
         END IF                                                         DE3N5     657
         IF (EFD(JYG+4).LT.0.0) EFD(JYG+4)=0.0                          DE3N5     658
      END IF                                                            DE3N5     659
C                                                                       DE3N5     660
C     EXTR VARIABLE FOR TSEC                                            DE3N5     661
C                                                                       DE3N5     662
      XVARB=XSTATE(JSTATE+6)                                            DE3N5     663
      REFMX=0.99*VRMAX                                                  DE3N5     664
C                                                                       DE3N5     665
      LSTATE=LSTATE+NXS                                                 DE3N5     666
C                                                                       DE3N5     667
      RETURN                                                            DE3N5     668
      END                                                               DE3N5     669
