CFPRIME DE31                                                            DE31        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 DE31                                                   DE31        3
CD                                                                      DE31        4
CD    TO CALCULATE THE DERIVATIVES OF THE STATES OF TYPE 31 EXCITER,    DE31        5
CD    USED BY BOTH RUNGE-KUTTA AND TRAPEZOIDAL METHOD.                  DE31        6
CD                                                                      DE31        7
CD    THE DATA STRUCTURE FOR THIS TYPE OF EXCITER IS GIVEN BELOW.       DE31        8
CD                                                                      DE31        9
CD   3.13 Exciter type 31                                               DE31       10
CD                                                                      DE31       11
CD     Exciter data                                                     DE31       12
CD                                                                      DE31       13
CD     IDDAT(JE+ 1)   = IVTN         : sensing bus number               DE31       14
CD     DDAT(JE+ 2)    = KA                                              DE31       15
CD     DDAT(JE+ 3)    = VAMAX                                           DE31       16
CD     DDAT(JE+ 4)    = TC                                              DE31       17
CD     DDAT(JE+ 5)    = TB                                              DE31       18
CD     DDAT(JE+ 6)    = PHIMAX                                          DE31       19
CD     DDAT(JE+ 7)    = PHIMIN                                          DE31       20
CD     DDAT(JE+ 8)    = VSMAX                                           DE31       21
CD     DDAT(JE+ 9)    = VSMIN                                           DE31       22
CD     DDAT(JE+10)    = VRMAX                                           DE31       23
CD     DDAT(JE+11)    = VRMIN                                           DE31       24
CD     DDAT(JE+12)    = (reserved for future use)                       DE31       25
CD     DDAT(JE+13)    = KVF                                             DE31       26
CD     DDAT(JE+14)    = ETMIN                                           DE31       27
CD     DDAT(JE+15)    = KIFL                                            DE31       28
CD     DDAT(JE+16)    = IFLMT                                           DE31       29
CD     DDAT(JE+17)    = (reserved for future use)                       DE31       30
CD     DDAT(JE+18)    = TR                                              DE31       31
CD     DDAT(JE+19)    = RC                                              DE31       32
CD     DDAT(JE+20)    = XC                                              DE31       33
CD     DDAT(JE+21)    = KETL                                            DE31       34
CD     DDAT(JE+22)    = TL1                                             DE31       35
CD     DDAT(JE+23)    = TL2                                             DE31       36
CD     DDAT(JE+24)    = ETLMT                                           DE31       37
CD     DDAT(JE+25)    = VOMX                                            DE31       38
CD                                                                      DE31       39
CD     Exciter states                                                   DE31       40
CD                                                                      DE31       41
CD     XSTATE(JES+1)  = TR block     : compulsory                       DE31       42
CD     XSTATE(JES+2)  = TL2 block    : optional                         DE31       43
CD     XSTATE(JES+3)  = TB block     : optional                         DE31       44
CD                                                                      DE31       45
CD     Exciter Y-variables                                              DE31       46
CD                                                                      DE31       47
CD     VREG(JYE+1)    = VC (input to the TR block)                      DE31       48
CD     VREF(JYE+2)    = reference value                                 DE31       49
CD                                                                      DE31       50
      INCLUDE 'PARX.INS'                                                DE31       51
      INCLUDE 'CNPT.INS'                                                DE31       52
      INCLUDE 'CNVOLT.INS'                                              DE31       53
      INCLUDE 'CNIPTR.INS'                                              DE31       54
      INCLUDE 'CNMDAT.INS'                                              DE31       55
      INCLUDE 'CNB1.INS'                                                DE31       56
      INCLUDE 'CNB3.INS'                                                DE31       57
      INCLUDE 'CNB4.INS'                                                DE31       58
      INCLUDE 'CNB5.INS'                                                DE31       59
      INCLUDE 'CNB8.INS'                                                DE31       60
      INCLUDE 'CNB9.INS'                                                DE31       61
      INCLUDE 'CNB10.INS'                                               DE31       62
      INCLUDE 'CNB19.INS'                                               DE31       63
      INCLUDE 'CNEXC.INS'                                               DE31       64
      INCLUDE 'CNSTN.INS'                                               DE31       65
      INCLUDE 'CNXSTA.INS'                                              DE31       66
      INCLUDE 'CNQSTA.INS'                                              DE31       67
      INCLUDE 'CNMYVA.INS'                                              DE31       68
      INCLUDE 'CNYVAR.INS'                                              DE31       69
      INCLUDE 'CNMSG.INS'                                               DE31       70
