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