CFPRIME IUDB26                                                          IUDB26      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 IUDB26(IORD,INDEX,NLF,KN,CID)                          IUDB26      3
CD                                                                      IUDB26      4
CD    TO PERFORM INITIALIZATION FOR USER DEFINED BLOCK TYPE 23 (A/D     IUDB26      5
CD    BLOCK) IN ANY USER DEFINED MODEL.                                 IUDB26      6
CD                                                                      IUDB26      7
      INCLUDE 'PARX.INS'                                                IUDB26      8
      INCLUDE 'CNMDAT.INS'                                              IUDB26      9
      INCLUDE 'CNMSTA.INS'                                              IUDB26     10
      INCLUDE 'CNXSTA.INS'                                              IUDB26     11
      INCLUDE 'CNSTN.INS'                                               IUDB26     12
      INCLUDE 'CNYVAR.INS'                                              IUDB26     13
      INCLUDE 'CNUNIT.INS'                                              IUDB26     14
      INCLUDE 'CNFLAG.INS'                                              IUDB26     15
      INCLUDE 'CNMSG.INS'                                               IUDB26     16
      INCLUDE 'CNUDM.INS'                                               IUDB26     17
C                                                                       IUDB26     18
      CHARACTER*2 CID                                                   IUDB26     19
      DIMENSION XX(11)                                                  IUDB26     20
C                                                                       IUDB26     21
      LDEB=(JDEB(262).NE.0)                                             IUDB26     22
C                                                                       IUDB26     23
      VALI=0.0                                                          IUDB26     24
      NEXTB=0                                                           IUDB26     25
      JORD=JUDE(IORD)                                                   IUDB26     26
      JEI=JEB+2                                                         IUDB26     27
      NX=IDDAT(JEI+1)                                                   IUDB26     28
      IF(NX.LE.1.OR.NX.GT.11) THEN                                      IUDB26     29
         WRITE(MSG(1),1010) NLF,INAME(KN-2),INAME(KN-1),INAME(KN),CID   IUDB26     30
         WRITE(MSG(2),1060) IORD,BLNAM1,BLNAM2                          IUDB26     31
         WRITE(MSG(3),1070)                                             IUDB26     32
         CALL PRTMSG(3)                                                 IUDB26     33
         MSG(1)='IUDB26: UDM ERROR'                                     IUDB26     34
         CALL ASTOP(MSG(1),17)                                          IUDB26     35
      ENDIF                                                             IUDB26     36
      DO 100 I=1,NX                                                     IUDB26     37
      XX(I)=DDAT(JEI+I+1)                                               IUDB26     38
      IF(I.GT.1) THEN                                                   IUDB26     39
         IF(XX(I).LE.XX(I-1))THEN                                       IUDB26     40
         WRITE(MSG(1),1010) NLF,INAME(KN-2),INAME(KN-1),INAME(KN),CID   IUDB26     41
         WRITE(MSG(2),1020) IORD,BLNAM1,BLNAM2                          IUDB26     42
         WRITE(MSG(3),1030) (DDAT(JEI+J+1),J=1,6)                       IUDB26     43
         WRITE(MSG(4),1031) (DDAT(JEI+J+1),J=7,NX)                      IUDB26     44
         CALL PRTMSG(4)                                                 IUDB26     45
         MSG(1)='IUDB26: UDM ERROR'                                     IUDB26     46
         CALL ASTOP(MSG(1),17)                                          IUDB26     47
         ENDIF                                                          IUDB26     48
      ENDIF                                                             IUDB26     49
  100 CONTINUE                                                          IUDB26     50
