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