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