CFPRIME DE34                                                            DE34        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 DE34(H)                                                DE34        3
CD                                                                      DE34        4
CD    TO CALCULATE THE DERIVATIVES OF THE STATES OF TYPE 34 EXCITER,    DE34        5
CD    USED BY BOTH RUNGE-KUTTA AND TRAPEZOIDAL METHOD. SUBDIVISION OF   DE34        6
CD    TIME STEP IS USED IF NECESSARY (ONLY FOR RUNGE-KUTTA METHOD).     DE34        7
CD                                                                      DE34        8
CD    THE DATA STRUCTURE FOR THIS TYPE OF EXCITER IS GIVEN BELOW.       DE34        9
CD                                                                      DE34       10
CD   3.15 Exciter type 34                                               DE34       11
CD                                                                      DE34       12
CD     Exciter data                                                     DE34       13
CD                                                                      DE34       14
CD     IDDAT(JE+ 1)   = IVTN         : sensing bus number               DE34       15
CD     DDAT(JE+ 2)    = KA                                              DE34       16
CD     DDAT(JE+ 3)    = TA                                              DE34       17
CD     DDAT(JE+ 4)    = KF                                              DE34       18
CD     DDAT(JE+ 5)    = TF                                              DE34       19
CD     DDAT(JE+ 6)    = VIMAX                                           DE34       20
CD     DDAT(JE+ 7)    = VIMIN                                           DE34       21
CD     DDAT(JE+ 8)    = TC                                              DE34       22
CD     DDAT(JE+ 9)    = TB                                              DE34       23
CD     DDAT(JE+10)    = TC1                                             DE34       24
CD     DDAT(JE+11)    = TB1                                             DE34       25
CD     DDAT(JE+12)    = VAMAX                                           DE34       26
CD     DDAT(JE+13)    = VAMIN                                           DE34       27
CD     DDAT(JE+14)    = VRMAX                                           DE34       28
CD     DDAT(JE+15)    = VRMIN                                           DE34       29
CD     DDAT(JE+16)    = KC                                              DE34       30
CD     DDAT(JE+17)    = (reserved for future use)                       DE34       31
CD     DDAT(JE+18)    = TR                                              DE34       32
CD     DDAT(JE+19)    = RC                                              DE34       33
CD     DDAT(JE+20)    = XC                                              DE34       34
CD     DDAT(JE+21)    = KLR                                             DE34       35
CD     DDAT(JE+22)    = ILR                                             DE34       36
CD                                                                      DE34       37
CD     Exciter states                                                   DE34       38
CD                                                                      DE34       39
CD     XSTATE(JES+1)  = TR block     : compulsory                       DE34       40
CD     XSTATE(JES+2)  = TA block     : compulsory                       DE34       41
CD     XSTATE(JES+3)  = TF block     : optional                         DE34       42
CD     XSTATE(JES+4)  = TB block     : optional                         DE34       43
CD     XSTATE(JES+5)  = TB1 block    : optional                         DE34       44
CD                                                                      DE34       45
CD     Exciter Y-variables                                              DE34       46
CD                                                                      DE34       47
CD     VREG(JYE+1)    = VC (input to the TR block)                      DE34       48
CD     VREF(JYE+2)    = reference value                                 DE34       49
CD     VRFIN(JYE+3)   = output of the HV gate (exciter EFD)             DE34       50
CD                                                                      DE34       51
      INCLUDE 'PARX.INS'                                                DE34       52
      INCLUDE 'CNPT.INS'                                                DE34       53
      INCLUDE 'CNVOLT.INS'                                              DE34       54
      INCLUDE 'CNIPTR.INS'                                              DE34       55
      INCLUDE 'CNMDAT.INS'                                              DE34       56
      INCLUDE 'CNB3.INS'                                                DE34       57
      INCLUDE 'CNB5.INS'                                                DE34       58
      INCLUDE 'CNB8.INS'                                                DE34       59
      INCLUDE 'CNB9.INS'                                                DE34       60
      INCLUDE 'CNB10.INS'                                               DE34       61
      INCLUDE 'CNB19.INS'                                               DE34       62
      INCLUDE 'CNEXC.INS'                                               DE34       63
      INCLUDE 'CNXSTA.INS'                                              DE34       64
      INCLUDE 'CNQSTA.INS'                                              DE34       65
      INCLUDE 'CNMYVA.INS'                                              DE34       66
      INCLUDE 'CNYVAR.INS'                                              DE34       67
      INCLUDE 'CNFLAG.INS'                                              DE34       68
      INCLUDE 'CNUNIT.INS'                                              DE34       69
      INCLUDE 'CNPREV.INS'                                              DE34       70
      INCLUDE 'CNIMPR.INS'                                              DE34       71
