CFPRIME USBIN                                                           USBIN       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  USBIN (JBLK)                                          USBIN       3
CD -------------------------------------------------------------------  USBIN       4
CD                                                                      USBIN       5
CD              *****     USBIN   ROUTINE   *****                       USBIN       6
CD                                                                      USBIN       7
CD -------------------------------------------------------------------  USBIN       8
CD                                                                      USBIN       9
CD       PURPOSE:  Performs the solution of the udc type BINARY.        USBIN      10
CD                                                                      USBIN      11
CD                                                                      USBIN      12
CD       DEFINITION OF LOCAL VARIABLES:                                 USBIN      13
CD          (P)    BLK    -  current udc block.                         USBIN      14
CD                 BNAME  -  current udc block name.                    USBIN      15
CD                 LEN    -  length of current udc block name.          USBIN      16
CD                 SUBNAM -  subroutine name.                           USBIN      17
CD                 TNAME  -  udc type name.                             USBIN      18
CD                 VALUE1 -  first operand of binary function.          USBIN      19
CD                 VALUE2 -  second operand of binary function.         USBIN      20
CD                                                                      USBIN      21
CD -------------------------------------------------------------------  USBIN      22
C                                                                       USBIN      23
      INCLUDE 'PARX.INS'                                                USBIN      24
      INCLUDE 'CNPARX.INS'                                              USBIN      25
      INCLUDE 'GRDC01.INS'                                              USBIN      26
      INCLUDE 'GRDC03.INS'                                              USBIN      27
      INCLUDE 'UDCA.INS'                                                USBIN      28
      INCLUDE 'UDCD.INS'                                                USBIN      29
      INCLUDE 'UDCE.INS'                                                USBIN      30
      INCLUDE 'UDCF.INS'                                                USBIN      31
      INCLUDE 'UDCG.INS'                                                USBIN      32
      INCLUDE 'UDCH.INS'                                                USBIN      33
      INCLUDE 'UDCJ.INS'                                                USBIN      34
      INCLUDE 'CNUNIT.INS'                                              USBIN      35
      INCLUDE 'CNMSG.INS'                                               USBIN      36
C                                                                       USBIN      37
      LOGICAL       LIMIT, DONE, AGAIN                                  USBIN      38
C                                                                       USBIN      39
      DIMENSION     XINPUT(20),OUTPUT(10)                               USBIN      40
      DIMENSION  AA(11), B(10), C(10), CC(10), H(10),OLDX(10),IPVT(10)  USBIN      41
C                                                                       USBIN      42
      DOUBLE PRECISION    A(10,10), X(10)                               USBIN      43
      DOUBLE PRECISION     CK1, CK2                                     USBIN      44
C                                                                       USBIN      45
      CHARACTER*72  STRING                                              USBIN      46
      CHARACTER*20  SUBNAM                                              USBIN      47
      CHARACTER*17  BNAME                                               USBIN      48
      CHARACTER*8   TNAME                                               USBIN      49
      CHARACTER*1   MODE                                                USBIN      50
C                                                                       USBIN      51
      INCLUDE 'GRBIN.INS'                                               USBIN      52
      INCLUDE 'GRFRDC.INS'                                              USBIN      53
      INCLUDE 'GRMLTP.INS'                                              USBIN      54
      INCLUDE 'GRSBLK.INS'                                              USBIN      55
      INCLUDE 'GRSRCE.INS'                                              USBIN      56
      INCLUDE 'GRFRAC.INS'                                              USBIN      57
C                                                                       USBIN      58
      DATA          JGROUN /0/                                          USBIN      59
C                                                                       USBIN      60
      IF(SDBG)THEN                                                      USBIN      61
         SUBNAM = 'USBIN ROUTINE.'                                      USBIN      62
      ELSE                                                              USBIN      63
         SUBNAM = ' '                                                   USBIN      64
      END IF                                                            USBIN      65
      TNAME = TPNAME(IBINAR)                                            USBIN      66
      BNAME = UDNAME(JBLK)                                              USBIN      67
      LEN = IUDLEN(JBLK)                                                USBIN      68
C                                                                       USBIN      69
C                                                                       USBIN      70
C                                                                       USBIN      71
C     Retrieve input values.                                            USBIN      72
C                                                                       USBIN      73
      NEXTI = IUNIPT(JBLK)                                              USBIN      74
      NEXTP = IUDPPT(JBLK)                                              USBIN      75
      IF(UIDENT(NEXTI) .NE. ' ')THEN                                    USBIN      76
         VALUE1 = UDVAL(IUDINT(NEXTI))                                  USBIN      77
      ELSE                                                              USBIN      78
         VALUE1 = UDPARM(NEXTP)                                         USBIN      79
      END IF                                                            USBIN      80
C                                                                       USBIN      81
      NEXTI = IUDINX(NEXTI)                                             USBIN      82
      NEXTP = IUDPNX(NEXTP)                                             USBIN      83
      IF(UIDENT(NEXTI) .NE. ' ')THEN                                    USBIN      84
         VALUE2 = UDVAL(IUDINT(NEXTI))                                  USBIN      85
      ELSE                                                              USBIN      86
         VALUE2 = UDPARM(NEXTP)                                         USBIN      87
      END IF                                                            USBIN      88
C                                                                       USBIN      89
C     Calculate UDVAL.                                                  USBIN      90
C                                                                       USBIN      91
C                                                                       USBIN      92
C     PLUS subtype.                                                     USBIN      93
C                                                                       USBIN      94
      IF(IUDSUB(JBLK).EQ.IPLUSS)THEN                                    USBIN      95
         UDVAL(JBLK) = VALUE1 + VALUE2                                  USBIN      96
C                                                                       USBIN      97
C                                                                       USBIN      98
C     MINUS subtype.                                                    USBIN      99
C                                                                       USBIN     100
      ELSEIF(IUDSUB(JBLK).EQ.MINUSS)THEN                                USBIN     101
         UDVAL(JBLK) = VALUE1 - VALUE2                                  USBIN     102
C                                                                       USBIN     103
C                                                                       USBIN     104
C     MULT subtype.                                                     USBIN     105
C                                                                       USBIN     106
      ELSEIF(IUDSUB(JBLK).EQ.MULTS)THEN                                 USBIN     107
         UDVAL(JBLK) = VALUE1 * VALUE2                                  USBIN     108
C                                                                       USBIN     109
C                                                                       USBIN     110
C     DIV subtype.                                                      USBIN     111
C                                                                       USBIN     112
      ELSEIF(IUDSUB(JBLK).EQ.IDIVS)THEN                                 USBIN     113
         IF(VALUE2 .NE. 0.0)THEN                                        USBIN     114
            UDVAL(JBLK) = VALUE1 / VALUE2                               USBIN     115
         ELSE                                                           USBIN     116
            UDVAL(JBLK) = 99.0                                          USBIN     117
            WRITE (MSG(1),9000) SUBNAM                                  USBIN     118
            WRITE(MSG(2),9001) TNAME                                    USBIN     119
            WRITE(MSG(3),9002) BNAME(1:LEN)                             USBIN     120
            WRITE(MSG(4),9003)                                          USBIN     121
            CALL PRTMSG(4)                                              USBIN     122
            IERCNT = IERCNT + 1                                         USBIN     123
         END IF                                                         USBIN     124
C                                                                       USBIN     125
C                                                                       USBIN     126
C     Power subtype.                                                    USBIN     127
C                                                                       USBIN     128
      ELSEIF(IUDSUB(JBLK).EQ.IPOWER)THEN                                USBIN     129
         IF(VALUE1 .LT. 0.0)THEN                                        USBIN     130
            VALUE1 = 0.0                                                USBIN     131
         END IF                                                         USBIN     132
         UDVAL(JBLK) = VALUE1 ** VALUE2                                 USBIN     133
