CFPRIME DUDB24                                                          DUDB24      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 DUDB24(LORD,KORD)                                      DUDB24      3
CD                                                                      DUDB24      4
CD    TO CALCULATE THE DERIVATIVES OF THE STATES OF USER DEFINED BLOCK  DUDB24      5
CD    TYPE 24 (TRANSFER FUNCTION BLOCK) IN ANY USER DEFINED MODEL, USED DUDB24      6
CD    BY BOTH RUNGE-KUTTA AND TRAPEZOIDAL METHOD.                       DUDB24      7
CD                                                                      DUDB24      8
      INCLUDE 'PARX.INS'                                                DUDB24      9
      INCLUDE 'CNMDAT.INS'                                              DUDB24     10
      INCLUDE 'CNMSTA.INS'                                              DUDB24     11
      INCLUDE 'CNXSTA.INS'                                              DUDB24     12
      INCLUDE 'CNSTN.INS'                                               DUDB24     13
      INCLUDE 'CNYVAR.INS'                                              DUDB24     14
      INCLUDE 'CNUNIT.INS'                                              DUDB24     15
      INCLUDE 'CNFLAG.INS'                                              DUDB24     16
      INCLUDE 'CNUDM.INS'                                               DUDB24     17
C                                                                       DUDB24     18
      DIMENSION AA(6),DD(5)                                             DUDB24     19
      LDEB=(JDEB(264).NE.0)                                             DUDB24     20
C                                                                       DUDB24     21
      VALI=0.0                                                          DUDB24     22
      IORD=IDDAT(JE4+LORD)                                              DUDB24     23
      JEI=JEB+2                                                         DUDB24     24
      NS=IDDAT(JEI+1)                                                   DUDB24     25
      AA(1)=1.0                                                         DUDB24     26
      DO 100 I=1,NS                                                     DUDB24     27
      AA(I+1)=DDAT(JEI+I+1)                                             DUDB24     28
      DD(I)=DDAT(JEI+I+7)                                               DUDB24     29
  100 CONTINUE                                                          DUDB24     30
      DEN=AA(NS+1)                                                      DUDB24     31
      KINT=KINPU                                                        DUDB24     32
      KINPU=KINPU+IDDAT(JEI+13)                                         DUDB24     33
      IF(KINT.LT.KINPU) THEN                                            DUDB24     34
         DO 110 J=KINT+1,KINPU                                          DUDB24     35
         XDAT=GAINS(J)                                                  DUDB24     36
         IOUT=INPUTS(J)                                                 DUDB24     37
         VALI=VALI+VALOUT(IOUT)*XDAT                                    DUDB24     38
  110    CONTINUE                                                       DUDB24     39
      ENDIF                                                             DUDB24     40
      KINP=KINPU                                                        DUDB24     41
      KINPU=KINPU+IDDAT(JEI+14)                                         DUDB24     42
      IF(KINP.LT.KINPU) THEN                                            DUDB24     43
         DO 120 J=KINP+1,KINPU                                          DUDB24     44
         XDAT=GAINS(J)                                                  DUDB24     45
         IIN=INPUTS(J)                                                  DUDB24     46
         VALI=VALI+VALIN(IIN)*XDAT                                      DUDB24     47
  120    CONTINUE                                                       DUDB24     48
      ENDIF                                                             DUDB24     49
C                                                                       DUDB24     50
      DO 130 I=1,NS                                                     DUDB24     51
      DD(I)=DD(I)*VALI                                                  DUDB24     52
  130 CONTINUE                                                          DUDB24     53
      BB0=DDAT(JEI+7)*VALI                                              DUDB24     54
      IF(NS.GE.2) THEN                                                  DUDB24     55
         DO 140 L=1,NS-1                                                DUDB24     56
         DSTATE(LSTATE+KORD+L)=XSTATE(JSTATE+KORD+L+1)+DD(L+1)          DUDB24     57
  140    CONTINUE                                                       DUDB24     58
      ENDIF                                                             DUDB24     59
      DSTATE(LSTATE+KORD+NS)=BB0/DEN                                    DUDB24     60
      DO 150 I=1,NS                                                     DUDB24     61
      DSTATE(LSTATE+KORD+NS)=DSTATE(LSTATE+KORD+NS)                     DUDB24     62
     &-AA(I)*(XSTATE(JSTATE+KORD+I)+DD(I))/DEN                          DUDB24     63
  150 CONTINUE                                                          DUDB24     64
      VALOUT(IORD)=XSTATE(JSTATE+KORD+1)+DD(1)                          DUDB24     65
      KORD=KORD+NS                                                      DUDB24     66
      IF(LDEB) WRITE(IUD6,1000) KORD,LORD,IORD,VALOUT(IORD)             DUDB24     67
C                                                                       DUDB24     68
      RETURN                                                            DUDB24     69
 1000 FORMAT(1X,'KORD,LORD,IORD,VALOUT(IORD): ',3I5,F10.3)              DUDB24     70
      END                                                               DUDB24     71