C                                                                       DE34       72
      LOGICAL SLOGIC                                                    DE34       73
C                                                                       DE34       74
      LDEB=.FALSE.                                                      DE34       75
C                                                                       DE34       76
      IF (LIR1.AND.IDDAT(JE+29).EQ.-1) IDDAT(JE+29)=0                   DE34       77
C                                                                       DE34       78
C     DESIGN IF SMALLER TIME STEP SHOULD BE TAKEN                       DE34       79
C                                                                       DE34       80
      DELT=0.0                                                          DE34       81
      IF (IDDAT(JE+24).NE.0) THEN                                       DE34       82
         IF (H.LE.DDAT(JE+25)) THEN                                     DE34       83
            SLOGIC=.FALSE.                                              DE34       84
            KTM=1                                                       DE34       85
         ELSE                                                           DE34       86
            SLOGIC=.TRUE.                                               DE34       87
            KTM=INT(H/DDAT(JE+25)/KSBINT)+1                             DE34       88
            DELT=H/KTM/KSBINT                                           DE34       89
         END IF                                                         DE34       90
      ELSE                                                              DE34       91
         SLOGIC=.FALSE.                                                 DE34       92
         KTM=1                                                          DE34       93
      END IF                                                            DE34       94
C                                                                       DE34       95
C     FIELD CURRENT LIMITER                                             DE34       96
C                                                                       DE34       97
      IF (IDDAT(JE+21).EQ.0.OR.IDDAT(JE+22).EQ.0) THEN                  DE34       98
         V6=0.0                                                         DE34       99
      ELSE                                                              DE34      100
         IF (DDAT(JE+22).GT.CFDN) THEN                                  DE34      101
            V6=0.0                                                      DE34      102
            IF (IDDAT(JE+29).EQ.1) IDDAT(JE+29)=-1                      DE34      103
         ELSE                                                           DE34      104
            IF (IDDAT(JE+29).EQ.-1) THEN                                DE34      105
               V6=0.0                                                   DE34      106
            ELSE                                                        DE34      107
               V6=DDAT(JE+21)*(CFDN-DDAT(JE+22))                        DE34      108
               IF (IDDAT(JE+29).EQ.0) IDDAT(JE+29)=1                    DE34      109
            END IF                                                      DE34      110
         END IF                                                         DE34      111
      END IF                                                            DE34      112
C                                                                       DE34      113
      NXS=2                                                             DE34      114
      VRMAX=DDAT(JE+12)                                                 DE34      115
      VRMIN=DDAT(JE+13)                                                 DE34      116
C                                                                       DE34      117
      KX1=NXS+1                                                         DE34      118
C                                                                       DE34      119
      DO 500 ITM=1,KTM                                                  DE34      120
      NXS=KX1-1                                                         DE34      121
C                                                                       DE34      122
C     RATE FEEDBACK BLOCK                                               DE34      123
C                                                                       DE34      124
      XRATE=VRFIN(JYE+3)                                                DE34      125
C                                                                       DE34      126
      IF (IDDAT(JE+5).NE.0) THEN                                        DE34      127
         NXS=NXS+1                                                      DE34      128
         DSTATE(LSTATE+NXS)=(XRATE-XSTATE(JSTATE+NXS))/DDAT(JE+5)       DE34      129
         V2=DSTATE(LSTATE+NXS)*DDAT(JE+4)                               DE34      130
      ELSE                                                              DE34      131
         V2=0.0                                                         DE34      132
      END IF                                                            DE34      133
C                                                                       DE34      134
      VSUM=VREF(JYE+2)-V1-V2                                            DE34      135
      IF (ISTABN.GT.0.AND.LVS.EQ.1) VSUM=VSUM+VSS(JYS+1)                DE34      136
      IF (IUALN.NE.0.AND.LVUEL.EQ.1) VSUM=VSUM+VUAL(JYU+1)              DE34      137
      IF (ITEBN.NE.0) VSUM=VSUM+TEB(JYTB+1)                             DE34      138
      IF (IMXLN.NE.0.AND.LVOEL.EQ.1) VSUM=VSUM-VMXL(JYMX+1)             DE34      139