C                                                                       USBIN     134
      END IF                                                            USBIN     135
C                                                                       USBIN     136
      RETURN                                                            USBIN     137
C                                                                       USBIN     138
C                                                                       USBIN     139
C---------------------------------------------------------------------  USBIN     140
C                                                                       USBIN     141
      ENTRY USFORT (JBLK)                                               USBIN     142
CD -------------------------------------------------------------------  USBIN     143
CD                                                                      USBIN     144
CD              *****     USFORT  ROUTINE   *****                       USBIN     145
CD                                                                      USBIN     146
CD -------------------------------------------------------------------  USBIN     147
CD                                                                      USBIN     148
CD       PURPOSE:  Performs the solution of the udc type FORTRN.        USBIN     149
CD                                                                      USBIN     150
CD -------------------------------------------------------------------  USBIN     151
C                                                                       USBIN     152
      IF(SDBG)THEN                                                      USBIN     153
         SUBNAM = 'USFORT ROUTINE.'                                     USBIN     154
      ELSE                                                              USBIN     155
         SUBNAM = ' '                                                   USBIN     156
      END IF                                                            USBIN     157
C                                                                       USBIN     158
      MODE = 'S'                                                        USBIN     159
      MAXIN = 20                                                        USBIN     160
      MAXOUT = 10                                                       USBIN     161
      TNAME = TPNAME(IFRTRA)                                            USBIN     162
      BNAME = UDNAME(JBLK)                                              USBIN     163
      LEN = IUDLEN(JBLK)                                                USBIN     164
C                                                                       USBIN     165
      I = 0                                                             USBIN     166
      NEXTI = IUNIPT(JBLK)                                              USBIN     167
      NEXTP = IUDPPT(JBLK)                                              USBIN     168
C                                                                       USBIN     169
C     Retrieve the input parameters.                                    USBIN     170
C                                                                       USBIN     171
100   CONTINUE                                                          USBIN     172
      DONE = (NEXTI.EQ.0)                                               USBIN     173
      IF(DONE) GOTO 110                                                 USBIN     174
C                                                                       USBIN     175
      I = I + 1                                                         USBIN     176
      IF(I .GT. MAXIN)THEN                                              USBIN     177
         IERCNT = IERCNT + 1                                            USBIN     178
         WRITE(MSG(1),9000) SUBNAM                                      USBIN     179
         WRITE(MSG(2),9005)                                             USBIN     180
         WRITE(MSG(3),9006) I,BNAME(1:LEN)                              USBIN     181
         WRITE(MSG(4),9007) MAXIN                                       USBIN     182
         CALL PRTMSG(4)                                                 USBIN     183
         GOTO 110                                                       USBIN     184
      END IF                                                            USBIN     185
C                                                                       USBIN     186
      IF(UIDENT(NEXTI) .NE. ' ')THEN                                    USBIN     187
         XINPUT(I) = UDVAL(IUDINT(NEXTI))                               USBIN     188
      ELSE                                                              USBIN     189
         XINPUT(I) = UDPARM(NEXTP)                                      USBIN     190
      END IF                                                            USBIN     191
C                                                                       USBIN     192
      NEXTI = IUDINX(NEXTI)                                             USBIN     193
      NEXTP = IUDPNX(NEXTP)                                             USBIN     194
      GOTO 100                                                          USBIN     195
C                                                                       USBIN     196
110   CONTINUE                                                          USBIN     197
C                                                                       USBIN     198
      IF(I.EQ.0)THEN                                                    USBIN     199
         WRITE(MSG(1),9004) SUBNAM                                      USBIN     200
         WRITE(MSG(2),9005)                                             USBIN     201
         WRITE(MSG(3),9010) BNAME(1:LEN)                                USBIN     202
         CALL PRTMSG(3)                                                 USBIN     203
      END IF                                                            USBIN     204
C                                                                       USBIN     205
      CALL FORTRN(JBLK,XINPUT,OUTPUT,MODE)                              USBIN     206
C                                                                       USBIN     207
      NUM = ISBFNU(IUDSUB(JBLK))                                        USBIN     208
C                                                                       USBIN     209
C     If no output parameters (or too many) were found, then issue an   USBIN     210
C     error message.                                                    USBIN     211
C                                                                       USBIN     212
      IF(NUM .LT. 1 .OR. NUM .GT. MAXOUT)THEN                           USBIN     213
         WRITE(MSG(1),9000) SUBNAM                                      USBIN     214
         WRITE(MSG(2),9005)                                             USBIN     215
         WRITE(MSG(3),9008) NUM,BNAME(1:LEN)                            USBIN     216
         WRITE(MSG(4),9009) MAXOUT                                      USBIN     217
         CALL PRTMSG(4)                                                 USBIN     218
         IERCNT = IERCNT + 1                                            USBIN     219
         IF(NUM .GT. MAXOUT) NUM = MAXOUT                               USBIN     220
      END IF                                                            USBIN     221
C                                                                       USBIN     222
C     Search the array FRTNAM to locate this particular block.          USBIN     223
C                                                                       USBIN     224
      JPTR = 0                                                          USBIN     225
      DO 115 I=1,IFRTBK                                                 USBIN     226
         IF(UDNAME(JBLK).EQ.FRTNAM(I))THEN                              USBIN     227
            JPTR = IDUMPT(I)                                            USBIN     228
         END IF                                                         USBIN     229
115   CONTINUE                                                          USBIN     230
C                                                                       USBIN     231
      IF(JPTR.EQ.0)THEN                                                 USBIN     232
         IERCNT = IERCNT + 1                                            USBIN     233
         WRITE(MSG(1),9000) SUBNAM                                      USBIN     234
         WRITE(MSG(2),9005)                                             USBIN     235
         WRITE(MSG(3),9008) NUM,BNAME(1:LEN)                            USBIN     236
         WRITE(MSG(4),9009) MAXOUT                                      USBIN     237
         CALL PRTMSG(4)                                                 USBIN     238
      ELSE                                                              USBIN     239
C                                                                       USBIN     240
C        Store the output values in the DUMMY blocks.                   USBIN     241
C                                                                       USBIN     242
         DO 120 I=1,NUM                                                 USBIN     243
            UDVAL(IDUMBK(JPTR)) = OUTPUT(I)                             USBIN     244
            JPTR = JPTR + 1                                             USBIN     245
120      CONTINUE                                                       USBIN     246
      END IF                                                            USBIN     247
C                                                                       USBIN     248
      RETURN                                                            USBIN     249
C                                                                       USBIN     250
9000  FORMAT(' *** ERROR', 5X, A)                                       USBIN     251
9001  FORMAT(11X,'DURING THE SOLUTION OF UDC "',A                       USBIN     252
     *,'" BLOCKS, THE BLOCK')                                           USBIN     253
9002  FORMAT(11X,'"', A, '" HAS A DIVIDE BY ZERO.  ',                   USBIN     254
     3        'THE RESULT OF THIS')                                     USBIN     255
9003  FORMAT(11X,'DIVISION IS SET TO NINETY-NINE.')                     USBIN     256
9004  FORMAT(' *** WARNING', 5X, A)                                     USBIN     257
9005  FORMAT(11X,'DURING THE SOLUTION OF UDC "FORTRAN" BLOCKS, ',       USBIN     258
     2       'THERE')                                                   USBIN     259
9010  FORMAT(11X,'WERE NO INPUT PARAMETERS FOUND ',                     USBIN     260
     3       'FOR BLOCK, "', A, '".')                                   USBIN     261
9006  FORMAT(11X,'WERE ',I3,' INPUT PARAMETERS FOUND ',                 USBIN     262
     3       'FOR BLOCK, "', A, '".')                                   USBIN     263
9007  FORMAT(11X,'MAXIMUM IS ', I3)                                     USBIN     264
9008  FORMAT(11X,'WERE ', I3, ' OUTPUT PARAMTERS FOUND ',               USBIN     265
     3       'FOR BLOCK, "', A, '".')                                   USBIN     266