C                                                                       DE31       71
C                                                                       DE31       72
      IF (IR.EQ.1.AND.IDDAT(JE+28).EQ.-1) IDDAT(JE+28)=0                DE31       73
C                                                                       DE31       74
      EFMX=DDAT(JE+10)                                                  DE31       75
      EFMN=DDAT(JE+11)                                                  DE31       76
      NXS=1                                                             DE31       77
C                                                                       DE31       78
C  TERMINAL VOLTAGE LIMITER                                             DE31       79
C                                                                       DE31       80
      IF (IDDAT(JE+21).EQ.0) THEN                                       DE31       81
         V2=0.0                                                         DE31       82
      ELSE                                                              DE31       83
         XETD=ET-DDAT(JE+24)                                            DE31       84
         IF (XETD.LT.0.0) XETD=0.0                                      DE31       85
         V2=DDAT(JE+21)*XETD                                            DE31       86
         IF (IDDAT(JE+23).NE.0) THEN                                    DE31       87
            NXS=NXS+1                                                   DE31       88
            DSTATE(LSTATE+NXS)=(V2-XSTATE(JSTATE+NXS))/DDAT(JE+23)      DE31       89
            IF (XSTATE(JSTATE+NXS).GE.DDAT(JE+25).AND.DSTATE(LSTATE+    DE31       90
     +         NXS).GT.0.0) THEN                                        DE31       91
               DSTATE(LSTATE+NXS)=0.0                                   DE31       92
               QSTATE(JSTATE+NXS)=0.0                                   DE31       93
            END IF                                                      DE31       94
            V2=XSTATE(JSTATE+NXS)+DDAT(JE+22)*DSTATE(LSTATE+NXS)        DE31       95
          END IF                                                        DE31       96
          IF (V2.GT.DDAT(JE+25)) V2=DDAT(JE+25)                         DE31       97
      END IF                                                            DE31       98
C                                                                       DE31       99
C  FIELD CURRENT LIMITER                                                DE31      100
C                                                                       DE31      101
      IF (IDDAT(JE+15).EQ.0.OR.IDDAT(JE+16).EQ.0) THEN                  DE31      102
         XIFL=0.0                                                       DE31      103
      ELSE                                                              DE31      104
         IF (DDAT(JE+16).GT.CFDN) THEN                                  DE31      105
            XIFL=0.0                                                    DE31      106
            IF (IDDAT(JE+28).EQ.1) IDDAT(JE+28)=-1                      DE31      107
         ELSE                                                           DE31      108
            IF (IDDAT(JE+28).EQ.-1) THEN                                DE31      109
               XIFL=0.0                                                 DE31      110
            ELSE                                                        DE31      111
               XIFL=DDAT(JE+15)*(CFDN-DDAT(JE+16))                      DE31      112
               IF (IDDAT(JE+28).EQ.0) IDDAT(JE+28)=1                    DE31      113
            END IF                                                      DE31      114
         END IF                                                         DE31      115
      END IF                                                            DE31      116
C                                                                       DE31      117
      IF (ISTABN.GT.0) THEN                                             DE31      118
         VSUM=VSS(JYS+1)-V2                                             DE31      119
      ELSE                                                              DE31      120
         VSUM=-V2                                                       DE31      121
      ENDIF                                                             DE31      122
      IF (IUALN.NE.0) VSUM=VSUM+VUAL(JYU+1)                             DE31      123
      IF (ITEBN.NE.0) VSUM=VSUM+TEB(JYTB+1)                             DE31      124
      IF (IMXLN.NE.0) VSUM=VSUM-VMXL(JYMX+1)                            DE31      125
