CFPRIME UDINIT                                                          UDINIT      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  UDINIT                                                UDINIT      3
CD -------------------------------------------------------------------  UDINIT      4
CD                                                                      UDINIT      5
CD              *****     UDINIT  ROUTINE   *****                       UDINIT      6
CD                                                                      UDINIT      7
CD -------------------------------------------------------------------  UDINIT      8
CD                                                                      UDINIT      9
CD       PURPOSE:  Performs the initialization of the UDC system.       UDINIT     10
CD                 Attempts to stabilize the loops and subsystems.      UDINIT     11
CD                                                                      UDINIT     12
CD                                                                      UDINIT     13
CD       DEFINITION OF LOCAL VARIABLES:                                 UDINIT     14
CD                 JBLK    -  current udc block.                        UDINIT     15
CD                 BNAME  -  current udc block name.                    UDINIT     16
CD                 FOUND  -  search for block was successful.           UDINIT     17
CD                 I      - 'do' loop index.                            UDINIT     18
CD                 INBLK  -  list of input blocks to this block.        UDINIT     19
CD                 J      - 'do' loop index.                            UDINIT     20
CD                 LABEL  -  title for printing.                        UDINIT     21
CD                 LAST   -  previous pointer in linked list.           UDINIT     22
CD                 LEN    -  length of current udc block name.          UDINIT     23
CD                 NEXT   -  current pointer in linked list.            UDINIT     24
CD                 OK     -  indicates if the desired and calculated    UDINIT     25
CD                           values are ok.                             UDINIT     26
CD                 LORDER -  pointer to the next block in solution      UDINIT     27
CD                           order.                                     UDINIT     28
CD                 SNAME  -  udc subtype name.                          UDINIT     29
CD                 TNAME  -  udc type name.                             UDINIT     30
CD                                                                      UDINIT     31
CD -------------------------------------------------------------------  UDINIT     32
      INCLUDE 'CNUNIT.INS'                                              UDINIT     33
      INCLUDE 'PARX.INS'                                                UDINIT     34
      INCLUDE 'UDCA.INS'                                                UDINIT     35
      INCLUDE 'UDCB.INS'                                                UDINIT     36
      INCLUDE 'UDCD.INS'                                                UDINIT     37
      INCLUDE 'UDCE.INS'                                                UDINIT     38
      INCLUDE 'UDCH.INS'                                                UDINIT     39
      INCLUDE 'CNFLAG.INS'                                              UDINIT     40
C                                                                       UDINIT     41
      DIMENSION       INBLK(10),LEN(10)                                 UDINIT     42
C                                                                       UDINIT     43
      LOGICAL       FOUND,OK,LDEB1                                      UDINIT     44
C                                                                       UDINIT     45
      CHARACTER*50  LABEL                                               UDINIT     46
      CHARACTER*17  BNAME(10)                                           UDINIT     47
      CHARACTER*8   SNAME, TNAME                                        UDINIT     48
C                                                                       UDINIT     49
C                                                                       UDINIT     50
C---------------------------------------------------------------------  UDINIT     51
C                                                                       UDINIT     52
      LDEB=(JDEB(304).NE.0)                                             UDINIT     53
      LDEB1=(JDEB(305).NE.0)                                            UDINIT     54
C                                                                       UDINIT     55
C     Initialize all blocks in the system to zero.                      UDINIT     56
C                                                                       UDINIT     57
      DO 20 I = 1, IUDC                                                 UDINIT     58
         UDVAL(I) = 0.0                                                 UDINIT     59
         UDOU2(I) = ' '                                                 UDINIT     60
         UDVA3(I) = 0.0                                                 UDINIT     61
         UDOU4(I) = ' '                                                 UDINIT     62
20    CONTINUE                                                          UDINIT     63
C                                                                       UDINIT     64
C     Initialize all blocks on the start list to their specified value. UDINIT     65
C                                                                       UDINIT     66
      IF(IFXSTR .NE. 0)THEN                                             UDINIT     67
         NEXT = IFXSTR                                                  UDINIT     68
         LAST = NEXT                                                    UDINIT     69