9009  FORMAT(11X,'MAXIMUM IS ',I3,' MINIMUM IS 1.')                     USBIN     267
C                                                                       USBIN     268
C---------------------------------------------------------------------  USBIN     269
C                                                                       USBIN     270
      ENTRY USFRAC (JBLK)                                               USBIN     271
CD -------------------------------------------------------------------  USBIN     272
CD                                                                      USBIN     273
CD              *****     USFRACD ROUTINE   *****                       USBIN     274
CD                                                                      USBIN     275
CD -------------------------------------------------------------------  USBIN     276
CD                                                                      USBIN     277
CD       PURPOSE:  Performs the solution of the udc type                USBIN     278
CD                 FROMAC.                                              USBIN     279
CD                                                                      USBIN     280
CD -------------------------------------------------------------------  USBIN     281
C                                                                       USBIN     282
      NEXTI = IUNIPT(JBLK)                                              USBIN     283
C                                                                       USBIN     284
      NP = IUDINT(NEXTI)                                                USBIN     285
C                                                                       USBIN     286
C                                                                       USBIN     287
C                                                                       USBIN     288
C     Determine what variables and how many are required for the        USBIN     289
C     specified subtype.                                                USBIN     290
C                                                                       USBIN     291
C     VMAG subtype.                                                     USBIN     292
C                                                                       USBIN     293
      IF(IUDSUB(JBLK).EQ.IVMAGS)THEN                                    USBIN     294
         UDVAL(JBLK) = SQRT(DCEA(NP) * DCEA(NP) + DCEB(NP) * DCEB(NP))  USBIN     295
C                                                                       USBIN     296
C     VANG subtype.                                                     USBIN     297
C                                                                       USBIN     298
      ELSEIF(IUDSUB(JBLK).EQ.IVANGS)THEN                                USBIN     299
         VMG = SQRT(DCEA(NP) * DCEA(NP) + DCEB(NP) * DCEB(NP))          USBIN     300
         IF(VMG.GT.0.05) THEN                                           USBIN     301
            TEMP=ATAN2 (DCEB(NP), DCEA(NP))                             USBIN     302
            TEMP1=UDVAL(JBLK) * PII/180.0                               USBIN     303
            AGAIN=.TRUE.                                                USBIN     304
  200       IF(.NOT.AGAIN) GO TO 210                                    USBIN     305
            AGAIN=.FALSE.                                               USBIN     306
            IF((TEMP-TEMP1).LT.-3.15) THEN                              USBIN     307
               TEMP=TEMP+2.0*PII                                        USBIN     308
               AGAIN=.TRUE.                                             USBIN     309
            ENDIF                                                       USBIN     310
            IF((TEMP-TEMP1).GT.3.15) THEN                               USBIN     311
               TEMP=TEMP-2.0*PII                                        USBIN     312
               AGAIN=.TRUE.                                             USBIN     313
            ENDIF                                                       USBIN     314
            GO TO 200                                                   USBIN     315
  210       UDVAL(JBLK) = TEMP*180.0/PII                                USBIN     316
         END IF                                                         USBIN     317
C                                                                       USBIN     318
C                                                                       USBIN     319
C                                                                       USBIN     320
      ELSEIF(IUDSUB(JBLK).EQ.IMAGS .OR. IUDSUB(JBLK).EQ.IPS .OR.        USBIN     321
     1         IUDSUB(JBLK).EQ.IQS)THEN                                 USBIN     322
C                                                                       USBIN     323
         NEXTI = IUDINX(NEXTI)                                          USBIN     324
         NQ = IUDINT(NEXTI)                                             USBIN     325
         NEXTI = IUDINX(NEXTI)                                          USBIN     326
         LOC = IUDINT(NEXTI)                                            USBIN     327
C                                                                       USBIN     328
C  GET LINE FLOW                                                        USBIN     329
C                                                                       USBIN     330
         CALL GETCUR (CURR, CURI, LOC)                                  USBIN     331
C                                                                       USBIN     332
C        IMAG subtype.                                                  USBIN     333
C                                                                       USBIN     334
         IF(IUDSUB(JBLK).EQ.IMAGS)THEN                                  USBIN     335
C                                                                       USBIN     336
            CMAG = SQRT(CURR*CURR+CURI*CURI)*ACIBAS(NP)                 USBIN     337
            UDVAL(JBLK) = CMAG                                          USBIN     338
C                                                                       USBIN     339
C        P subtype.                                                     USBIN     340
C                                                                       USBIN     341
         ELSEIF(IUDSUB(JBLK).EQ.IPS)THEN                                USBIN     342
C                                                                       USBIN     343
            UDVAL(JBLK) = (DCEA(NP) * CURR + DCEB(NP) * CURI) * PABASE  USBIN     344
C                                                                       USBIN     345
C        Q subtype.                                                     USBIN     346
C                                                                       USBIN     347
         ELSEIF(IUDSUB(JBLK).EQ.IQS)THEN                                USBIN     348
C                                                                       USBIN     349
            UDVAL(JBLK) = (DCEB(NP) * CURR - DCEA(NP) * CURI) * PABASE  USBIN     350
         END IF                                                         USBIN     351
C                                                                       USBIN     352
C     FREQ subtype.                                                     USBIN     353
C                                                                       USBIN     354
      ELSEIF(IUDSUB(JBLK).EQ.IFREQS)THEN                                USBIN     355
         VMG = SQRT(DCEA(NP) * DCEA(NP) + DCEB(NP) * DCEB(NP))          USBIN     356
         IF(VMG.GT.0.05) THEN                                           USBIN     357
C                                                                       USBIN     358
C        Recover history of bus angle                                   USBIN     359
C                                                                       USBIN     360
            NEXTS = IUDSPT(JBLK)                                        USBIN     361
            THETA = UDOLD(NEXTS)                                        USBIN     362
            CK1 = DCEA(NP)                                              USBIN     363
            CK2 = DCEB(NP)                                              USBIN     364
            CALL DFREQ (THETA, CK1, CK2, DTIME)                         USBIN     365
            UDVAL(JBLK) = CK2 * 0.5 / PII                               USBIN     366
            UDOLD(NEXTS) = CK1                                          USBIN     367
         END IF                                                         USBIN     368
C                                                                       USBIN     369
C     Invalid subtype.                                                  USBIN     370
C                                                                       USBIN     371
      ELSE                                                              USBIN     372
         UDVAL(JBLK) = 0.0                                              USBIN     373
      END IF                                                            USBIN     374
C                                                                       USBIN     375
      RETURN                                                            USBIN     376
C                                                                       USBIN     377
C---------------------------------------------------------------------  USBIN     378
C                                                                       USBIN     379
      ENTRY USFRDC (JBLK)                                               USBIN     380
CD -------------------------------------------------------------------  USBIN     381
CD                                                                      USBIN     382
CD              *****     USFRDCD ROUTINE   *****                       USBIN     383
CD                                                                      USBIN     384
CD -------------------------------------------------------------------  USBIN     385
CD                                                                      USBIN     386
CD       PURPOSE:  Performs the solution of the udc type FROMDC.        USBIN     387
CD                                                                      USBIN     388
CD -------------------------------------------------------------------  USBIN     389
C                                                                       USBIN     390
      NEXTI = IUNIPT(JBLK)                                              USBIN     391
      IF(IUDSUB(JBLK) .NE. IVDIFF)THEN                                  USBIN     392
         NUM = IUDINT(NEXTI)                                            USBIN     393
         NEXTI = IUDINX(NEXTI)                                          USBIN     394
      END IF                                                            USBIN     395
