CFPRIME DUDB25                                                          DUDB25      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 DUDB25(LORD,STEP1)                                     DUDB25      3
CD                                                                      DUDB25      4
CD    TO CALCULATE THE DERIVATIVES OF THE STATES OF USER DEFINED BLOCK  DUDB25      5
CD    TYPE 25 (DIGITAL CONTROLLER BLOCK) IN ANY USER DEFINED MODEL, USEDDUDB25      6
CD    BY BOTH RUNGE-KUTTA AND TRAPEZOIDAL METHOD.                       DUDB25      7
CD                                                                      DUDB25      8
      INCLUDE 'PARX.INS'                                                DUDB25      9
      INCLUDE 'CNMDAT.INS'                                              DUDB25     10
      INCLUDE 'CNB4.INS'                                                DUDB25     11
      INCLUDE 'CNMSTA.INS'                                              DUDB25     12
      INCLUDE 'CNXSTA.INS'                                              DUDB25     13
      INCLUDE 'CNSTN.INS'                                               DUDB25     14
      INCLUDE 'CNYVAR.INS'                                              DUDB25     15
      INCLUDE 'CNUNIT.INS'                                              DUDB25     16
      INCLUDE 'CNFLAG.INS'                                              DUDB25     17
      INCLUDE 'CNUDM.INS'                                               DUDB25     18
      INCLUDE 'CNB9.INS'                                                DUDB25     19
C                                                                       DUDB25     20
      DIMENSION AA(5),BB(5),VI(5),VO(5)                                 DUDB25     21
C                                                                       DUDB25     22
      LDEB=(JDEB(264).NE.0)                                             DUDB25     23
C                                                                       DUDB25     24
      VALI=0.0                                                          DUDB25     25
      IORD=IDDAT(JE4+LORD)                                              DUDB25     26
      JEI=JEB+2                                                         DUDB25     27
      JLS=IDDAT(JEI+1)                                                  DUDB25     28
      DO 100 I=1,5                                                      DUDB25     29
      AA(I)=DDAT(JEI+I+1)                                               DUDB25     30
      BB(I)=DDAT(JEI+I+7)                                               DUDB25     31
      VI(I)=SSMAT(JLS+I)                                                DUDB25     32
      VO(I)=SSMAT(JLS+I+5)                                              DUDB25     33
  100 CONTINUE                                                          DUDB25     34
      BB0=DDAT(JEI+7)                                                   DUDB25     35
      VALI2=SSMAT(JLS+11)                                               DUDB25     36
      SIMT=SSMAT(JLS+12)                                                DUDB25     37
      SAMT=SSMAT(JLS+13)                                                DUDB25     38
      KINT=KINPU                                                        DUDB25     39
      KINPU=KINPU+IDDAT(JEI+13)                                         DUDB25     40
      IF(KINT.LT.KINPU) THEN                                            DUDB25     41
         DO 110 J=KINT+1,KINPU                                          DUDB25     42
         XDAT=GAINS(J)                                                  DUDB25     43
         IOUT=INPUTS(J)                                                 DUDB25     44
         VALI=VALI+VALOUT(IOUT)*XDAT                                    DUDB25     45
  110    CONTINUE                                                       DUDB25     46
      ENDIF                                                             DUDB25     47
      KINP=KINPU                                                        DUDB25     48
      KINPU=KINPU+IDDAT(JEI+14)                                         DUDB25     49
      IF(KINP.LT.KINPU) THEN                                            DUDB25     50
         DO 120 J=KINP+1,KINPU                                          DUDB25     51
         XDAT=GAINS(J)                                                  DUDB25     52
         IIN=INPUTS(J)                                                  DUDB25     53
         VALI=VALI+VALIN(IIN)*XDAT                                      DUDB25     54
  120    CONTINUE                                                       DUDB25     55
      ENDIF                                                             DUDB25     56
C                                                                       DUDB25     57
      VALO=VO(1)                                                        DUDB25     58
      IF(INTMTH.LE.5.AND..NOT.LIR4) GO TO 170                           DUDB25     59
      SIMT1=TS+STEP1                                                    DUDB25     60
      IF(SIMT.GE.SIMT1) GO TO 170                                       DUDB25     61
      SIMT2=SIMT1-SIMT                                                  DUDB25     62
      VALI1=VALI2                                                       DUDB25     63
  130 CONTINUE                                                          DUDB25     64
      IF(STEP1.GT.SAMT) THEN                                            DUDB25     65
         VALI1=VALI1+SAMT*(VALI-VALI2)/SIMT2                            DUDB25     66
      ELSE                                                              DUDB25     67
         VALI1=VALI                                                     DUDB25     68
      ENDIF                                                             DUDB25     69
      VALO=BB0*VALI1                                                    DUDB25     70
      DO 140 I=1,5                                                      DUDB25     71
      VALO=VALO-AA(I)*VO(I)+BB(I)*VI(I)                                 DUDB25     72
  140 CONTINUE                                                          DUDB25     73
      DO 150 I=1,4                                                      DUDB25     74
      VO(I+1)=VO(I)                                                     DUDB25     75
      VI(I+1)=VI(I)                                                     DUDB25     76
  150 CONTINUE                                                          DUDB25     77
      VO(1)=VALO                                                        DUDB25     78
      VI(1)=VALI1                                                       DUDB25     79
      SIMT=SIMT+SAMT                                                    DUDB25     80
      IF(SIMT.LT.SIMT1) GO TO 130                                       DUDB25     81
      DO 160 I=1,5                                                      DUDB25     82
      SSMAT(JLS+I)=VI(I)                                                DUDB25     83
      SSMAT(JLS+I+5)=VO(I)                                              DUDB25     84
  160 CONTINUE                                                          DUDB25     85
      SSMAT(JLS+11)=VALI1                                               DUDB25     86
      SSMAT(JLS+12)=SIMT                                                DUDB25     87
  170 VALOUT(IORD)=VALO                                                 DUDB25     88
      IF(LDEB) WRITE(IUD6,1000) LORD,IORD,VALOUT(IORD)                  DUDB25     89
C                                                                       DUDB25     90
      RETURN                                                            DUDB25     91
 1000 FORMAT(' LORD,IORD,VALOUT(IORD): ',2I5,F10.3)                     DUDB25     92
      END                                                               DUDB25     93