C                                                                       DE34      140
      IF (VSUM.GT.DDAT(JE+6)) THEN                                      DE34      141
         VSUM=DDAT(JE+6)                                                DE34      142
      ELSE IF (VSUM.LT.DDAT(JE+7)) THEN                                 DE34      143
         VSUM=DDAT(JE+7)                                                DE34      144
      END IF                                                            DE34      145
C                                                                       DE34      146
C     ALTERNATE VUEL CONNECTION POINT                                   DE34      147
C                                                                       DE34      148
      IF (IUALN.NE.0.AND.LVUEL.EQ.2) THEN                               DE34      149
         IF (VSUM.LT.VUAL(JYU+1)) VSUM=VUAL(JYU+1)                      DE34      150
      END IF                                                            DE34      151
C                                                                       DE34      152
C     LEAD/LAG BLOCKS                                                   DE34      153
C                                                                       DE34      154
      IF (IDDAT(JE+9).NE.0) THEN                                        DE34      155
         NXS=NXS+1                                                      DE34      156
         RATIO=DDAT(JE+8)/DDAT(JE+9)                                    DE34      157
         DSTATE(LSTATE+NXS)=(VSUM-XSTATE(JSTATE+NXS))/DDAT(JE+9)        DE34      158
         V3=VSUM*RATIO+XSTATE(JSTATE+NXS)*(1.0-RATIO)                   DE34      159
      ELSE                                                              DE34      160
         V3=VSUM                                                        DE34      161
      END IF                                                            DE34      162
C                                                                       DE34      163
      IF (IDDAT(JE+11).NE.0) THEN                                       DE34      164
         NXS=NXS+1                                                      DE34      165
         DSTATE(LSTATE+NXS)=(V3-XSTATE(JSTATE+NXS))/DDAT(JE+11)         DE34      166
         V4=XSTATE(JSTATE+NXS)+DDAT(JE+10)*DSTATE(LSTATE+NXS)           DE34      167
      ELSE                                                              DE34      168
         V4=V3                                                          DE34      169
      END IF                                                            DE34      170
C                                                                       DE34      171
C     AMPILIFIER BLOCK                                                  DE34      172
C                                                                       DE34      173
      IF (IDDAT(JE+3).NE.0) THEN                                        DE34      174
         DSTATE(LSTATE+2)=(DDAT(JE+2)*V4-XSTATE(JSTATE+2))/DDAT(JE+3)   DE34      175
         VR=XSTATE(JSTATE+2)                                            DE34      176
      ELSE                                                              DE34      177
         VR=DDAT(JE+2)*V4                                               DE34      178
         DSTATE(LSTATE+2)=0.                                            DE34      179
         XSTATE(JSTATE+2)=VR                                            DE34      180
      END IF                                                            DE34      181
C                                                                       DE34      182
C     NON-WINDUP LIMITS ON STATE #2                                     DE34      183
C                                                                       DE34      184
      IF (VR.GE.VRMAX) THEN                                             DE34      185
         VR=VRMAX                                                       DE34      186
         IF (DSTATE(LSTATE+2).GT.0.0) THEN                              DE34      187
            DSTATE(LSTATE+2)=0.0                                        DE34      188
            QSTATE(JSTATE+2)=0.0                                        DE34      189
         END IF                                                         DE34      190
      ELSE IF (VR.LE.VRMIN) THEN                                        DE34      191
         VR=VRMIN                                                       DE34      192
         IF (DSTATE(LSTATE+2).LT.0.0) THEN                              DE34      193
            DSTATE(LSTATE+2)=0.0                                        DE34      194
            QSTATE(JSTATE+2)=0.0                                        DE34      195
         END IF                                                         DE34      196
      END IF                                                            DE34      197
C                                                                       DE34      198
C     SUMMIMG JUNCTION WITH FIELD CURRENT LIMITER AND/OR                DE34      199
C     ALTERNATE VS CONNECTION POINT                                     DE34      200
C                                                                       DE34      201
      VE=VR-V6                                                          DE34      202
      IF (ISTABN.GT.0.AND.LVS.EQ.2) VE=VE+VSS(JYS+1)                    DE34      203