C                                                                       USBIN     396
      IF(IUDSUB(JBLK).EQ.IPLINE .OR. IUDSUB(JBLK).EQ.ILINES .OR.        USBIN     397
     1    IUDSUB(JBLK).EQ.IVDIFF .OR. IUDSUB(JBLK).EQ.ICAPS)THEN        USBIN     398
         JBUS1 = IUDINT(NEXTI)                                          USBIN     399
         NEXTI = IUDINX(NEXTI)                                          USBIN     400
         JBUS2 = IUDINT(NEXTI)                                          USBIN     401
      END IF                                                            USBIN     402
C                                                                       USBIN     403
C                                                                       USBIN     404
C     DC converter voltage.                                             USBIN     405
C                                                                       USBIN     406
      IF(IUDSUB(JBLK).EQ.IVCONV)THEN                                    USBIN     407
         UDVAL(JBLK) = VDCONV(NUM)                                      USBIN     408
C                                                                       USBIN     409
C                                                                       USBIN     410
C     DC converter current.                                             USBIN     411
C                                                                       USBIN     412
      ELSEIF(IUDSUB(JBLK).EQ.ICONVS)THEN                                USBIN     413
         UDVAL(JBLK) = XDCONV(NUM) * 1000.0                             USBIN     414
C                                                                       USBIN     415
C                                                                       USBIN     416
C     DC node voltage to ground.                                        USBIN     417
C                                                                       USBIN     418
      ELSEIF(IUDSUB(JBLK).EQ.IVNODE)THEN                                USBIN     419
         UDVAL(JBLK) = VDCNOD(NUM)                                      USBIN     420
C                                                                       USBIN     421
C                                                                       USBIN     422
C     Net current into dc node.                                         USBIN     423
C                                                                       USBIN     424
      ELSEIF(IUDSUB(JBLK).EQ.INODES)THEN                                USBIN     425
         UDVAL(JBLK) = XDNODE(NUM) * 1000.0                             USBIN     426
C                                                                       USBIN     427
C                                                                       USBIN     428
C     cos (alpha) of dc converter.                                      USBIN     429
C                                                                       USBIN     430
      ELSEIF(IUDSUB(JBLK).EQ.IALFAS)THEN                                USBIN     431
         IF(IABS(ICTYPE(NUM)) .EQ. 1) THEN                              USBIN     432
            UDVAL(JBLK) = ACOS(CALPHA(NUM)) * 180.0 / PII               USBIN     433
         ELSEIF(IABS(ICTYPE(NUM)) .EQ. 2) THEN                          USBIN     434
            UDVAL(JBLK) = CALPHA(NUM) * 180.0 / PII                     USBIN     435
         ENDIF                                                          USBIN     436
C                                                                       USBIN     437
C                                                                       USBIN     438
C     cos (gamma) of dc converter.                                      USBIN     439
C                                                                       USBIN     440
      ELSEIF(IUDSUB(JBLK).EQ.IGAMAS)THEN                                USBIN     441
         IF(IABS(ICTYPE(NUM)) .EQ. 1) THEN                              USBIN     442
            UDVAL(JBLK) = ACOS(CGAMMA(NUM)) * 180.0 / PII               USBIN     443
         ELSEIF(IABS(ICTYPE(NUM)) .EQ. 2) THEN                          USBIN     444
            UDVAL(JBLK) = CGAMMA(NUM)                                   USBIN     445
         ENDIF                                                          USBIN     446
C                                                                       USBIN     447
C                                                                       USBIN     448
C     DC converter real power injection.                                USBIN     449
C                                                                       USBIN     450
      ELSEIF(IUDSUB(JBLK).EQ.IPACS)THEN                                 USBIN     451
         UDVAL(JBLK) = PAHVDC(NUM)                                      USBIN     452
C                                                                       USBIN     453
C                                                                       USBIN     454
C     DC converter reactive power injection.                            USBIN     455
C                                                                       USBIN     456
      ELSEIF(IUDSUB(JBLK).EQ.IQACS)THEN                                 USBIN     457
         IF(IABS(ICTYPE(NUM)) .EQ. 1) THEN                              USBIN     458
            UDVAL(JBLK) = QAHVDC(NUM)                                   USBIN     459
         ELSEIF(IABS(ICTYPE(NUM)) .EQ. 2) THEN                          USBIN     460
            UDVAL(JBLK) = QAHVDC(NUM) + Q2HVDC(NUM)                     USBIN     461
         ENDIF                                                          USBIN     462
C                                                                       USBIN     463
C                                                                       USBIN     464
C     Current flow for dc line.                                         USBIN     465
C                                                                       USBIN     466
      ELSEIF(IUDSUB(JBLK).EQ.ILINES)THEN                                USBIN     467
         IF(JBUS1.EQ.JGROUN)THEN                                        USBIN     468
            VBUS1 = 0.0                                                 USBIN     469
         ELSE                                                           USBIN     470
            VBUS1 = VDCNOD(JBUS1)                                       USBIN     471
         END IF                                                         USBIN     472
C                                                                       USBIN     473
         IF(JBUS2.EQ.JGROUN)THEN                                        USBIN     474
            VBUS2 = 0.0                                                 USBIN     475
         ELSE                                                           USBIN     476
            VBUS2 = VDCNOD(JBUS2)                                       USBIN     477
         END IF                                                         USBIN     478
C                                                                       USBIN     479
         CALL USLINE (VBUS1, VBUS2, NUM, CFLOW, CAPFLW)                 USBIN     480
         UDVAL(JBLK) = CFLOW * 1000.0                                   USBIN     481
C                                                                       USBIN     482
C     Current flow for dc line shunt capacitance                        USBIN     483
C                                                                       USBIN     484
      ELSEIF(IUDSUB(JBLK).EQ.ICAPS)THEN                                 USBIN     485
         IF(JBUS1.EQ.JGROUN)THEN                                        USBIN     486
            VBUS1 = 0.0                                                 USBIN     487
         ELSE                                                           USBIN     488
            VBUS1 = VDCNOD(JBUS1)                                       USBIN     489
         ENDIF                                                          USBIN     490
C                                                                       USBIN     491
         IF(JBUS2.EQ.JGROUN)THEN                                        USBIN     492
            VBUS2 = 0.0                                                 USBIN     493
         ELSE                                                           USBIN     494
            VBUS2 = VDCNOD(JBUS2)                                       USBIN     495
         ENDIF                                                          USBIN     496
C                                                                       USBIN     497
         CALL USLINE (VBUS1, VBUS2, NUM, CFLOW, CAPFLW)                 USBIN     498
         UDVAL(JBLK) = CAPFLW * 1000.0                                  USBIN     499
C                                                                       USBIN     500
C     Current flow for breakers.                                        USBIN     501
C                                                                       USBIN     502
      ELSEIF(IUDSUB(JBLK).EQ.IBRKRS)THEN                                USBIN     503
         IF(NUM.LT.0) THEN                                              USBIN     504
            SIGN = -1.0                                                 USBIN     505
            NUM = -NUM                                                  USBIN     506
         ELSE                                                           USBIN     507
            SIGN = 1.0                                                  USBIN     508
         END IF                                                         USBIN     509
         UDVAL(JBLK) = UBCURR(NUM) * 1000.0 * SIGN                      USBIN     510
C                                                                       USBIN     511
C     Breaker status.                                                   USBIN     512
C                                                                       USBIN     513
      ELSEIF(IUDSUB(JBLK).EQ.ISBRKR)THEN                                USBIN     514
         IF(NUM.LT.0) THEN                                              USBIN     515
            NUM = -NUM                                                  USBIN     516
         END IF                                                         USBIN     517
         UDVAL(JBLK) = REAL(IBSTAT(NUM))                                USBIN     518
