CFPRIME DUDB22                                                          DUDB22      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 DUDB22(LORD,KORD)                                      DUDB22      3
CD                                                                      DUDB22      4
CD    TO CALCULATE THE DERIVATIVES OF THE STATES OF USER DEFINED BLOCK  DUDB22      5
CD    TYPE 22 (STATE SPACE BLOCK) IN ANY USER DEFINED MODEL, USED BY    DUDB22      6
CD    BOTH RUNGE-KUTTA AND TRAPEZOIDAL METHOD.                          DUDB22      7
CD                                                                      DUDB22      8
      INCLUDE 'PARX.INS'                                                DUDB22      9
      INCLUDE 'CNMDAT.INS'                                              DUDB22     10
      INCLUDE 'CNMSTA.INS'                                              DUDB22     11
      INCLUDE 'CNXSTA.INS'                                              DUDB22     12
      INCLUDE 'CNSTN.INS'                                               DUDB22     13
      INCLUDE 'CNYVAR.INS'                                              DUDB22     14
      INCLUDE 'CNUNIT.INS'                                              DUDB22     15
      INCLUDE 'CNFLAG.INS'                                              DUDB22     16
      INCLUDE 'CNUDM.INS'                                               DUDB22     17
C                                                                       DUDB22     18
      DIMENSION AA(8,8),BB(8,8),CC(8),DD(8),VALI(8)                     DUDB22     19
      LDEB=(JDEB(264).NE.0)                                             DUDB22     20
C                                                                       DUDB22     21
      IBB=0                                                             DUDB22     22
      VALO=0.0                                                          DUDB22     23
      IORD=IDDAT(JE4+LORD)                                              DUDB22     24
      JEI=JEB+2                                                         DUDB22     25
      NAA=IDDAT(JEI+1)                                                  DUDB22     26
      NBB=IDDAT(JEI+2)                                                  DUDB22     27
      JLS=IDDAT(JEI+3)                                                  DUDB22     28
      KINT=KINPU                                                        DUDB22     29
      KINPU=KINPU+IDDAT(JEI+13)                                         DUDB22     30
      IF(KINT.LT.KINPU) THEN                                            DUDB22     31
         DO 110 J=KINT+1,KINPU                                          DUDB22     32
         XDAT=GAINS(J)                                                  DUDB22     33
         IOUT=INPUTS(J)                                                 DUDB22     34
         IBB=IBB+1                                                      DUDB22     35
         VALI(IBB)=VALOUT(IOUT)*XDAT                                    DUDB22     36
  110    CONTINUE                                                       DUDB22     37
      ENDIF                                                             DUDB22     38
      KINP=KINPU                                                        DUDB22     39
      KINPU=KINPU+IDDAT(JEI+14)                                         DUDB22     40
      IF(KINP.LT.KINPU) THEN                                            DUDB22     41
         DO 120 J=KINP+1,KINPU                                          DUDB22     42
         XDAT=GAINS(J)                                                  DUDB22     43
         IIN=INPUTS(J)                                                  DUDB22     44
         IBB=IBB+1                                                      DUDB22     45
         VALI(IBB)=VALIN(IIN)*XDAT                                      DUDB22     46
  120    CONTINUE                                                       DUDB22     47
      ENDIF                                                             DUDB22     48
      DO 130 L=1,NAA                                                    DUDB22     49
      DO 130 J=1,NAA                                                    DUDB22     50
      JLS=JLS+1                                                         DUDB22     51
      AA(L,J)=SSMAT(JLS)                                                DUDB22     52
  130 CONTINUE                                                          DUDB22     53
      DO 140 L=1,NAA                                                    DUDB22     54
      DO 140 J=1,NBB                                                    DUDB22     55
      JLS=JLS+1                                                         DUDB22     56
      BB(L,J)=SSMAT(JLS)                                                DUDB22     57
  140 CONTINUE                                                          DUDB22     58
      DO 150 L=1,NAA                                                    DUDB22     59
      JLS=JLS+1                                                         DUDB22     60
      CC(L)=SSMAT(JLS)                                                  DUDB22     61
  150 CONTINUE                                                          DUDB22     62
      DO 160 L=1,NBB                                                    DUDB22     63
      JLS=JLS+1                                                         DUDB22     64
      DD(L)=SSMAT(JLS)                                                  DUDB22     65
  160 CONTINUE                                                          DUDB22     66
      DO 180 I=1,NAA                                                    DUDB22     67
      SUM=0.0                                                           DUDB22     68
      DO 170 J=1,NAA                                                    DUDB22     69
      SUM=SUM+AA(I,J)*XSTATE(JSTATE+KORD+J)                             DUDB22     70
  170 CONTINUE                                                          DUDB22     71
      DSTATE(LSTATE+KORD+I)=SUM                                         DUDB22     72
  180 CONTINUE                                                          DUDB22     73
      DO 200 I=1,NAA                                                    DUDB22     74
      SUM=0.0                                                           DUDB22     75
      DO 190 J=1,IBB                                                    DUDB22     76
      SUM=SUM+BB(I,J)*VALI(J)                                           DUDB22     77
  190 CONTINUE                                                          DUDB22     78
      DSTATE(LSTATE+KORD+I)=DSTATE(LSTATE+KORD+I)+SUM                   DUDB22     79
  200 CONTINUE                                                          DUDB22     80
      DO 210 J=1,NAA                                                    DUDB22     81
      KORD=KORD+1                                                       DUDB22     82
      VALO=VALO+CC(J)*XSTATE(JSTATE+KORD)                               DUDB22     83
  210 CONTINUE                                                          DUDB22     84
      DO 220 J=1,IBB                                                    DUDB22     85
      VALO=VALO+DD(J)*VALI(J)                                           DUDB22     86
  220 CONTINUE                                                          DUDB22     87
      VALOUT(IORD)=VALO                                                 DUDB22     88
      IF(LDEB) WRITE(IUD6,1000) KORD,LORD,IORD,VALOUT(IORD)             DUDB22     89
C                                                                       DUDB22     90
      RETURN                                                            DUDB22     91
 1000 FORMAT(1X,'KORD,LORD,IORD,VALOUT(IORD): ',3I5,F10.3)              DUDB22     92
      END                                                               DUDB22     93