C                                                                       DE34      204
C     ALTERNATE VUEL AND/OR VOEL CONNECTION POINT                       DE34      205
C                                                                       DE34      206
      IF (IUALN.NE.0.AND.LVUEL.EQ.3) THEN                               DE34      207
         IF (VE.LT.VUAL(JYU+1)) VE=VUAL(JYU+1)                          DE34      208
      END IF                                                            DE34      209
      IF (IMXLN.NE.0.AND.LVOEL.EQ.2) THEN                               DE34      210
         IF (VE.GT.VMXL(JYMX+1)) VE=VMXL(JYMX+1)                        DE34      211
      END IF                                                            DE34      212
C                                                                       DE34      213
      VRFIN(JYE+3)=VE                                                   DE34      214
C                                                                       DE34      215
C     EULER FORWARD METHOD                                              DE34      216
C                                                                       DE34      217
      KX2=NXS                                                           DE34      218
      IF (SLOGIC) THEN                                                  DE34      219
         DO 310 JX=KX1,KX2                                              DE34      220
            XSTATE(JSTATE+JX)=XSTATE(JSTATE+JX)+DELT*DSTATE(LSTATE+JX)  DE34      221
  310    CONTINUE                                                       DE34      222
         IF (XSTATE(JSTATE+2).GT.VRMAX) THEN                            DE34      223
            XSTATE(JSTATE+2)=VRMAX                                      DE34      224
         ELSE IF (XSTATE(JSTATE+2).LT.VRMIN) THEN                       DE34      225
            XSTATE(JSTATE+2)=VRMIN                                      DE34      226
         END IF                                                         DE34      227
         IF (IDDAT(JE+3).NE.0) THEN                                     DE34      228
            VRFIN(JYE+3)=XSTATE(JSTATE+2)                               DE34      229
         ELSE IF(IDDAT(JE+9).NE.0) THEN                                 DE34      230
            VRFIN(JYE+3)=(XSTATE(JSTATE+KX2)+DSTATE(LSTATE+KX2)         DE34      231
     +                   *DDAT(JE+8))*DDAT(JE+2)                        DE34      232
         ELSE IF (IDDAT(JE+11).NE.0) THEN                               DE34      233
            VRFIN(JYE+3)=(XSTATE(JSTATE+KX2)+DSTATE(LSTATE+KX2)         DE34      234
     +                   *DDAT(JE+10))*DDAT(JE+2)                       DE34      235
         ELSE                                                           DE34      236
            VRFIN(JYE+3)=VSUM*DDAT(JE+2)                                DE34      237
         END IF                                                         DE34      238
         VRFIN(JYE+3)=VRFIN(JYE+3)-V6                                   DE34      239
         IF (IUALN.NE.0.AND.LVUEL.EQ.2) THEN                            DE34      240
            IF (VRFIN(JYE+3).LT.VUAL(JYU+1)) VRFIN(JYE+3)=VUAL(JYU+1)   DE34      241
         END IF                                                         DE34      242
      END IF                                                            DE34      243
C                                                                       DE34      244
  500 CONTINUE                                                          DE34      245
C                                                                       DE34      246
C     IF STATES WERE UPDATED BY INNER LOOP, FOOL THE RKG                DE34      247
C                                                                       DE34      248
      IF (SLOGIC) THEN                                                  DE34      249
         DO 320 JX=2,NXS                                                DE34      250
            DSTATE(LSTATE+JX)=0.0                                       DE34      251
  320    CONTINUE                                                       DE34      252
      END IF                                                            DE34      253
C                                                                       DE34      254
C     LIMITS ON EFD                                                     DE34      255
C                                                                       DE34      256
      VEMAX=DDAT(JE+14)*ET-DDAT(JE+16)*CFDN                             DE34      257
      VEMIN=DDAT(JE+15)*ET                                              DE34      258
      IF (VE.GE.VEMAX) THEN                                             DE34      259
         VE=VEMAX                                                       DE34      260
      ELSE IF (VE.LE.VEMIN) THEN                                        DE34      261
         VE=VEMIN                                                       DE34      262
      END IF                                                            DE34      263
C                                                                       DE34      264
      EFD(JYG+4)=VE                                                     DE34      265
C                                                                       DE34      266
      LSTATE=LSTATE+NXS                                                 DE34      267
C                                                                       DE34      268
      RETURN                                                            DE34      269
C                                                                       DE34      270
      ENTRY DEI34(H)                                                    DE34      271
