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