40       IF(NEXT.EQ.0) GOTO 60                                          UDINIT     70
C                                                                       UDINIT     71
C           Set this block to its initial value.                        UDINIT     72
C                                                                       UDINIT     73
            IF(FXNAM2(NEXT).EQ.' ')THEN                                 UDINIT     74
               UDVAL(IFXNUM(NEXT)) = FXVAL(NEXT)                        UDINIT     75
            END IF                                                      UDINIT     76
            NEXT = IFXNEX(NEXT)                                         UDINIT     77
            GOTO 40                                                     UDINIT     78
60       CONTINUE                                                       UDINIT     79
C                                                                       UDINIT     80
      END IF                                                            UDINIT     81
C                                                                       UDINIT     82
C                                                                       UDINIT     83
C     Initialize all the run mode blocks, using the run mode list and   UDINIT     84
C     the interface list.                                               UDINIT     85
C                                                                       UDINIT     86
      IF(IFXRMO .NE. 0)THEN                                             UDINIT     87
         NEXT = IFXRMO                                                  UDINIT     88
80       IF(NEXT.EQ.0) GOTO 140                                         UDINIT     89
C                                                                       UDINIT     90
C           Search the interface block list for this converter number.  UDINIT     91
C                                                                       UDINIT     92
            FOUND = .FALSE.                                             UDINIT     93
            NXT = IFXINT                                                UDINIT     94
100         IF(FOUND .OR. NXT.EQ.0) GOTO 120                            UDINIT     95
               IF(IFXNUM(NEXT).EQ.IFXNUM(NXT))THEN                      UDINIT     96
                  FOUND = .TRUE.                                        UDINIT     97
                  JFXNUM(NEXT) = JFXNUM(NXT)                            UDINIT     98
                  UDVAL(IFINUM(NEXT)) = REAL (JFXNUM(NEXT))             UDINIT     99
               ELSE                                                     UDINIT    100
                  NXT = IFXNEX(NXT)                                     UDINIT    101
               END IF                                                   UDINIT    102
               GOTO 100                                                 UDINIT    103
120         CONTINUE                                                    UDINIT    104
            NEXT = IFXNEX(NEXT)                                         UDINIT    105
            GOTO 80                                                     UDINIT    106
140      CONTINUE                                                       UDINIT    107
      END IF                                                            UDINIT    108
C                                                                       UDINIT    109
C                                                                       UDINIT    110
C     Delete the interface block list.                                  UDINIT    111
C                                                                       UDINIT    112
      IF(IFXINT .NE. 0)THEN                                             UDINIT    113
         IFXNEX(IFXLST) = IFXFRE                                        UDINIT    114
         IFXFRE = IFXINT                                                UDINIT    115
         IFXINT = 0                                                     UDINIT    116
         IFXLST = 0                                                     UDINIT    117
      END IF                                                            UDINIT    118
C                                                                       UDINIT    119
C     Evaluate each udc block in solution order.                        UDINIT    120
C                                                                       UDINIT    121
      LORDER = 1                                                        UDINIT    122
160   IF(LORDER .GT. IUDC)  GOTO 280                                    UDINIT    123
         JBLK = IUDPRM(LORDER)                                          UDINIT    124
C                                                                       UDINIT    125
C        Check if stack processing should begin.                        UDINIT    126
C                                                                       UDINIT    127
         FOUND = .TRUE.                                                 UDINIT    128
180      IF(.NOT. FOUND) GOTO 220                                       UDINIT    129
            CALL UILOOP (JBLK, LORDER)                                  UDINIT    130
            FOUND = .FALSE.                                             UDINIT    131
            DO 200 I = 1, LPMAX                                         UDINIT    132
               NEXT = LPTOP(I)                                          UDINIT    133
               IF(JBLK.EQ.LPNUM(NEXT))THEN                              UDINIT    134
C                                                                       UDINIT    135
C                 Recognized a block which begins a loop or subsystem.  UDINIT    136
C                                                                       UDINIT    137
                  FOUND = .TRUE.                                        UDINIT    138
               END IF                                                   UDINIT    139
200         CONTINUE                                                    UDINIT    140
            GOTO 180                                                    UDINIT    141
220      CONTINUE                                                       UDINIT    142
C                                                                       UDINIT    143
C                                                                       UDINIT    144
C        No more stack processing is needed.                            UDINIT    145
C                                                                       UDINIT    146
         IF(LORDER .LE. IUDC)THEN                                       UDINIT    147