CD                                                                      DE34      272
CD    TO CALCULATE THE DERIVATIVES OF THE STATES OF TYPE 34 EXCITER,    DE34      273
CD    USED BY TRAPEZOIDAL METHOD.                                       DE34      274
CD                                                                      DE34      275
      NXS=2                                                             DE34      276
      IF (IDDAT(JE+5).NE.0) NXS=NXS+1                                   DE34      277
      IF (IDDAT(JE+9).NE.0) NXS=NXS+1                                   DE34      278
      IF (IDDAT(JE+11).NE.0) NXS=NXS+1                                  DE34      279
C                                                                       DE34      280
C     DESIGN IF SMALLER TIME STEP SHOULD BE TAKEN                       DE34      281
C                                                                       DE34      282
      DELT=0.0                                                          DE34      283
      IF (IDDAT(JE+24).NE.0) THEN                                       DE34      284
         IF (H.LE.DDAT(JE+25)) THEN                                     DE34      285
            SLOGIC=.FALSE.                                              DE34      286
            KTM=1                                                       DE34      287
         ELSE                                                           DE34      288
            SLOGIC=.TRUE.                                               DE34      289
            KTM=INT(H/DDAT(JE+25))+1                                    DE34      290
            DELT=H/KTM                                                  DE34      291
            IF (NITER.EQ.0) THEN                                        DE34      292
               DO 90 JX=2,NXS                                           DE34      293
                  XSTATE(JSTATE+JX)=XPREV(1,JSTATE+JX)                  DE34      294
   90          CONTINUE                                                 DE34      295
            END IF                                                      DE34      296
         END IF                                                         DE34      297
      ELSE                                                              DE34      298
         SLOGIC=.FALSE.                                                 DE34      299
         KTM=1                                                          DE34      300
      END IF                                                            DE34      301
C                                                                       DE34      302
C     BYPASS IF SUBDIVISION IS ON AND NITER > 0                         DE34      303
C                                                                       DE34      304
      IF (SLOGIC.AND.NITER.GT.0) GOTO 130                               DE34      305
C                                                                       DE34      306
C     FIELD CURRENT LIMITER                                             DE34      307
C                                                                       DE34      308
      IF (IDDAT(JE+21).EQ.0.OR.IDDAT(JE+22).EQ.0) THEN                  DE34      309
         V6=0.0                                                         DE34      310
      ELSE                                                              DE34      311
         IF (DDAT(JE+22).GT.CFDN) THEN                                  DE34      312
            V6=0.0                                                      DE34      313
            IF (IDDAT(JE+29).EQ.1) IDDAT(JE+29)=-1                      DE34      314
         ELSE                                                           DE34      315
            IF (IDDAT(JE+29).EQ.-1) THEN                                DE34      316
               V6=0.0                                                   DE34      317
            ELSE                                                        DE34      318
               V6=DDAT(JE+21)*(CFDN-DDAT(JE+22))                        DE34      319
               IF (IDDAT(JE+29).EQ.0) IDDAT(JE+29)=1                    DE34      320
            END IF                                                      DE34      321
         END IF                                                         DE34      322
      END IF                                                            DE34      323
C                                                                       DE34      324
      NXS=2                                                             DE34      325
      VRMAX=DDAT(JE+12)                                                 DE34      326
      VRMIN=DDAT(JE+13)                                                 DE34      327
C                                                                       DE34      328
      KX1=NXS+1                                                         DE34      329
C                                                                       DE34      330
      DO 100 ITM=1,KTM                                                  DE34      331
      NXS=KX1-1                                                         DE34      332
C                                                                       DE34      333
C     RATE FEEDBACK BLOCK                                               DE34      334
C                                                                       DE34      335
      XRATE=VRFIN(JYE+3)                                                DE34      336
C                                                                       DE34      337
      IF (IDDAT(JE+5).NE.0) THEN                                        DE34      338
         NXS=NXS+1                                                      DE34      339
         DSTATE(LSTATE+NXS)=(XRATE-XSTATE(JSTATE+NXS))/DDAT(JE+5)       DE34      340
         V2=DSTATE(LSTATE+NXS)*DDAT(JE+4)                               DE34      341
      ELSE                                                              DE34      342
         V2=0.0                                                         DE34      343
      END IF                                                            DE34      344
