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