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