C                                                                       DE34      345
      VSUM=VREF(JYE+2)-V1-V2                                            DE34      346
      IF (ISTABN.GT.0) VSUM=VSUM+VSS(JYS+1)                             DE34      347
      IF (IUALN.NE.0.AND.LVUEL.EQ.1) VSUM=VSUM+VUAL(JYU+1)              DE34      348
      IF (ITEBN.NE.0) VSUM=VSUM+TEB(JYTB+1)                             DE34      349
      IF (IMXLN.NE.0.AND.LVOEL.EQ.1) VSUM=VSUM-VMXL(JYMX+1)             DE34      350
C                                                                       DE34      351
      IF (VSUM.GT.DDAT(JE+6)) THEN                                      DE34      352
         VSUM=DDAT(JE+6)                                                DE34      353
      ELSE IF (VSUM.LT.DDAT(JE+7)) THEN                                 DE34      354
         VSUM=DDAT(JE+7)                                                DE34      355
      END IF                                                            DE34      356
C                                                                       DE34      357
C     ALTERNATE VUEL CONNECTION POINT                                   DE34      358
C                                                                       DE34      359
      IF (IUALN.NE.0.AND.LVUEL.EQ.2) THEN                               DE34      360
         IF (VSUM.LT.VUAL(JYU+1)) VSUM=VUAL(JYU+1)                      DE34      361
      END IF                                                            DE34      362
C                                                                       DE34      363
C     LEAD/LAG BLOCKS                                                   DE34      364
C                                                                       DE34      365
      IF (IDDAT(JE+9).NE.0) THEN                                        DE34      366
         NXS=NXS+1                                                      DE34      367
         RATIO=DDAT(JE+8)/DDAT(JE+9)                                    DE34      368
         DSTATE(LSTATE+NXS)=(VSUM-XSTATE(JSTATE+NXS))/DDAT(JE+9)        DE34      369
         V3=VSUM*RATIO+XSTATE(JSTATE+NXS)*(1.0-RATIO)                   DE34      370
      ELSE                                                              DE34      371
         V3=VSUM                                                        DE34      372
      END IF                                                            DE34      373
C                                                                       DE34      374
      IF (IDDAT(JE+11).NE.0) THEN                                       DE34      375
         NXS=NXS+1                                                      DE34      376
         DSTATE(LSTATE+NXS)=(V3-XSTATE(JSTATE+NXS))/DDAT(JE+11)         DE34      377
         V4=XSTATE(JSTATE+NXS)+DDAT(JE+10)*DSTATE(LSTATE+NXS)           DE34      378
      ELSE                                                              DE34      379
         V4=V3                                                          DE34      380
      END IF                                                            DE34      381
C                                                                       DE34      382
C     AMPILIFIER BLOCK                                                  DE34      383
C                                                                       DE34      384
      IF (IDDAT(JE+3).NE.0) THEN                                        DE34      385
         DSTATE(LSTATE+2)=(DDAT(JE+2)*V4-XSTATE(JSTATE+2))/DDAT(JE+3)   DE34      386
         VR=XSTATE(JSTATE+2)                                            DE34      387
      ELSE                                                              DE34      388
         VR=DDAT(JE+2)*V4                                               DE34      389
         DSTATE(LSTATE+2)=0.                                            DE34      390
         XSTATE(JSTATE+2)=VR                                            DE34      391
      END IF                                                            DE34      392
C                                                                       DE34      393
C     NON-WINDUP LIMITS ON STATE #2                                     DE34      394
C                                                                       DE34      395
      IF (VR.GE.VRMAX) THEN                                             DE34      396
         VR=VRMAX                                                       DE34      397
         IF (DSTATE(LSTATE+2).GT.0.0) DSTATE(LSTATE+2)=0.0              DE34      398
      ELSE IF (VR.LE.VRMIN) THEN                                        DE34      399
         VR=VRMIN                                                       DE34      400
         IF (DSTATE(LSTATE+2).LT.0.0) DSTATE(LSTATE+2)=0.0              DE34      401
      END IF                                                            DE34      402
C                                                                       DE34      403
C     SUMMIMG JUNCTION WITH FIELD CURRENT LIMITER AND/OR                DE34      404
C     ALTERNATE VS CONNECTION POINT                                     DE34      405
C                                                                       DE34      406
      VE=VR-V6                                                          DE34      407
      IF (ISTABN.GT.0.AND.LVS.EQ.2) VE=VE+VSS(JYS+1)                    DE34      408