C                                                                       IUDB26     51
      IF(INDEX.EQ.1.OR.INDEX.EQ.2) THEN                                 IUDB26     52
         J2=JE5-2                                                       IUDB26     53
         DO 110 J=1,INTUD                                               IUDB26     54
         J2=J2+2                                                        IUDB26     55
         IDD=IDDAT(J2+2)                                                IUDB26     56
         IDD=ABS(IDD)                                                   IUDB26     57
         IF(IDD.EQ.IORD) THEN                                           IUDB26     58
            XDAT=1.0                                                    IUDB26     59
            IF(IDDAT(J2+2).LT.0) XDAT=-1.0                              IUDB26     60
            IOUT=IDDAT(J2+1)                                            IUDB26     61
            LTYP1=IDDAT(JE3+17*IOUT-15)                                 IUDB26     62
            IF(JUDE(IOUT).EQ.0.AND.                                     IUDB26     63
     &      (LTYP1.NE.4.AND.LTYP1.NE.6)) THEN                           IUDB26     64
               NEXTB=IOUT                                               IUDB26     65
               XDATN=XDAT                                               IUDB26     66
            ELSE                                                        IUDB26     67
               VALI=VALI+VALOUT(IOUT)*XDAT                              IUDB26     68
            ENDIF                                                       IUDB26     69
         ENDIF                                                          IUDB26     70
  110    CONTINUE                                                       IUDB26     71
      ENDIF                                                             IUDB26     72
      J3=JE6-3                                                          IUDB26     73
      DO 120 J=1,INPUD                                                  IUDB26     74
      J3=J3+3                                                           IUDB26     75
      IF(IDDAT(J3+1).EQ.IORD) THEN                                      IUDB26     76
         IIN=IDDAT(J3+2)                                                IUDB26     77
         IF(IIN.EQ.20) THEN                                             IUDB26     78
            XDATN=DDAT(J3+3)                                            IUDB26     79
         ELSE                                                           IUDB26     80
            VALI=VALI+VALIN(IIN)*DDAT(J3+3)                             IUDB26     81
         ENDIF                                                          IUDB26     82
      ENDIF                                                             IUDB26     83
  120 CONTINUE                                                          IUDB26     84
      IF(INDEX.EQ.2) THEN                                               IUDB26     85
         VALO=VALOUT(IORD)                                              IUDB26     86
         IF(VALO.LT.XX(1)) THEN                                         IUDB26     87
            WRITE(MSG(1),1010) NLF,INAME(KN-2),INAME(KN-1)              IUDB26     88
     *                        ,INAME(KN),CID                            IUDB26     89
            WRITE(MSG(2),1040) IORD,BLNAM1,BLNAM2                       IUDB26     90
            WRITE(MSG(3),1050)                                          IUDB26     91
            CALL PRTMSG(3)                                              IUDB26     92
         GO TO 140                                                      IUDB26     93
         ENDIF                                                          IUDB26     94
         DO 130 I=2,NX                                                  IUDB26     95
         IF(VALO.LT.XX(I))THEN                                          IUDB26     96
            RATIO=(VALO-XX(I-1))/(XX(I)-XX(I-1))                        IUDB26     97
            IF(RATIO.GT.0.001) THEN                                     IUDB26     98
            WRITE(MSG(1),1010) NLF,INAME(KN-2),INAME(KN-1)              IUDB26     99
     *                        ,INAME(KN),CID                            IUDB26    100
            WRITE(MSG(2),1040) IORD,BLNAM1,BLNAM2                       IUDB26    101
            WRITE(MSG(3),1050)                                          IUDB26    102
            CALL PRTMSG(3)                                              IUDB26    103
            ENDIF                                                       IUDB26    104
            GO TO 140                                                   IUDB26    105
         ENDIF                                                          IUDB26    106
  130    CONTINUE                                                       IUDB26    107
         IF(VALO.GT.XX(NX)) THEN                                        IUDB26    108
            WRITE(MSG(1),1010) NLF,INAME(KN-2),INAME(KN-1)              IUDB26    109
     *                        ,INAME(KN),CID                            IUDB26    110
            WRITE(MSG(2),1040) IORD,BLNAM1,BLNAM2                       IUDB26    111
            WRITE(MSG(3),1050)                                          IUDB26    112
            CALL PRTMSG(3)                                              IUDB26    113
         ENDIF                                                          IUDB26    114
  140    CONTINUE                                                       IUDB26    115
         IF(JORD.LT.NUDB) THEN                                          IUDB26    116
            IF(NEXTB.EQ.0)THEN                                          IUDB26    117
            MSG(1)='IUDB26: 1'                                          IUDB26    118
            CALL ASTOP(MSG(1),9)                                        IUDB26    119
            ENDIF                                                       IUDB26    120
            VALOUT(NEXTB)=(VALO-VALI)/XDATN                             IUDB26    121
         ELSE                                                           IUDB26    122
            VALIN(20)=(VALO-VALI)/XDATN                                 IUDB26    123
         ENDIF                                                          IUDB26    124
      ELSE                                                              IUDB26    125
         DO 150 I=2,NX                                                  IUDB26    126
         IF(VALI.LT.XX(I))THEN                                          IUDB26    127
            VALO=XX(I-1)                                                IUDB26    128
            GO TO 160                                                   IUDB26    129
         ENDIF                                                          IUDB26    130
  150    CONTINUE                                                       IUDB26    131
         VALO=XX(NX)                                                    IUDB26    132
  160    VALOUT(IORD)=VALO                                              IUDB26    133
      ENDIF                                                             IUDB26    134
C                                                                       IUDB26    135
      IF(LDEB)WRITE(IUD6,1000) JORD                                     IUDB26    136
C                                                                       IUDB26    137
      RETURN                                                            IUDB26    138
 1000 FORMAT(1X,'JORD: ',I5)                                            IUDB26    139
 1010 FORMAT(' *** ERROR USER DEFINED MODEL AT BUS:',I5,' STATION: '    IUDB26    140
     *,3A4,' ID:',A4)                                                   IUDB26    141
 1020 FORMAT(11X,'IN BLOCK#',I3,' (',2A4                                IUDB26    142
     *,') X VALUES MUST BE IN INCREASING ORDER.')                       IUDB26    143
 1030 FORMAT(11X,'X VALUES: ',6F8.3)                                    IUDB26    144
 1031 FORMAT(21X,5F8.3)                                                 IUDB26    145
 1040 FORMAT(11X,'IN BLOCK#',I3,' (',2A4                                IUDB26    146
     *,') THE OUTPUT IS BETWEEN STEPS OR')                              IUDB26    147
 1050 FORMAT(11X                                                        IUDB26    148
     *,'OUTSIDE LIMITS. IT WILL MOVE AT THE FIRST TIME STEP.')          IUDB26    149
 1060 FORMAT(11X,'BLOCK#',I3,' (',2A4                                   IUDB26    150
     *,') NX MUST BE LARGER THAN 1')                                    IUDB26    151
 1070 FORMAT(11X,'BUT NOT LARGER THAN 11.')                             IUDB26    152
      END                                                               IUDB26    153
