CFPRIME IUDB25                                                          IUDB25      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 IUDB25(IORD,INDEX,NLF,KN,CID)                          IUDB25      3
CD                                                                      IUDB25      4
CD    TO PERFORM INITIALIZATION FOR USER DEFINED BLOCK TYPE 23 (DIGITAL IUDB25      5
CD    CONTROLLER BLOCK) IN ANY USER DEFINED MODEL.                      IUDB25      6
CD                                                                      IUDB25      7
      INCLUDE 'PARX.INS'                                                IUDB25      8
      INCLUDE 'CNMDAT.INS'                                              IUDB25      9
      INCLUDE 'CNMSTA.INS'                                              IUDB25     10
      INCLUDE 'CNXSTA.INS'                                              IUDB25     11
      INCLUDE 'CNSTN.INS'                                               IUDB25     12
      INCLUDE 'CNYVAR.INS'                                              IUDB25     13
      INCLUDE 'CNUNIT.INS'                                              IUDB25     14
      INCLUDE 'CNFLAG.INS'                                              IUDB25     15
      INCLUDE 'CNMSG.INS'                                               IUDB25     16
      INCLUDE 'CNUDM.INS'                                               IUDB25     17
C                                                                       IUDB25     18
      CHARACTER*2 CID                                                   IUDB25     19
      DIMENSION AA(5),BB(5)                                             IUDB25     20
C                                                                       IUDB25     21
      LDEB=(JDEB(262).NE.0)                                             IUDB25     22
C                                                                       IUDB25     23
      NEXTB=0                                                           IUDB25     24
      VALI=0.0                                                          IUDB25     25
      JORD=JUDE(IORD)                                                   IUDB25     26
      JEI=JEB+2                                                         IUDB25     27
      JLS=IDDAT(JEI+1)                                                  IUDB25     28
      SAMT=SSMAT(JLS+13)                                                IUDB25     29
      IF(SAMT.LT.0.00001) THEN                                          IUDB25     30
         WRITE(MSG(1),1000) NLF,INAME(KN-2),INAME(KN-1),INAME(KN),CID   IUDB25     31
         WRITE(MSG(2),1050) IORD,BLNAM1,BLNAM2                          IUDB25     32
         WRITE(MSG(3),1060)                                             IUDB25     33
         CALL PRTMSG(3)                                                 IUDB25     34
         MSG(1)='IUDB25: UDM ERROR'                                     IUDB25     35
         CALL ASTOP(MSG(1),17)                                          IUDB25     36
      ENDIF                                                             IUDB25     37
      BB0=DDAT(JEI+7)                                                   IUDB25     38
      SUMA=1.0                                                          IUDB25     39
      SUMB=BB0                                                          IUDB25     40
      DO 100 I=1,5                                                      IUDB25     41
      AA(I)=DDAT(JEI+I+1)                                               IUDB25     42
      SUMA=SUMA+AA(I)                                                   IUDB25     43
      BB(I)=DDAT(JEI+I+7)                                               IUDB25     44
      SUMB=SUMB+BB(I)                                                   IUDB25     45
  100 CONTINUE                                                          IUDB25     46
C                                                                       IUDB25     47
      IF(INDEX.EQ.1.OR.INDEX.EQ.2) THEN                                 IUDB25     48
         J2=JE5-2                                                       IUDB25     49
         DO 110 J=1,INTUD                                               IUDB25     50
         J2=J2+2                                                        IUDB25     51
         IDD=IDDAT(J2+2)                                                IUDB25     52
         IDD=ABS(IDD)                                                   IUDB25     53
         IF(IDD.EQ.IORD) THEN                                           IUDB25     54
            XDAT=1.0                                                    IUDB25     55
            IF(IDDAT(J2+2).LT.0) XDAT=-1.0                              IUDB25     56
            IOUT=IDDAT(J2+1)                                            IUDB25     57
            LTYP1=IDDAT(JE3+17*IOUT-15)                                 IUDB25     58
            IF(JUDE(IOUT).EQ.0.AND.                                     IUDB25     59
     &      (LTYP1.NE.4.AND.LTYP1.NE.6)) THEN                           IUDB25     60
               NEXTB=IOUT                                               IUDB25     61
               XDATN=XDAT                                               IUDB25     62
            ELSE                                                        IUDB25     63
               VALI=VALI+VALOUT(IOUT)*XDAT                              IUDB25     64
            ENDIF                                                       IUDB25     65
         ENDIF                                                          IUDB25     66
  110    CONTINUE                                                       IUDB25     67
      ENDIF                                                             IUDB25     68
      J3=JE6-3                                                          IUDB25     69
      DO 120 J=1,INPUD                                                  IUDB25     70
      J3=J3+3                                                           IUDB25     71
      IF(IDDAT(J3+1).EQ.IORD) THEN                                      IUDB25     72
         IIN=IDDAT(J3+2)                                                IUDB25     73
         IF(IIN.EQ.20) THEN                                             IUDB25     74
            XDATN=DDAT(J3+3)                                            IUDB25     75
         ELSE                                                           IUDB25     76
            VALI=VALI+VALIN(IIN)*DDAT(J3+3)                             IUDB25     77
         ENDIF                                                          IUDB25     78
      ENDIF                                                             IUDB25     79
  120 CONTINUE                                                          IUDB25     80
C                                                                       IUDB25     81
      IF(INDEX.EQ.2) THEN                                               IUDB25     82
         VALO=VALOUT(IORD)                                              IUDB25     83
         IF(JORD.LT.NUDB) THEN                                          IUDB25     84
            IF(NEXTB.EQ.0)THEN                                          IUDB25     85
            MSG(1)='IUDB25: 1'                                          IUDB25     86
            CALL ASTOP(MSG(1),9)                                        IUDB25     87
            ENDIF                                                       IUDB25     88
            VALOUT(NEXTB)=(VALO*SUMA/SUMB-VALI)/XDATN                   IUDB25     89
         ELSE                                                           IUDB25     90
            VALIN(20)=(VALO*SUMA/SUMB-VALI)/XDATN                       IUDB25     91
         ENDIF                                                          IUDB25     92
         VALI=VALO*SUMA/SUMB                                            IUDB25     93
      ELSE                                                              IUDB25     94
         VALOUT(IORD)=VALI*SUMB/SUMA                                    IUDB25     95
      ENDIF                                                             IUDB25     96
C                                                                       IUDB25     97
      DO 130 L=1,5                                                      IUDB25     98
      SSMAT(JLS+L)=VALI                                                 IUDB25     99
      SSMAT(JLS+L+5)=VALOUT(IORD)                                       IUDB25    100
  130 CONTINUE                                                          IUDB25    101
      SSMAT(JLS+11)=VALI                                                IUDB25    102
      SSMAT(JLS+12)=0.0                                                 IUDB25    103
C                                                                       IUDB25    104
C                                                                       IUDB25    105
      RETURN                                                            IUDB25    106
 1000 FORMAT(' *** ERROR USER DEFINED MODEL AT BUS:',I5,' STATION: '    IUDB25    107
     *,3A4,' ID:',A4)                                                   IUDB25    108
 1050 FORMAT(11X,'BLOCK#',I3,'(',2A4                                    IUDB25    109
     *,') HAS UNACCEPTABLE SAMPLING TIME')                              IUDB25    110
 1060 FORMAT(11X,'(EITHER ZERO OR NEGATIVE).')                          IUDB25    111
      END                                                               IUDB25    112