C                                                                       USBIN     519
C     Power flow for dc line.                                           USBIN     520
C                                                                       USBIN     521
      ELSEIF(IUDSUB(JBLK).EQ.IPLINE)THEN                                USBIN     522
         IF(JBUS1.EQ.JGROUN)THEN                                        USBIN     523
            VBUS1 = 0.0                                                 USBIN     524
         ELSE                                                           USBIN     525
            VBUS1 = VDCNOD(JBUS1)                                       USBIN     526
         END IF                                                         USBIN     527
         IF(JBUS2.EQ.JGROUN)THEN                                        USBIN     528
            VBUS2 = 0.0                                                 USBIN     529
         ELSE                                                           USBIN     530
            VBUS2 = VDCNOD(JBUS2)                                       USBIN     531
         END IF                                                         USBIN     532
C                                                                       USBIN     533
         CALL USLINE (VBUS1, VBUS2, NUM, CFLOW, CAPFLW)                 USBIN     534
         UDVAL(JBLK) = CFLOW * VBUS1                                    USBIN     535
C                                                                       USBIN     536
C     Bridge subtype.                                                   USBIN     537
C                                                                       USBIN     538
      ELSEIF(IUDSUB(JBLK).EQ.IBRDGE)THEN                                USBIN     539
         UDVAL(JBLK) = REAL (NSBRDG(NUM))                               USBIN     540
C                                                                       USBIN     541
C     Commutation voltage subtype.                                      USBIN     542
C                                                                       USBIN     543
      ELSEIF(IUDSUB(JBLK).EQ.IVCOMM)THEN                                USBIN     544
         IF(IABS(ICTYPE(NUM)) .EQ. 1) THEN                              USBIN     545
            UDVAL(JBLK) = VAHVDC(NUM) * TAPPOS(NUM)                     USBIN     546
         ELSEIF(IABS(ICTYPE(NUM)) .EQ. 2) THEN                          USBIN     547
            UDVAL(JBLK) = VAHVDC(NUM) / TAPPOS(NUM)                     USBIN     548
         ENDIF                                                          USBIN     549
C                                                                       USBIN     550
C     Commutating Reactance subtype.                                    USBIN     551
C                                                                       USBIN     552
      ELSEIF(IUDSUB(JBLK).EQ.IXCS)THEN                                  USBIN     553
         UDVAL(JBLK) = XCCONV(NUM)                                      USBIN     554
C                                                                       USBIN     555
C     Tap Position subtype.                                             USBIN     556
C                                                                       USBIN     557
      ELSEIF(IUDSUB(JBLK).EQ.ITAPS)THEN                                 USBIN     558
         UDVAL(JBLK) = TAPPOS(NUM)                                      USBIN     559
C                                                                       USBIN     560
C     Commutation failure monitoring                                    USBIN     561
C                                                                       USBIN     562
      ELSEIF(IUDSUB(JBLK).EQ.ICOMFL)THEN                                USBIN     563
         IF(UMODE(NUM).EQ.'COMFAIL')THEN                                USBIN     564
            UDVAL(JBLK) = 1.0                                           USBIN     565
         ELSE                                                           USBIN     566
            IF(UMODE(NUM).NE.'BYPASS'.AND.UMODE(NUM).NE.'BLOCK') THEN   USBIN     567
               IF(UMOD2(NUM).EQ.'COMFAIL') THEN                         USBIN     568
                  UDVAL(JBLK) = 1.0                                     USBIN     569
               ELSE                                                     USBIN     570
                  UDVAL(JBLK) = 0.0                                     USBIN     571
               ENDIF                                                    USBIN     572
            ELSE                                                        USBIN     573
               UDVAL(JBLK) = 0.0                                        USBIN     574
            ENDIF                                                       USBIN     575
         END IF                                                         USBIN     576
C                                                                       USBIN     577
C     Block monitoring                                                  USBIN     578
C                                                                       USBIN     579
      ELSEIF(IUDSUB(JBLK).EQ.JBLOCK)THEN                                USBIN     580
         IF(UMODE(NUM).EQ.'BLOCK')THEN                                  USBIN     581
            UDVAL(JBLK) = 1.0                                           USBIN     582
         ELSE                                                           USBIN     583
            IF(UMODE(NUM).NE.'BYPASS'.AND.UMODE(NUM).NE.'COMFAIL') THEN USBIN     584
               IF(UMOD2(NUM).EQ.'BLOCK') THEN                           USBIN     585
                  UDVAL(JBLK) = 1.0                                     USBIN     586
               ELSE                                                     USBIN     587
                  UDVAL(JBLK) = 0.0                                     USBIN     588
               ENDIF                                                    USBIN     589
            ELSE                                                        USBIN     590
               UDVAL(JBLK) = 0.0                                        USBIN     591
            ENDIF                                                       USBIN     592
         END IF                                                         USBIN     593
C                                                                       USBIN     594
C     First line capacitance.                                           USBIN     595
C                                                                       USBIN     596
      ELSEIF(IUDSUB(JBLK).EQ.ICL1S)THEN                                 USBIN     597
         UDVAL(JBLK) = CDCA(NUM) * 1.0E6                                USBIN     598
C                                                                       USBIN     599
C     Second line capacitance.                                          USBIN     600
C                                                                       USBIN     601
      ELSEIF(IUDSUB(JBLK).EQ.ICL2S)THEN                                 USBIN     602
         UDVAL(JBLK) = CDCB(NUM) * 1.0E6                                USBIN     603
C                                                                       USBIN     604
C     Line inductance.                                                  USBIN     605
C                                                                       USBIN     606
      ELSEIF(IUDSUB(JBLK).EQ.LLS)THEN                                   USBIN     607
         UDVAL(JBLK) = XLDC(NUM) * 1.0E3                                USBIN     608
C                                                                       USBIN     609
C     Line resistance.                                                  USBIN     610
C                                                                       USBIN     611
      ELSEIF(IUDSUB(JBLK).EQ.IRLS)THEN                                  USBIN     612
         UDVAL(JBLK) = RDCOHM(NUM)                                      USBIN     613
C                                                                       USBIN     614
C     Run mode.                                                         USBIN     615
C                                                                       USBIN     616
      ELSEIF(IUDSUB(JBLK).EQ.IRMODE)THEN                                USBIN     617
C                                                                       USBIN     618
C     Convert a character string to the numeric equivalent.             USBIN     619
C                                                                       USBIN     620
         STRING = ' '                                                   USBIN     621
         STRING(1:8) = UMODE (NUM)                                      USBIN     622
         STRING(9:16)= UMOD2 (NUM)                                      USBIN     623
         CALL USTRNG(STRING, UDVAL(JBLK), JBLK, ' R ')                  USBIN     624
C                                                                       USBIN     625
C     Initial mode.                                                     USBIN     626
C                                                                       USBIN     627
      ELSEIF(IUDSUB(JBLK).EQ.IMODES)THEN                                USBIN     628
C                                                                       USBIN     629
C     Convert a character string to the numeric equivalent.             USBIN     630
C                                                                       USBIN     631
         STRING = ' '                                                   USBIN     632
         STRING(1:4) = SPTYPE(NUM)                                      USBIN     633
         STRING(5:6) = SPTYP3(NUM)                                      USBIN     634
         CALL USTRNG(STRING, UDVAL(JBLK), JBLK, 'I  ')                  USBIN     635
C                                                                       USBIN     636
C     Voltage Difference.                                               USBIN     637
C                                                                       USBIN     638
      ELSEIF(IUDSUB(JBLK).EQ.IVDIFF)THEN                                USBIN     639
         IF(JBUS1.EQ.JGROUN)THEN                                        USBIN     640
            VBUS1 = 0.0                                                 USBIN     641
         ELSE                                                           USBIN     642
            VBUS1 = VDCNOD(JBUS1)                                       USBIN     643
         END IF                                                         USBIN     644
