CFPRIME DEMXL1                                                          DEMXL1      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 DEMXL1(STEP)                                           DEMXL1      3
CD                                                                      DEMXL1      4
CD    TO CALCULATE THE DERIVATIVES OF THE STATES OF TYPE 1 MAXIMUM      DEMXL1      5
CD    EXCITATION CURRENT LIMITER, USED BY RUNGE-KUTTA METHOD.           DEMXL1      6
CD                                                                      DEMXL1      7
CD    THE DATA STRUCTURE AFTER THE INITIALIZATION IS GIVEN BELOW.       DEMXL1      8
CD                                                                      DEMXL1      9
CD   7.1 Over excitation current limiter type 1                         DEMXL1     10
CD                                                                      DEMXL1     11
CD     Over Excitation current limiter data                             DEMXL1     12
CD                                                                      DEMXL1     13
CD     DDAT(JMX+ 1)   = K                                               DEMXL1     14
CD     DDAT(JMX+ 2)   = TA                                              DEMXL1     15
CD     DDAT(JMX+ 3)   = TB                                              DEMXL1     16
CD     DDAT(JMX+ 4)   = U                                               DEMXL1     17
CD     DDAT(JMX+ 5)   = IFLMAX                                          DEMXL1     18
CD     DDAT(JMX+ 6)   = IFLMIN                                          DEMXL1     19
CD     DDAT(JMX+ 7)   = T1                                              DEMXL1     20
CD     DDAT(JMX+ 8)   = T2 or RATE                                      DEMXL1     21
CD                                                                      DEMXL1     22
CD     Over Excitation current limiter states                           DEMXL1     23
CD                                                                      DEMXL1     24
CD     XSTATE(JMXS+1) = TB block                                        DEMXL1     25
CD                                                                      DEMXL1     26
CD     Over Excitation current limiter Y-variables                      DEMXL1     27
CD                                                                      DEMXL1     28
CD     VMXL(JYMX+1)   = output of maximum excitation current limiter    DEMXL1     29
CD     YIFL(JYMX+2)   = definite integral of vector current from the    DEMXL1     30
CD                      triggering time to the current time             DEMXL1     31
CD                                                                      DEMXL1     32
      INCLUDE 'PARX.INS'                                                DEMXL1     33
      INCLUDE 'CNPT.INS'                                                DEMXL1     34
      INCLUDE 'CNVOLT.INS'                                              DEMXL1     35
      INCLUDE 'CNIPTR.INS'                                              DEMXL1     36
      INCLUDE 'CNMDAT.INS'                                              DEMXL1     37
      INCLUDE 'CNB3.INS'                                                DEMXL1     38
      INCLUDE 'CNB5.INS'                                                DEMXL1     39
      INCLUDE 'CNB8.INS'                                                DEMXL1     40
      INCLUDE 'CNB9.INS'                                                DEMXL1     41
      INCLUDE 'CNB10.INS'                                               DEMXL1     42
      INCLUDE 'CNB19.INS'                                               DEMXL1     43
      INCLUDE 'CNEXC.INS'                                               DEMXL1     44
      INCLUDE 'CNXSTA.INS'                                              DEMXL1     45
      INCLUDE 'CNMYVA.INS'                                              DEMXL1     46
      INCLUDE 'CNYVAR.INS'                                              DEMXL1     47
      INCLUDE 'CNFLAG.INS'                                              DEMXL1     48
C                                                                       DEMXL1     49
      LDEB=(JDEB(89).NE.0)                                              DEMXL1     50
C                                                                       DEMXL1     51
      IF (LDEB) THEN                                                    DEMXL1     52
         WRITE(IUD6,2010) (DDAT(JMX+I),I=1,10)                          DEMXL1     53
         WRITE(IUD6,2020) (XSTATE(JSTATE+I),I=1,1)                      DEMXL1     54
         WRITE(IUD6,2030) (YVAR(JYMX+I),I=1,2)                          DEMXL1     55
      ENDIF                                                             DEMXL1     56
