CFPRIME DETSCL                                                          DETSCL      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 DETSCL(H)                                              DETSCL      3
CD                                                                      DETSCL      4
CD    TO CALCULATE THE DERIVATIVES OF THE STATES OF TSC LOAD FOR USE IN DETSCL      5
CD    THE RUNGE-KUTTA METHOD.                                           DETSCL      6
CD                                                                      DETSCL      7
CD    UPDATE THE STATES FOR THE CURRENT TIME STEP BY THE RUNGE-KUTTA    DETSCL      8
CD    FORMULA.                                                          DETSCL      9
CD                                                                      DETSCL     10
      INCLUDE 'PARX.INS'                                                DETSCL     11
      INCLUDE 'CNPT.INS'                                                DETSCL     12
      INCLUDE 'CNB4.INS'                                                DETSCL     13
      INCLUDE 'CNB6.INS'                                                DETSCL     14
      INCLUDE 'CNB9.INS'                                                DETSCL     15
      INCLUDE 'CNB19.INS'                                               DETSCL     16
      INCLUDE 'CNPARX.INS'                                              DETSCL     17
      INCLUDE 'CNIPTR.INS'                                              DETSCL     18
      INCLUDE 'CNXSTA.INS'                                              DETSCL     19
      INCLUDE 'CNQSTA.INS'                                              DETSCL     20
      INCLUDE 'CNZSTA.INS'                                              DETSCL     21
      INCLUDE 'CNMDAT.INS'                                              DETSCL     22
      INCLUDE 'CNVOLT.INS'                                              DETSCL     23
      INCLUDE 'CNMYVA.INS'                                              DETSCL     24
C                                                                       DETSCL     25
      IF (NTSCL.EQ.0) RETURN                                            DETSCL     26
C                                                                       DETSCL     27
      DO 120 K=1,NTSCL                                                  DETSCL     28
         JTSC=JTCDAT(K)                                                 DETSCL     29
         IF (IDDAT(JTSC+15).EQ.1) GOTO 120                              DETSCL     30
         JSTATE=JXTSC(K)                                                DETSCL     31
         NLF=IDDAT(JTSC+1)                                              DETSCL     32
C                                                                       DETSCL     33
         VREAL=REAL(VOLT(NLF))                                          DETSCL     34
         VIMAG=AIMAG(VOLT(NLF))                                         DETSCL     35
         VMG=VREAL**2+VIMAG**2                                          DETSCL     36
C                                                                       DETSCL     37
         GTSC=DDAT(JTSC+11)                                             DETSCL     38
         WS1=DDAT(JTSC+5)*GTSC*VMG+DDAT(JTSC+8)                         DETSCL     39
         DSTATE(1)=(WS1-XSTATE(JSTATE+1))/DDAT(JTSC+6)                  DETSCL     40
C                                                                       DETSCL     41
         DELT=DDAT(JTSC+9)-XSTATE(JSTATE+1)                             DETSCL     42
         DSTATE(2)=DDAT(JTSC+3)*DELT/DDAT(JTSC+4)                       DETSCL     43
C                                                                       DETSCL     44
         IF (XSTATE(JSTATE+2).GE.DDAT(JTSC+7)) THEN                     DETSCL     45
            XSTATE(JSTATE+2)=DDAT(JTSC+7)                               DETSCL     46
            IF (DSTATE(2).GT.0.0) THEN                                  DETSCL     47
               DSTATE(2)=0.0                                            DETSCL     48
               QSTATE(2)=0.0                                            DETSCL     49
            END IF                                                      DETSCL     50
         ELSE IF (XSTATE(JSTATE+2).LE.0.0) THEN                         DETSCL     51
            XSTATE(JSTATE+2)=0.0                                        DETSCL     52
            IF (DSTATE(2).LT.0.0) THEN                                  DETSCL     53
               DSTATE(2)=0.0                                            DETSCL     54
               QSTATE(2)=0.0                                            DETSCL     55
            END IF                                                      DETSCL     56
         END IF                                                         DETSCL     57
C                                                                       DETSCL     58
         CALL RKG(2,JSTATE,XSTATE,DSTATE,QSTATE,ZSTATE,H)               DETSCL     59
C                                                                       DETSCL     60
         IF (LIR4) THEN                                                 DETSCL     61
            IF (XSTATE(JSTATE+2).GE.DDAT(JTSC+7)) THEN                  DETSCL     62
               XSTATE(JSTATE+2)=DDAT(JTSC+7)                            DETSCL     63
            ELSE IF (XSTATE(JSTATE+2).LE.0.0) THEN                      DETSCL     64
               XSTATE(JSTATE+2)=0.0                                     DETSCL     65
            END IF                                                      DETSCL     66
C                                                                       DETSCL     67
            GTSC=XSTATE(JSTATE+2)+DDAT(JTSC+2)*DELT                     DETSCL     68
C                                                                       DETSCL     69
            IF (GTSC.GT.DDAT(JTSC+7)) THEN                              DETSCL     70
               GTSC=DDAT(JTSC+7)                                        DETSCL     71
            ELSE IF (GTSC.LT.0.0) THEN                                  DETSCL     72
               GTSC=0.0                                                 DETSCL     73
            END IF                                                      DETSCL     74
            DDAT(JTSC+11)=GTSC                                          DETSCL     75
         END IF                                                         DETSCL     76
C                                                                       DETSCL     77
 120  CONTINUE                                                          DETSCL     78
C                                                                       DETSCL     79
      RETURN                                                            DETSCL     80
      END                                                               DETSCL     81