C                                                                       USBIN     645
         IF(JBUS2.EQ.JGROUN)THEN                                        USBIN     646
            VBUS2 = 0.0                                                 USBIN     647
         ELSE                                                           USBIN     648
            VBUS2 = VDCNOD(JBUS2)                                       USBIN     649
         END IF                                                         USBIN     650
C                                                                       USBIN     651
         UDVAL(JBLK) = VBUS1 - VBUS2                                    USBIN     652
      END IF                                                            USBIN     653
C                                                                       USBIN     654
      RETURN                                                            USBIN     655
C                                                                       USBIN     656
C---------------------------------------------------------------------  USBIN     657
C                                                                       USBIN     658
      ENTRY USMLTP (JBLK)                                               USBIN     659
CD -------------------------------------------------------------------  USBIN     660
CD                                                                      USBIN     661
CD              *****     USMLTP  ROUTINE   *****                       USBIN     662
CD                                                                      USBIN     663
CD -------------------------------------------------------------------  USBIN     664
CD                                                                      USBIN     665
CD       PURPOSE:  Performs the solution of the udc type MULTIPLE.      USBIN     666
CD                                                                      USBIN     667
CD -------------------------------------------------------------------  USBIN     668
C                                                                       USBIN     669
C     Retrieve input value.                                             USBIN     670
C                                                                       USBIN     671
      NEXTI = IUNIPT(JBLK)                                              USBIN     672
      NEXTP = IUDPPT(JBLK)                                              USBIN     673
C                                                                       USBIN     674
C                                                                       USBIN     675
      IF(IUDSUB(JBLK) .NE. ISUMR)THEN                                   USBIN     676
C                                                                       USBIN     677
C        Initialize output to the first input.                          USBIN     678
C                                                                       USBIN     679
         IF(UIDENT(NEXTI) .NE. ' ')THEN                                 USBIN     680
            UDVAL(JBLK) = UDVAL(IUDINT(NEXTI))                          USBIN     681
         ELSE                                                           USBIN     682
            UDVAL(JBLK) = UDPARM(NEXTP)                                 USBIN     683
         END IF                                                         USBIN     684
         NEXTI = IUDINX(NEXTI)                                          USBIN     685
         NEXTP = IUDPNX(NEXTP)                                          USBIN     686
C                                                                       USBIN     687
C        Keep retrieving input values until no more are stored.         USBIN     688
C                                                                       USBIN     689
420      IF(NEXTI.EQ.0 .OR. NEXTP.EQ.0) GOTO 440                        USBIN     690
            IF(UIDENT(NEXTI) .NE. ' ')THEN                              USBIN     691
               VALUE = UDVAL(IUDINT(NEXTI))                             USBIN     692
            ELSE                                                        USBIN     693
               VALUE = UDPARM(NEXTP)                                    USBIN     694
            END IF                                                      USBIN     695
C                                                                       USBIN     696
C                                                                       USBIN     697
C           Multiple addition.                                          USBIN     698
C                                                                       USBIN     699
            IF(IUDSUB(JBLK).EQ.ISUMS)THEN                               USBIN     700
               UDVAL(JBLK) = UDVAL(JBLK) + VALUE                        USBIN     701
C                                                                       USBIN     702
C                                                                       USBIN     703
C           Multiple minimum.                                           USBIN     704
C                                                                       USBIN     705
            ELSEIF(IUDSUB(JBLK).EQ.MINS)THEN                            USBIN     706
              UDVAL(JBLK) = MIN(UDVAL(JBLK),VALUE)                      USBIN     707
C                                                                       USBIN     708
C                                                                       USBIN     709
C           Multiple maximum.                                           USBIN     710
C                                                                       USBIN     711
            ELSEIF(IUDSUB(JBLK).EQ.MAXS)THEN                            USBIN     712
               UDVAL(JBLK) = MAX(UDVAL(JBLK),VALUE)                     USBIN     713
C                                                                       USBIN     714
            END IF                                                      USBIN     715
C                                                                       USBIN     716
            NEXTI = IUDINX(NEXTI)                                       USBIN     717
            NEXTP = IUDPNX(NEXTP)                                       USBIN     718
            GOTO 420                                                    USBIN     719
440      CONTINUE                                                       USBIN     720
C                                                                       USBIN     721
C                                                                       USBIN     722
C                                                                       USBIN     723
      ELSE                                                              USBIN     724
C                                                                       USBIN     725
C        Initialize output to the first input.                          USBIN     726
C                                                                       USBIN     727
         IF(UIDENT(NEXTI) .NE. ' ')THEN                                 USBIN     728
            VALUE = UDVAL(IUDINT(NEXTI))                                USBIN     729
         ELSE                                                           USBIN     730
            VALUE = UDPARM(NEXTP)                                       USBIN     731
         END IF                                                         USBIN     732
         NEXTI = IUDINX(NEXTI)                                          USBIN     733
         NEXTP = IUDPNX(NEXTP)                                          USBIN     734
C                                                                       USBIN     735
C                                                                       USBIN     736
C        Multiple first output by gain.                                 USBIN     737
C                                                                       USBIN     738
         GAIN = UDPARM(NEXTP)                                           USBIN     739
         NEXTP = IUDPNX(NEXTP)                                          USBIN     740
C                                                                       USBIN     741
         UDVAL(JBLK) = VALUE * GAIN                                     USBIN     742
C                                                                       USBIN     743
460      IF(NEXTI.EQ.0 .OR. NEXTP.EQ.0) GOTO 480                        USBIN     744
C                                                                       USBIN     745
C           Initialize output to the first input.                       USBIN     746
C                                                                       USBIN     747
            IF(UIDENT(NEXTI) .NE. ' ')THEN                              USBIN     748
               VALUE = UDVAL(IUDINT(NEXTI))                             USBIN     749
            ELSE                                                        USBIN     750
               VALUE = UDPARM(NEXTP)                                    USBIN     751
            END IF                                                      USBIN     752
            NEXTI = IUDINX(NEXTI)                                       USBIN     753
            NEXTP = IUDPNX(NEXTP)                                       USBIN     754
C                                                                       USBIN     755
C                                                                       USBIN     756
C           Multiple first output by gain.                              USBIN     757
C                                                                       USBIN     758
            GAIN = UDPARM(NEXTP)                                        USBIN     759
            NEXTP = IUDPNX(NEXTP)                                       USBIN     760
C                                                                       USBIN     761
            UDVAL(JBLK) = UDVAL(JBLK) + VALUE * GAIN                    USBIN     762
C                                                                       USBIN     763
            GOTO 460                                                    USBIN     764
480      CONTINUE                                                       USBIN     765
      END IF                                                            USBIN     766
C                                                                       USBIN     767
      RETURN                                                            USBIN     768
C                                                                       USBIN     769
C---------------------------------------------------------------------  USBIN     770
C                                                                       USBIN     771
      ENTRY USSBLK (JBLK)                                               USBIN     772
CD -------------------------------------------------------------------  USBIN     773
CD                                                                      USBIN     774
CD              *****     USSBLK  ROUTINE   *****                       USBIN     775
CD                                                                      USBIN     776
CD -------------------------------------------------------------------  USBIN     777
CD                                                                      USBIN     778
CD       PURPOSE:  Performs the solution of the udc type SBLOCK.        USBIN     779
CD                                                                      USBIN     780
CD -------------------------------------------------------------------  USBIN     781
C                                                                       USBIN     782
      NEXTI = IUNIPT(JBLK)                                              USBIN     783
      NEXTP = IUDPPT(JBLK)                                              USBIN     784
      NEXTR = IUDRPT(JBLK)                                              USBIN     785
      NEXTS = IUDSPT(JBLK)                                              USBIN     786
C                                                                       USBIN     787
C     Input block.                                                      USBIN     788
C                                                                       USBIN     789
      JBLOCK = IUDINT(NEXTI)                                            USBIN     790
      VALUE = UDVAL(JBLOCK)                                             USBIN     791
      NEXTI = IUDINX(NEXTI)                                             USBIN     792