C                                                                       UDINIT    148
C           Evaluate the output value for this block.                   UDINIT    149
C                                                                       UDINIT    150
            TNAME = TPNAME(IUDTYP(JBLK))                                UDINIT    151
C                                                                       UDINIT    152
            IF(IUDTYP(JBLK).EQ.IACSYS)THEN                              UDINIT    153
C               SNAME = SBACSY(IUDSUB(JBLK))                            UDINIT    154
C               CALL UIACSY (JBLK)                                      UDINIT    155
            ELSEIF(IUDTYP(JBLK).EQ.IBINAR)THEN                          UDINIT    156
               SNAME = SBBIN(IUDSUB(JBLK))                              UDINIT    157
               CALL UIBIN (JBLK)                                        UDINIT    158
            ELSEIF(IUDTYP(JBLK).EQ.IBREAK)THEN                          UDINIT    159
               SNAME = SBBRKR(IUDSUB(JBLK))                             UDINIT    160
               CALL UIBRKR (JBLK)                                       UDINIT    161
            ELSEIF(IUDTYP(JBLK).EQ.IFRTRA)THEN                          UDINIT    162
               SNAME = SBFORT(IUDSUB(JBLK))                             UDINIT    163
               CALL UIFORT(JBLK)                                        UDINIT    164
            ELSEIF(IUDTYP(JBLK).EQ.IFRMAC)THEN                          UDINIT    165
               SNAME = SBFRAC(IUDSUB(JBLK))                             UDINIT    166
               CALL UIFRAC (JBLK)                                       UDINIT    167
            ELSEIF(IUDTYP(JBLK).EQ.IFRMDC)THEN                          UDINIT    168
               SNAME = SBFRDC(IUDSUB(JBLK))                             UDINIT    169
               CALL UIFRDC (JBLK)                                       UDINIT    170
            ELSEIF(IUDTYP(JBLK).EQ.INTERF)THEN                          UDINIT    171
               SNAME = ' '                                              UDINIT    172
               CALL UIINTF (JBLK, OK)                                   UDINIT    173
            ELSEIF(IUDTYP(JBLK).EQ.LIMITR)THEN                          UDINIT    174
               SNAME = SBLIMT(IUDSUB(JBLK))                             UDINIT    175
               CALL UILIMT (JBLK)                                       UDINIT    176
            ELSEIF(IUDTYP(JBLK).EQ.LOGIC)THEN                           UDINIT    177
               SNAME = SBLOGC(IUDSUB(JBLK))                             UDINIT    178
               CALL UILOGC (JBLK)                                       UDINIT    179
            ELSEIF(IUDTYP(JBLK).EQ.MULTI)THEN                           UDINIT    180
               SNAME = SBMLTP(IUDSUB(JBLK))                             UDINIT    181
               CALL UIMLTP (JBLK)                                       UDINIT    182
            ELSEIF(IUDTYP(JBLK).EQ.IPRTR)THEN                           UDINIT    183
               SNAME = SBPRT(IUDSUB(JBLK))                              UDINIT    184
               CALL UIPRT (JBLK)                                        UDINIT    185
            ELSEIF(IUDTYP(JBLK).EQ.IOTHER)THEN                          UDINIT    186
               SNAME = SBOTHR(IUDSUB(JBLK))                             UDINIT    187
               CALL UIOTHR (JBLK)                                       UDINIT    188
            ELSEIF(IUDTYP(JBLK).EQ.ISBLCK)THEN                          UDINIT    189
               SNAME = SBSBLK(IUDSUB(JBLK))                             UDINIT    190
               CALL UISBLK (JBLK)                                       UDINIT    191
            ELSEIF(IUDTYP(JBLK).EQ.ISETUP)THEN                          UDINIT    192
               SNAME = SBSETP(IUDSUB(JBLK))                             UDINIT    193
               CALL UISETP (JBLK)                                       UDINIT    194
            ELSEIF(IUDTYP(JBLK).EQ.ISOURC)THEN                          UDINIT    195
               SNAME = SBSRCE(IUDSUB(JBLK))                             UDINIT    196
               CALL UISRCE (JBLK)                                       UDINIT    197
            ELSEIF(IUDTYP(JBLK).EQ.ISUBSY)THEN                          UDINIT    198
               SNAME = SBSUBS(IUDSUB(JBLK))                             UDINIT    199
               CALL UISUBS (JBLK, OK)                                   UDINIT    200
            ELSEIF(IUDTYP(JBLK).EQ.IUDUMY)THEN                          UDINIT    201