C                                                                       DE34      409
C     ALTERNATE VUEL AND/OR VOEL CONNECTION POINT                       DE34      410
C                                                                       DE34      411
      IF (IUALN.NE.0.AND.LVUEL.EQ.3) THEN                               DE34      412
         IF (VE.LT.VUAL(JYU+1)) VE=VUAL(JYU+1)                          DE34      413
      END IF                                                            DE34      414
      IF (IMXLN.NE.0.AND.LVOEL.EQ.2) THEN                               DE34      415
         IF (VE.GT.VMXL(JYMX+1)) VE=VMXL(JYMX+1)                        DE34      416
      END IF                                                            DE34      417
C                                                                       DE34      418
      VRFIN(JYE+3)=VE                                                   DE34      419
C                                                                       DE34      420
C     EULER FORWARD METHOD                                              DE34      421
C                                                                       DE34      422
      KX2=NXS                                                           DE34      423
      IF (SLOGIC) THEN                                                  DE34      424
         DO 110 JX=KX1,KX2                                              DE34      425
            XSTATE(JSTATE+JX)=XSTATE(JSTATE+JX)+DELT*DSTATE(LSTATE+JX)  DE34      426
  110    CONTINUE                                                       DE34      427
         IF (XSTATE(JSTATE+2).GT.VRMAX) THEN                            DE34      428
            XSTATE(JSTATE+2)=VRMAX                                      DE34      429
         ELSE IF (XSTATE(JSTATE+2).LT.VRMIN) THEN                       DE34      430
            XSTATE(JSTATE+2)=VRMIN                                      DE34      431
         END IF                                                         DE34      432
         IF (IDDAT(JE+3).NE.0) THEN                                     DE34      433
            VRFIN(JYE+3)=XSTATE(JSTATE+2)                               DE34      434
         ELSE IF(IDDAT(JE+9).NE.0) THEN                                 DE34      435
            VRFIN(JYE+3)=(XSTATE(JSTATE+KX2)+DSTATE(LSTATE+KX2)         DE34      436
     +                   *DDAT(JE+8))*DDAT(JE+2)                        DE34      437
         ELSE IF (IDDAT(JE+11).NE.0) THEN                               DE34      438
            VRFIN(JYE+3)=(XSTATE(JSTATE+KX2)+DSTATE(LSTATE+KX2)         DE34      439
     +                   *DDAT(JE+10))*DDAT(JE+2)                       DE34      440
         ELSE                                                           DE34      441
            VRFIN(JYE+3)=VSUM*DDAT(JE+2)                                DE34      442
         END IF                                                         DE34      443
         VRFIN(JYE+3)=VRFIN(JYE+3)-V6                                   DE34      444
         IF (IUALN.NE.0.AND.LVUEL.EQ.2) THEN                            DE34      445
            IF (VRFIN(JYE+3).LT.VUAL(JYU+1)) VRFIN(JYE+3)=VUAL(JYU+1)   DE34      446
         END IF                                                         DE34      447
      END IF                                                            DE34      448
C                                                                       DE34      449
  100 CONTINUE                                                          DE34      450
C                                                                       DE34      451
C     LIMITS ON EFD                                                     DE34      452
C                                                                       DE34      453
      VEMAX=DDAT(JE+14)*ET-DDAT(JE+16)*CFDN                             DE34      454
      VEMIN=DDAT(JE+15)*ET                                              DE34      455
      IF (VE.GE.VEMAX) THEN                                             DE34      456
         VE=VEMAX                                                       DE34      457
      ELSE IF (VE.LE.VEMIN) THEN                                        DE34      458
         VE=VEMIN                                                       DE34      459
      END IF                                                            DE34      460
C                                                                       DE34      461
      EFD(JYG+4)=VE                                                     DE34      462
C                                                                       DE34      463
C     IF STATES WERE UPDATED BY INNER LOOP, FOOL THE RKG                DE34      464
C                                                                       DE34      465
  130  IF (SLOGIC) THEN                                                 DE34      466
         DO 140 JX=2,NXS                                                DE34      467
            DSTATE(LSTATE+JX)=0.0                                       DE34      468
  140    CONTINUE                                                       DE34      469
      END IF                                                            DE34      470
C                                                                       DE34      471
      LSTATE=LSTATE+NXS                                                 DE34      472
C                                                                       DE34      473
      RETURN                                                            DE34      474
      END                                                               DE34      475