C                                                                       USBIN     793
      IF(IUDSUB(JBLK).EQ.LIMITS)THEN                                    USBIN     794
C                                                                       USBIN     795
C        Low limit.                                                     USBIN     796
C                                                                       USBIN     797
         IF(UIDENT(NEXTI) .NE. ' ')THEN                                 USBIN     798
            XLOW = UDVAL(IUDINT(NEXTI))                                 USBIN     799
         ELSE                                                           USBIN     800
            XLOW = UDPARM(NEXTP)                                        USBIN     801
         END IF                                                         USBIN     802
         NEXTI = IUDINX(NEXTI)                                          USBIN     803
         NEXTP = IUDPNX(NEXTP)                                          USBIN     804
C                                                                       USBIN     805
C        High limit.                                                    USBIN     806
C                                                                       USBIN     807
         IF(UIDENT(NEXTI) .NE. ' ')THEN                                 USBIN     808
            HIGH = UDVAL(IUDINT(NEXTI))                                 USBIN     809
         ELSE                                                           USBIN     810
            HIGH = UDPARM(NEXTP)                                        USBIN     811
         END IF                                                         USBIN     812
         NEXTI = IUDINX(NEXTI)                                          USBIN     813
         NEXTP = IUDPNX(NEXTP)                                          USBIN     814
      END IF                                                            USBIN     815
C                                                                       USBIN     816
C     Order of equations.                                               USBIN     817
C                                                                       USBIN     818
      JORDER = IUDINT(NEXTI)                                            USBIN     819
      KORDER = JORDER + 1                                               USBIN     820
      NEXTI = IUDINX(NEXTI)                                             USBIN     821
C                                                                       USBIN     822
C                                                                       USBIN     823
C     Read in little a's.                                               USBIN     824
C                                                                       USBIN     825
      DO 520 I = KORDER, 1, -1                                          USBIN     826
         AA(I) = UDPARM(NEXTP)                                          USBIN     827
         NEXTP = IUDPNX(NEXTP)                                          USBIN     828
520   CONTINUE                                                          USBIN     829
C                                                                       USBIN     830
C                                                                       USBIN     831
C     Read in little c's.                                               USBIN     832
C                                                                       USBIN     833
      DO 540 I = KORDER, 1, -1                                          USBIN     834
         CC(I) = UDPARM(NEXTP)                                          USBIN     835
         NEXTP = IUDPNX(NEXTP)                                          USBIN     836
540   CONTINUE                                                          USBIN     837
C                                                                       USBIN     838
C     Zero out arrays.                                                  USBIN     839
C                                                                       USBIN     840
      DO 580 JCOL = 1, JORDER                                           USBIN     841
         DO 560 JROW = 1, JORDER                                        USBIN     842
            A(JROW,JCOL) = 0.0                                          USBIN     843
560      CONTINUE                                                       USBIN     844
         B(JCOL) = 0.0                                                  USBIN     845
         C(JCOL) = 0.0                                                  USBIN     846
         H(JCOL) = 0.0                                                  USBIN     847
580   CONTINUE                                                          USBIN     848
C                                                                       USBIN     849
C                                                                       USBIN     850
C     Define array A.                                                   USBIN     851
C                                                                       USBIN     852
      DO 600 JCOL = 2, JORDER                                           USBIN     853
         JROW = JCOL - 1                                                USBIN     854
         A(JROW,JCOL) = 1.0                                             USBIN     855
600   CONTINUE                                                          USBIN     856
C                                                                       USBIN     857
      DO 620 JCOL = 1, JORDER                                           USBIN     858
         A(JORDER,JCOL) = -CC(JCOL) / CC(KORDER)                        USBIN     859
620   CONTINUE                                                          USBIN     860
C                                                                       USBIN     861
C     Define vector B.                                                  USBIN     862
C                                                                       USBIN     863
      B(JORDER) = 1.0                                                   USBIN     864
C                                                                       USBIN     865
C     Define vector C.                                                  USBIN     866
C                                                                       USBIN     867
      DO 640 JCOL = 1, JORDER                                           USBIN     868
         C(JCOL) = (AA(JCOL) + AA(KORDER) * A(JORDER,JCOL)) / CC(KORDER)USBIN     869
640   CONTINUE                                                          USBIN     870
C                                                                       USBIN     871
C     Define value D.                                                   USBIN     872
C                                                                       USBIN     873
      D = AA(KORDER) / CC(KORDER)                                       USBIN     874
C                                                                       USBIN     875
C---------------------------------------------------------------------  USBIN     876
C                                                                       USBIN     877
C     For the solution of x' = Ax + Bu the damped trapezoidal           USBIN     878
C     integration algorithm requires solving x*.                        USBIN     879
C                                                                       USBIN     880
      DO 660 I = 1, JORDER                                              USBIN     881
         OLDX(I) = UDOLD(NEXTS)                                         USBIN     882
         NEXTS = IUDSNX(NEXTS)                                          USBIN     883
660   CONTINUE                                                          USBIN     884
C                                                                       USBIN     885
      OLDV = UDOLD(NEXTS)                                               USBIN     886
      NEXTS = IUDSNX(NEXTS)                                             USBIN     887
C                                                                       USBIN     888
      H(JORDER) = (CTIME / 2.0) * ((1. + ALPHAT) * B(JORDER) * VALUE +  USBIN     889
     1           (1. - ALPHAT) * B(JORDER) * OLDV)                      USBIN     890
C                                                                       USBIN     891
      DO 700 JROW = 1, JORDER                                           USBIN     892
         X(JROW) = 0.0                                                  USBIN     893
         DO 680 I = 1, JORDER                                           USBIN     894
           X(JROW) = X(JROW) + A(JROW,I) * OLDX(I)                      USBIN     895
680      CONTINUE                                                       USBIN     896
         X(JROW) = OLDX(JROW) + ((CTIME / 2.0) * (1. - ALPHAT) *        USBIN     897
     1            X(JROW)) + H(JROW)                                    USBIN     898
700   CONTINUE                                                          USBIN     899
C                                                                       USBIN     900
      DO 740 JCOL = 1, JORDER                                           USBIN     901
         DO 720 JROW = 1, JORDER                                        USBIN     902
            A(JROW,JCOL) = - ((CTIME / 2.0) * (1. + ALPHAT) *           USBIN     903
     1                   A(JROW,JCOL))                                  USBIN     904
720      CONTINUE                                                       USBIN     905
         A(JCOL,JCOL) = 1 + A(JCOL,JCOL)                                USBIN     906
740   CONTINUE                                                          USBIN     907
C                                                                       USBIN     908
      J = 10                                                            USBIN     909
C                                                                       USBIN     910
      CALL DGEFA2 (A, J, JORDER, IPVT, INFO)                            USBIN     911
C                                                                       USBIN     912
      CALL DGESL2 (A, J, JORDER, IPVT, X, 0)                            USBIN     913
C                                                                       USBIN     914
C                                                                       USBIN     915
C     Solve for the new UDVAL.                                          USBIN     916
C                                                                       USBIN     917
      UDVAL(JBLK) = 0.0                                                 USBIN     918
      DO 760 I = 1, JORDER                                              USBIN     919
         UDVAL(JBLK) = C(I) * X(I) + UDVAL(JBLK)                        USBIN     920
760   CONTINUE                                                          USBIN     921
      UDVAL(JBLK) = UDVAL(JBLK) + D * VALUE                             USBIN     922