C                                                                       DE31      126
      IF (VSUM.GT.DDAT(JE+8))THEN                                       DE31      127
      VSUM=DDAT(JE+8)                                                   DE31      128
      ELSEIF(VSUM.LT.DDAT(JE+9))THEN                                    DE31      129
      VSUM=DDAT(JE+9)                                                   DE31      130
      ENDIF                                                             DE31      131
C                                                                       DE31      132
      VSUM=VSUM+VREF(JYE+2)-V1-XIFL                                     DE31      133
      V3=VSUM                                                           DE31      134
C                                                                       DE31      135
C   TRANSIENT GAIN REDUCTION                                            DE31      136
C                                                                       DE31      137
      IF(IDDAT(JE+5).NE.0)THEN                                          DE31      138
      NXS=NXS+1                                                         DE31      139
      DSTATE(LSTATE+NXS)=(VSUM-XSTATE(JSTATE+NXS))/DDAT(JE+5)           DE31      140
      IF (XSTATE(JSTATE+NXS).GE.EFMX.AND.DSTATE(LSTATE+NXS).            DE31      141
     + GT.0.0) THEN                                                     DE31      142
         DSTATE(LSTATE+NXS)=0.0                                         DE31      143
         QSTATE(JSTATE+NXS)=0.0                                         DE31      144
      ELSE IF (XSTATE(JSTATE+NXS).LE.EFMN.AND.DSTATE(LSTATE+NXS).       DE31      145
     + LT.0.0) THEN                                                     DE31      146
         DSTATE(LSTATE+NXS)=0.0                                         DE31      147
         QSTATE(JSTATE+NXS)=0.0                                         DE31      148
      END IF                                                            DE31      149
      V3=XSTATE(JSTATE+NXS)+DDAT(JE+4)*DSTATE(LSTATE+NXS)               DE31      150
      ENDIF                                                             DE31      151
C                                                                       DE31      152
      IF(V3.GT.EFMX)THEN                                                DE31      153
      V3=EFMX                                                           DE31      154
      ELSEIF(V3.LT.EFMN)THEN                                            DE31      155
      V3=EFMN                                                           DE31      156
      ENDIF                                                             DE31      157
      PHI=(DDAT(JE+2)/DDAT(JE+3))*V3                                    DE31      158
      IF(PHI.GT.DDAT(JE+6))THEN                                         DE31      159
      PHI=DDAT(JE+6)                                                    DE31      160
      ELSEIF(PHI.LT.DDAT(JE+7))THEN                                     DE31      161
      PHI=DDAT(JE+7)                                                    DE31      162
      ENDIF                                                             DE31      163
      SPHI=SIN(PHI)                                                     DE31      164
      VE=(ET*DDAT(JE+3)-DDAT(JE+13)*CFDN)*SPHI                          DE31      165
      XVARB=PHI                                                         DE31      166
      REFMX=0.99*DDAT(JE+6)                                             DE31      167
      EFD(JYG+4)=VE                                                     DE31      168
C                                                                       DE31      169
      IF (ET.LT.DDAT(JE+14)) EFD(JYG+4)=0.                              DE31      170
C                                                                       DE31      171
      LSTATE=LSTATE+NXS                                                 DE31      172
C                                                                       DE31      173
      RETURN                                                            DE31      174
C                                                                       DE31      175
 1000 FORMAT(' *** WARNING GENERATOR AT BUS ',I5,' STATION: ',3A4       DE31      176
     1,' GID ',A2)                                                      DE31      177
 1010 FORMAT('     VERY FAST FIELD CURRENT CONTROL IN TYPE 31 EXCITER'  DE31      178
     1,' IS TRIGGERED')                                                 DE31      179
 1020 FORMAT('     AT ',F7.3,' SECONDS. IF NECESSARY, USE A SMALL'      DE31      180
     1,' STEP SIZE')                                                    DE31      181
 1030 FORMAT('     (ABOUT 0.001 SECONDS) DURING THE TRIGGERING PERIOD.')DE31      182
C                                                                       DE31      183
      END                                                               DE31      184