C                                                                       DEMXL1     57
C     CHECK IF TRIGGER CONDITION IS SATISFIED                           DEMXL1     58
C                                                                       DEMXL1     59
      IF (.NOT.LIR1) GOTO 100                                           DEMXL1     60
      IF (DDAT(JMX+10).LE.-0.9999) THEN                                 DEMXL1     61
         IF (CFDN.GE.DDAT(JMX+6)) DDAT(JMX+10)=0.0                      DEMXL1     62
      ENDIF                                                             DEMXL1     63
C                                                                       DEMXL1     64
 100  CONTINUE                                                          DEMXL1     65
C                                                                       DEMXL1     66
C     OBTAIN COMPENSATION CURRENT XINIT                                 DEMXL1     67
C                                                                       DEMXL1     68
      TON=DDAT(JMX+10)                                                  DEMXL1     69
      IF (TON.LE.0.0) THEN                                              DEMXL1     70
         XINIT=CFDN                                                     DEMXL1     71
      ELSE                                                              DEMXL1     72
         CFDA=YIFL(JYMX+2)/TON                                          DEMXL1     73
         IF (TON.LT.DDAT(JMX+7)) THEN                                   DEMXL1     74
            CIFL=DDAT(JMX+5)                                            DEMXL1     75
         ELSE IF (TON.GT.DDAT(JMX+8)) THEN                              DEMXL1     76
            CIFL=DDAT(JMX+6)                                            DEMXL1     77
         ELSE                                                           DEMXL1     78
            CIFL=DDAT(JMX+5)+DDAT(JMX+9)*(TON-DDAT(JMX+7))              DEMXL1     79
         END IF                                                         DEMXL1     80
         IF (CFDA.LT.CIFL) THEN                                         DEMXL1     81
            XINIT=CFDN                                                  DEMXL1     82
         ELSE                                                           DEMXL1     83
            XINIT=CIFL                                                  DEMXL1     84
         END IF                                                         DEMXL1     85
      END IF                                                            DEMXL1     86
C                                                                       DEMXL1     87
C     CALCULATE DSTATE                                                  DEMXL1     88
C                                                                       DEMXL1     89
      XINIT=CFDN-XINIT                                                  DEMXL1     90
      IF (XINIT.GT.DDAT(JMX+4)) THEN                                    DEMXL1     91
         XINIT=DDAT(JMX+4)                                              DEMXL1     92
      ELSE IF (XINIT.LT.0.0) THEN                                       DEMXL1     93
         XINIT=0.0                                                      DEMXL1     94
      END IF                                                            DEMXL1     95
      XINIT=XINIT*DDAT(JMX+1)                                           DEMXL1     96
      IF (IDDAT(JMX+3).NE.0) THEN                                       DEMXL1     97
         DSTATE(LSTATE+1)=(XINIT-XSTATE(JSTATE+1))/DDAT(JMX+3)          DEMXL1     98
         VMXL(JYMX+1)=XSTATE(JSTATE+1)+DSTATE(LSTATE+1)*DDAT(JMX+2)     DEMXL1     99
      ELSE                                                              DEMXL1    100
         VMXL(JYMX+1)=XINIT                                             DEMXL1    101
      END IF                                                            DEMXL1    102
C                                                                       DEMXL1    103
      LSTATE=LSTATE+1                                                   DEMXL1    104
      IF (LIR4) THEN                                                    DEMXL1    105
         IF (DDAT(JMX+10).GE.0.0) THEN                                  DEMXL1    106
            DDAT(JMX+10)=DDAT(JMX+10)+STEP                              DEMXL1    107
            YIFL(JYMX+2)=YIFL(JYMX+2)+CFDN*STEP                         DEMXL1    108
         END IF                                                         DEMXL1    109
      END IF                                                            DEMXL1    110
C                                                                       DEMXL1    111
      IF (LDEB) THEN                                                    DEMXL1    112
         WRITE(IUD6,2010) (DDAT(JMX+I),I=1,10)                          DEMXL1    113
         WRITE(IUD6,2020) (XSTATE(JSTATE+I),I=1,1)                      DEMXL1    114
         WRITE(IUD6,2040) (DSTATE(LSTATE+I),I=1,1)                      DEMXL1    115
         WRITE(IUD6,2030) (YVAR(JYMX+I),I=1,2)                          DEMXL1    116
      ENDIF                                                             DEMXL1    117