C                                                                       USBIN     923
C     Save current X and current value.                                 USBIN     924
C                                                                       USBIN     925
      LIMIT = .FALSE.                                                   USBIN     926
      IF(IUDSUB(JBLK).EQ.LIMITS)THEN                                    USBIN     927
         IF(XLOW.EQ.0.0.AND.HIGH.EQ.0.0)THEN                            USBIN     928
            LIMIT = .FALSE.                                             USBIN     929
         ELSEIF(UDVAL(JBLK) .LT. XLOW)THEN                              USBIN     930
            LIMIT = .TRUE.                                              USBIN     931
            UDVAL(JBLK) = XLOW                                          USBIN     932
         ELSEIF(UDVAL(JBLK) .GT. HIGH)THEN                              USBIN     933
            LIMIT = .TRUE.                                              USBIN     934
            UDVAL(JBLK) = HIGH                                          USBIN     935
         END IF                                                         USBIN     936
      END IF                                                            USBIN     937
C                                                                       USBIN     938
      NEXTS = IUDSPT(JBLK)                                              USBIN     939
C                                                                       USBIN     940
      KORDER = JORDER + 1                                               USBIN     941
      IF(LIMIT)THEN                                                     USBIN     942
         TEMP = (UDVAL(JBLK) * CC(KORDER) - AA(KORDER) * VALUE)         USBIN     943
         TEMP = TEMP / (AA(1) - AA(KORDER) * CC(1) / CC(KORDER))        USBIN     944
      ELSE                                                              USBIN     945
         TEMP = 0.0                                                     USBIN     946
      END IF                                                            USBIN     947
C                                                                       USBIN     948
      DO 780 N = 1, KORDER                                              USBIN     949
         IF(N.EQ.KORDER)THEN                                            USBIN     950
            UDOLD(NEXTS) = VALUE                                        USBIN     951
         ELSE                                                           USBIN     952
            IF(LIMIT)THEN                                               USBIN     953
               IF(N.EQ.1)THEN                                           USBIN     954
                  UDOLD(NEXTS) = TEMP                                   USBIN     955
               ELSE                                                     USBIN     956
                  UDOLD(NEXTS) = 0.0                                    USBIN     957
               END IF                                                   USBIN     958
            ELSE                                                        USBIN     959
               UDOLD(NEXTS) = X(N)                                      USBIN     960
            END IF                                                      USBIN     961
         END IF                                                         USBIN     962
         NEXTS = IUDSNX(NEXTS)                                          USBIN     963
780   CONTINUE                                                          USBIN     964
C                                                                       USBIN     965
      RETURN                                                            USBIN     966
C                                                                       USBIN     967
C---------------------------------------------------------------------  USBIN     968
C                                                                       USBIN     969
      ENTRY USSRCE (JBLK)                                               USBIN     970
CD -------------------------------------------------------------------  USBIN     971
CD                                                                      USBIN     972
CD              *****     USSRCE  ROUTINE   *****                       USBIN     973
CD                                                                      USBIN     974
CD -------------------------------------------------------------------  USBIN     975
CD                                                                      USBIN     976
CD       PURPOSE:  Performs the solution of the udc type SOURCE.        USBIN     977
CD                                                                      USBIN     978
CD -------------------------------------------------------------------  USBIN     979
C                                                                       USBIN     980
C     Determine the UDVAL based on what subtype was stored.             USBIN     981
C                                                                       USBIN     982
C     Fixed DC value.                                                   USBIN     983
C                                                                       USBIN     984
      IF(IUDSUB(JBLK).EQ.IDCS)THEN                                      USBIN     985
         NEXTP = IUDPPT(JBLK)                                           USBIN     986
         AMPLIT = UDPARM(NEXTP)                                         USBIN     987
         NEXTP = IUDPNX(NEXTP)                                          USBIN     988
         SRTTIM = UDPARM(NEXTP)                                         USBIN     989
C                                                                       USBIN     990
         IF((TIME + CTIME / 2.0) .GE. SRTTIM)THEN                       USBIN     991
            UDVAL(JBLK) = AMPLIT                                        USBIN     992
         ELSE                                                           USBIN     993
            UDVAL(JBLK) = 0.0                                           USBIN     994
         END IF                                                         USBIN     995
C                                                                       USBIN     996
C                                                                       USBIN     997
C     Sinusoidal.                                                       USBIN     998
C                                                                       USBIN     999
      ELSEIF(IUDSUB(JBLK).EQ.ISINS)THEN                                 USBIN    1000
         NEXTP = IUDPPT(JBLK)                                           USBIN    1001
         AMPLIT = UDPARM(NEXTP)                                         USBIN    1002
         NEXTP = IUDPNX(NEXTP)                                          USBIN    1003
         FREQ = UDPARM(NEXTP)                                           USBIN    1004
         NEXTP = IUDPNX(NEXTP)                                          USBIN    1005
         PHASE = UDPARM(NEXTP)                                          USBIN    1006
         NEXTP = IUDPNX(NEXTP)                                          USBIN    1007
         SRTTIM = UDPARM(NEXTP)                                         USBIN    1008
         IF((TIME + CTIME / 2.0) .GE. SRTTIM)THEN                       USBIN    1009
            UDVAL(JBLK) = AMPLIT * SIN((FREQ * 2.0 * PII *              USBIN    1010
     1                   (TIME - SRTTIM)) +  PHASE * PII/180.0)         USBIN    1011
         ELSE                                                           USBIN    1012
            UDVAL(JBLK) = 0.0                                           USBIN    1013
         END IF                                                         USBIN    1014
C                                                                       USBIN    1015
C                                                                       USBIN    1016
C     Ramp function.                                                    USBIN    1017
C                                                                       USBIN    1018
      ELSEIF(IUDSUB(JBLK).EQ.IRAMPS)THEN                                USBIN    1019
         NEXTP = IUDPPT(JBLK)                                           USBIN    1020
         RAMP = UDPARM(NEXTP)                                           USBIN    1021
         NEXTP = IUDPNX(NEXTP)                                          USBIN    1022
         SRTTIM = UDPARM(NEXTP)                                         USBIN    1023
         IF((TIME + CTIME / 2.0) .GE. SRTTIM)THEN                       USBIN    1024
            UDVAL(JBLK) = RAMP * (TIME - SRTTIM)                        USBIN    1025
         ELSE                                                           USBIN    1026
            UDVAL(JBLK) = 0.0                                           USBIN    1027
         END IF                                                         USBIN    1028
C                                                                       USBIN    1029
C                                                                       USBIN    1030
C     Value of the simulation time clock.                               USBIN    1031
C                                                                       USBIN    1032
      ELSEIF(IUDSUB(JBLK).EQ.ITIMES)THEN                                USBIN    1033
         UDVAL(JBLK) = TIME                                             USBIN    1034
C                                                                       USBIN    1035
C                                                                       USBIN    1036
C     Value of the ac system solution time step delta(t).               USBIN    1037
C                                                                       USBIN    1038
      ELSEIF(IUDSUB(JBLK).EQ.IDTACS)THEN                                USBIN    1039
         UDVAL(JBLK) = DTIME                                            USBIN    1040
C                                                                       USBIN    1041
C                                                                       USBIN    1042
C     Value of the dc system solution time step sigma(t).               USBIN    1043
C                                                                       USBIN    1044
      ELSEIF(IUDSUB(JBLK).EQ.IDTDCS)THEN                                USBIN    1045
         UDVAL(JBLK) = STIME                                            USBIN    1046
C                                                                       USBIN    1047
C                                                                       USBIN    1048
C     Value of the dc control solution time step sigma(t).              USBIN    1049
C                                                                       USBIN    1050
      ELSEIF(IUDSUB(JBLK).EQ.IDTCCS)THEN                                USBIN    1051
         UDVAL(JBLK) = CTIME                                            USBIN    1052
C                                                                       USBIN    1053
C                                                                       USBIN    1054
      END IF                                                            USBIN    1055
C                                                                       USBIN    1056
      RETURN                                                            USBIN    1057
C                                                                       USBIN    1058
C---------------------------------------------------------------------  USBIN    1059
C                                                                       USBIN    1060
      END                                                               USBIN    1061