C                                                                       UDINIT    202
C              The dummy blocks are initialized by the routine          UDINIT    203
C              'UIFORT', when the corresponding FORTRAN routine         UDINIT    204
C              is initialized.                                          UDINIT    205
C                                                                       UDINIT    206
            ELSEIF(IUDTYP(JBLK).EQ.IUNARY)THEN                          UDINIT    207
               SNAME = SBUNA(IUDSUB(JBLK))                              UDINIT    208
               CALL UIUNA (JBLK)                                        UDINIT    209
            END IF                                                      UDINIT    210
C                                                                       UDINIT    211
            IF(LDEB.AND.LDEB1)THEN                                      UDINIT    212
               WRITE (IUD6,9002) UDNAME(JBLK), TNAME, SNAME, UDVAL(JBLK)UDINIT    213
               I = 0                                                    UDINIT    214
               NEXT = INTOP(JBLK)                                       UDINIT    215
240            IF(NEXT.EQ.0) GOTO 260                                   UDINIT    216
                  I = I + 1                                             UDINIT    217
                  INBLK(I) = INNUM(NEXT)                                UDINIT    218
                  BNAME(I) = UDNAME(INBLK(I))                           UDINIT    219
                  LEN(I) = IUDLEN(INBLK(I))                             UDINIT    220
                  NEXT = IPOINT(NEXT)                                   UDINIT    221
                  GOTO 240                                              UDINIT    222
260            CONTINUE                                                 UDINIT    223
               IF(I.EQ.0)THEN                                           UDINIT    224
                  WRITE (IUD6,9004)                                     UDINIT    225
               ELSE                                                     UDINIT    226
                  WRITE (IUD6,9006) (BNAME(J)(1:LEN(J)),J = 1, I)       UDINIT    227
               END IF                                                   UDINIT    228
            END IF                                                      UDINIT    229
C                                                                       UDINIT    230
C                                                                       UDINIT    231
C           Next block is the next block in solution order.             UDINIT    232
C                                                                       UDINIT    233
            LORDER = IUDINV(JBLK)                                       UDINIT    234
            LORDER = LORDER + 1                                         UDINIT    235
            JBLK = IUDPRM(LORDER)                                       UDINIT    236
         END IF                                                         UDINIT    237
C                                                                       UDINIT    238
         GOTO 160                                                       UDINIT    239
280   CONTINUE                                                          UDINIT    240
C                                                                       UDINIT    241
C---------------------------------------------------------------------  UDINIT    242
C                                                                       UDINIT    243
      IF(LDEB)THEN                                                      UDINIT    244
         LABEL = '***  UDC BLOCK VALUES AFTER INITIALIZATION  ***'      UDINIT    245
         WRITE (IUD6,9008) LABEL                                        UDINIT    246
         DO 300 I = 1, IUDC                                             UDINIT    247
            J = IUDPRM(I)                                               UDINIT    248
            WRITE (IUD6,9010) UDNAME(J), UDVAL(J)                       UDINIT    249
300      CONTINUE                                                       UDINIT    250
      END IF                                                            UDINIT    251
C                                                                       UDINIT    252
C                                                                       UDINIT    253
C---------------------------------------------------------------------  UDINIT    254
C                                                                       UDINIT    255
      RETURN                                                            UDINIT    256
C                                                                       UDINIT    257
C---------------------------------------------------------------------  UDINIT    258
C                                                                       UDINIT    259
9002  FORMAT (/, ' BLOCK: ', A, 2X, 'TYPE: ', A, 2X, 'SUBTYPE: ',       UDINIT    260
     1        A, 2X, 'VALUE: ', F12.6)                                  UDINIT    261
9004  FORMAT (' INPUTS:  ** NONE **')                                   UDINIT    262
9006  FORMAT (' INPUTS:  ', 10(A, 3X))                                  UDINIT    263
9008  FORMAT (///, '1', 20X, A, /)                                      UDINIT    264
9010  FORMAT (5X, 'BLOCK: ', A, 10X, 'VALUE: ', F15.6)                  UDINIT    265
C                                                                       UDINIT    266
C---------------------------------------------------------------------  UDINIT    267
C                                                                       UDINIT    268
      END                                                               UDINIT    269