C                                                                       DEMXL1    118
 2010 FORMAT(1X,'DMXL1-DB:DDAT   ',9G12.5)                              DEMXL1    119
 2020 FORMAT(1X,'DMXL1-DB:XSTATE ',9G12.5)                              DEMXL1    120
 2030 FORMAT(1X,'DMXL1-DB:Y-VAR  ',9G12.5)                              DEMXL1    121
 2040 FORMAT(1X,'DMXL1-DB:DSTATE ',9G12.5)                              DEMXL1    122
C                                                                       DEMXL1    123
      RETURN                                                            DEMXL1    124
C                                                                       DEMXL1    125
C-----------------------------------------------------------------------DEMXL1    126
C                                                                       DEMXL1    127
      ENTRY DEMXLI(STEP)                                                DEMXL1    128
CD                                                                      DEMXL1    129
CD    FOR USE IN IMPLICIT INTEGRATION METHOD.                           DEMXL1    130
CD                                                                      DEMXL1    131
C                                                                       DEMXL1    132
C     OBTAIN COMPENSATION CURRENT XINIT                                 DEMXL1    133
C                                                                       DEMXL1    134
      TON=DDAT(JMX+10)                                                  DEMXL1    135
      IF (TON.LE.0.0) THEN                                              DEMXL1    136
         XINIT=CFDN                                                     DEMXL1    137
      ELSE                                                              DEMXL1    138
         CFDA=YIFL(JYMX+2)/TON                                          DEMXL1    139
         IF (TON.LT.DDAT(JMX+7)) THEN                                   DEMXL1    140
            CIFL=DDAT(JMX+5)                                            DEMXL1    141
         ELSE IF (TON.GT.DDAT(JMX+8)) THEN                              DEMXL1    142
            CIFL=DDAT(JMX+6)                                            DEMXL1    143
         ELSE                                                           DEMXL1    144
            CIFL=DDAT(JMX+5)+DDAT(JMX+9)*(TON-DDAT(JMX+7))              DEMXL1    145
         END IF                                                         DEMXL1    146
         IF (CFDA.LT.CIFL) THEN                                         DEMXL1    147
            XINIT=CFDN                                                  DEMXL1    148
         ELSE                                                           DEMXL1    149
            XINIT=CIFL                                                  DEMXL1    150
         END IF                                                         DEMXL1    151
      END IF                                                            DEMXL1    152
C                                                                       DEMXL1    153
C     CALCULATE DSTATE                                                  DEMXL1    154
C                                                                       DEMXL1    155
      XINIT=CFDN-XINIT                                                  DEMXL1    156
      IF (XINIT.GT.DDAT(JMX+4)) THEN                                    DEMXL1    157
         XINIT=DDAT(JMX+4)                                              DEMXL1    158
      ELSE IF (XINIT.LT.0.0) THEN                                       DEMXL1    159
         XINIT=0.0                                                      DEMXL1    160
      END IF                                                            DEMXL1    161
      XINIT=XINIT*DDAT(JMX+1)                                           DEMXL1    162
      IF (IDDAT(JMX+3).NE.0) THEN                                       DEMXL1    163
         DSTATE(LSTATE+1)=(XINIT-XSTATE(JSTATE+1))/DDAT(JMX+3)          DEMXL1    164
         VMXL(JYMX+1)=XSTATE(JSTATE+1)+DSTATE(LSTATE+1)*DDAT(JMX+2)     DEMXL1    165
      ELSE                                                              DEMXL1    166
         VMXL(JYMX+1)=XINIT                                             DEMXL1    167
      END IF                                                            DEMXL1    168
C                                                                       DEMXL1    169
      LSTATE=LSTATE+1                                                   DEMXL1    170
C                                                                       DEMXL1    171
      RETURN                                                            DEMXL1    172
      END                                                               DEMXL1    173
