CFPRIME UPYMAT                                                          UPYMAT      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 UPYMAT(ISCARD)                                         UPYMAT      3
CD                                                                      UPYMAT      4
CD    THIS SUBROUTINE UPDATES THE Y-MATRIX ACCORDING TO THE SWITCHING   UPYMAT      5
CD    ACTIVITIES. IT ALSO UPDATES THE NETWORK LINKNET INFORMATION IF    UPYMAT      6
CD    NETWORK IS MODIFIED.                                              UPYMAT      7
CD                                                                      UPYMAT      8
      INCLUDE 'PARX.INS'                                                UPYMAT      9
      INCLUDE 'CNPT.INS'                                                UPYMAT     10
      INCLUDE 'CNFLAG.INS'                                              UPYMAT     11
      INCLUDE 'CNIPTR.INS'                                              UPYMAT     12
      INCLUDE 'CNSTN.INS'                                               UPYMAT     13
      INCLUDE 'CNMON.INS'                                               UPYMAT     14
      INCLUDE 'CNPARX.INS'                                              UPYMAT     15
      INCLUDE 'CNUNIT.INS'                                              UPYMAT     16
      INCLUDE 'CNSPVI.INS'                                              UPYMAT     17
      INCLUDE 'CNSPDI.INS'                                              UPYMAT     18
C      INCLUDE 'CNLKN1.INS/LIST'                                        UPYMAT     19
      INCLUDE 'CNNETD.INS'                                              UPYMAT     20
      INCLUDE 'CNBRAU.INS'                                              UPYMAT     21
      INCLUDE 'CNBRL2.INS'                                              UPYMAT     22
      INCLUDE 'CNSELI.INS'                                              UPYMAT     23
      INCLUDE 'CNNNEW.INS'                                              UPYMAT     24
C                                                                       UPYMAT     25
      COMPLEX CMPLX                                                     UPYMAT     26
      CHARACTER*2 CID                                                   UPYMAT     27
      CHARACTER*4 ICKT                                                  UPYMAT     28
C                                                                       UPYMAT     29
      LDEB=(JDEB(40).NE.0)                                              UPYMAT     30
C                                                                       UPYMAT     31
C                                                                       UPYMAT     32
      REWIND IU7                                                        UPYMAT     33
      READ(IU7)LLNET                                                    UPYMAT     34
      CALL CMPWR(IU7,1,LLNET,BRAU)                                      UPYMAT     35
      CALL CMPWR(IU7,1,LLNET,BRAL)                                      UPYMAT     36
      ICOUNT=0                                                          UPYMAT     37
C                                                                       UPYMAT     38
 90   CONTINUE                                                          UPYMAT     39
      READ(IU12,3050)JTYP                                               UPYMAT     40
      BACKSPACE IU12                                                    UPYMAT     41
      IF(JTYP.EQ.2 .OR. JTYP.EQ.6 .OR. JTYP.EQ.12 .OR. JTYP.EQ.18)THEN  UPYMAT     42
      READ(IU12,3080) JTYP,NLFI,NLFJ,ICKT,GJJ,BJJ,GKK,BKK,              UPYMAT     43
     &                GJK,BJK,GKJ,BKJ,NMLINE,NJSELI                     UPYMAT     44
      ELSE                                                              UPYMAT     45
      READ(IU12,3050) JTYP,NLFI,NLFJ,ICKT,XREAL,XIMAG,VMG,VPHS,         UPYMAT     46
     &                VMG1,VPHS1,NMLINE,NJSELI                          UPYMAT     47
      ENDIF                                                             UPYMAT     48
C                                                                       UPYMAT     49
      ICOUNT=ICOUNT+1                                                   UPYMAT     50
C                                                                       UPYMAT     51
C   NETWORK CHANGES                                                     UPYMAT     52
C                                                                       UPYMAT     53
      NOLDI=NLFI                                                        UPYMAT     54
      NLFI=NOLD(NOLDI)                                                  UPYMAT     55
C                                                                       UPYMAT     56
      NOLDJ=NLFJ                                                        UPYMAT     57
      IF(NOLDJ.NE.0)NLFJ=NOLD(NOLDJ)                                    UPYMAT     58
C                                                                       UPYMAT     59
C            1   2   3   4   5   6   7   8   9  10  11  12              UPYMAT     60
C          ALI ATR APL ABT RLI RTR RPL RBT ASL RSL DLI DTR              UPYMAT     61
      GOTO(160,200,240,155,160,200,240,155,800,240,160,200              UPYMAT     62
C                                                                       UPYMAT     63
C       13  14  15  16  17  18  19  20  21  22  23  24  25              UPYMAT     64
C      DPL DLR DBT DSL MLI MTR MPL MSL RCG FCG  ZA  ZR  YK              UPYMAT     65
     &,240,165,155,240,150,180,220,800,220,220,140,140,140              UPYMAT     66
C                                                                       UPYMAT     67
C       26  27  28  29                                                  UPYMAT     68
C      LGF LLF LGR LLR                                                  UPYMAT     69
     &,130,130,130,130),JTYP                                            UPYMAT     70
 130  CONTINUE                                                          UPYMAT     71
C                                                                       UPYMAT     72
C         26  27  28  29                                                UPYMAT     73
C   ITYP=LGF,LLF,LGR,LLR                                                UPYMAT     74
C                                                                       UPYMAT     75
      IF(JTYP.EQ.26.OR.JTYP.EQ.28)THEN                                  UPYMAT     76
      XREAL=XREAL+VMG                                                   UPYMAT     77
      XIMAG=XIMAG+VPHS                                                  UPYMAT     78
      ZMAG=XREAL**2+XIMAG**2                                            UPYMAT     79
      XREAL=XREAL/ZMAG                                                  UPYMAT     80
      XIMAG=XIMAG/ZMAG                                                  UPYMAT     81
      ELSE                                                              UPYMAT     82
      ZMAG=XREAL**2+XIMAG**2                                            UPYMAT     83
      XREAL=XREAL/ZMAG                                                  UPYMAT     84
      XIMAG=XIMAG/ZMAG                                                  UPYMAT     85
      XREAL=XREAL+VMG/ZMAG                                              UPYMAT     86
      XIMAG=XIMAG+VPHS/ZMAG                                             UPYMAT     87
      ENDIF                                                             UPYMAT     88
C                                                                       UPYMAT     89
      IF(JTYP.LT.28)THEN                                                UPYMAT     90
      STAIRS(NOLDI)=STAIRS(NOLDI)+CMPLX(XREAL,-XIMAG)                   UPYMAT     91
      ELSE                                                              UPYMAT     92
      STAIRS(NOLDI)=STAIRS(NOLDI)-CMPLX(XREAL,-XIMAG)                   UPYMAT     93
      ENDIF                                                             UPYMAT     94
      GOTO  800                                                         UPYMAT     95
C                                                                       UPYMAT     96
 140  CONTINUE                                                          UPYMAT     97
C                                                                       UPYMAT     98
C        23 24 25                                                       UPYMAT     99
C   ITYP=ZA,ZR,YK                                                       UPYMAT    100
C                                                                       UPYMAT    101
      IF(JTYP.GT.24)THEN                                                UPYMAT    102
      STAIRS(NOLDI)=STAIRS(NOLDI)+CMPLX(XREAL,-XIMAG)                   UPYMAT    103
      ELSE                                                              UPYMAT    104
      ZMAG=XREAL**2+XIMAG**2                                            UPYMAT    105
      XREAL=XREAL/ZMAG                                                  UPYMAT    106
      XIMAG=XIMAG/ZMAG                                                  UPYMAT    107
         IF(JTYP.LT.24)THEN                                             UPYMAT    108
         STAIRS(NOLDI)=STAIRS(NOLDI)+CMPLX(XREAL,-XIMAG)                UPYMAT    109
         ELSE                                                           UPYMAT    110
         STAIRS(NOLDI)=STAIRS(NOLDI)-CMPLX(XREAL,-XIMAG)                UPYMAT    111
         ENDIF                                                          UPYMAT    112
      ENDIF                                                             UPYMAT    113
        STAR1=CABS(STAIRS(NOLDI))                                       UPYMAT    114
        IF(STAR1.LT.1.E-5)THEN                                          UPYMAT    115
         NISBUS=NISBUS+1                                                UPYMAT    116
         ISBUS(NISBUS)=NOLDI                                            UPYMAT    117
        ENDIF                                                           UPYMAT    118
      GOTO 800                                                          UPYMAT    119
C                                                                       UPYMAT    120
 150  CONTINUE                                                          UPYMAT    121
C                                                                       UPYMAT    122
C         17                                                            UPYMAT    123
C   TYPE=MLI                                                            UPYMAT    124
C                                                                       UPYMAT    125
      OXREAL=XREAL                                                      UPYMAT    126
      OXIMAG=XIMAG                                                      UPYMAT    127
      OVMG=VMG                                                          UPYMAT    128
      READ(IU12,3060) XREAL1,XIMAG1,VMG1                                UPYMAT    129
      ICOUNT=ICOUNT+1                                                   UPYMAT    130
      NETTOP=1                                                          UPYMAT    131
C                                                                       UPYMAT    132
      XREAL=XREAL1-OXREAL                                               UPYMAT    133
      XIMAG=XIMAG1-OXIMAG                                               UPYMAT    134
      VMG=VMG1-OVMG                                                     UPYMAT    135
C                                                                       UPYMAT    136
      LSTATU=0                                                          UPYMAT    137
      ASSIGN 170 TO I2000                                               UPYMAT    138
      GOTO 2000                                                         UPYMAT    139
C                                                                       UPYMAT    140
C     CODE FOR THE BUS TIE SWITCHING, TO BE ADDED LATER                 UPYMAT    141
C                                                                       UPYMAT    142
 155  CONTINUE                                                          UPYMAT    143
      LSTATU=0                                                          UPYMAT    144
      ASSIGN 156 TO I2000                                               UPYMAT    145
      GOTO 2000                                                         UPYMAT    146
 156  CONTINUE                                                          UPYMAT    147
          BRAU(LNET)=CMPLX(0.0,0.0)                                     UPYMAT    148
          BRAL(LNET)=CMPLX(0.0,0.0)                                     UPYMAT    149
          STAIRS(NLFI)=STAIRS(NLFI)+CMPLX(0.0,0.5*VMG)                  UPYMAT    150
          STAIRS(NLFJ)=STAIRS(NLFJ)+CMPLX(0.0,0.5*VMG)                  UPYMAT    151
      GOTO 800                                                          UPYMAT    152
C                                                                       UPYMAT    153
C                                                                       UPYMAT    154
C                                                                       UPYMAT    155
 160  CONTINUE                                                          UPYMAT    156
C          1   5  11                                                    UPYMAT    157
C   ITYP=ALI,RLI,DLI                                                    UPYMAT    158
C                                                                       UPYMAT    159
      NETTOP=1                                                          UPYMAT    160
C                                                                       UPYMAT    161
      IF(JTYP.GT.5) THEN                                                UPYMAT    162
      XREAL=-XREAL                                                      UPYMAT    163
      XIMAG=-XIMAG                                                      UPYMAT    164
      VMG=-VMG                                                          UPYMAT    165
      LSTATU=1                                                          UPYMAT    166
      ELSE                                                              UPYMAT    167
      LSTATU=0                                                          UPYMAT    168
      ENDIF                                                             UPYMAT    169
      ASSIGN 170 TO I2000                                               UPYMAT    170
      GOTO 2000                                                         UPYMAT    171
C                                                                       UPYMAT    172
C                                                                       UPYMAT    173
 165  CONTINUE                                                          UPYMAT    174
      IF(NJSELI.EQ.0)THEN                                               UPYMAT    175
       GOTO 160                                                         UPYMAT    176
      ELSE                                                              UPYMAT    177
       GOTO 240                                                         UPYMAT    178
      ENDIF                                                             UPYMAT    179
C                                                                       UPYMAT    180
C                                                                       UPYMAT    181
 170  CONTINUE                                                          UPYMAT    182
C                                                                       UPYMAT    183
C      OTHER BRANCHES                                                   UPYMAT    184
C                                                                       UPYMAT    185
         IF(JTYP.EQ.1)THEN                                              UPYMAT    186
          BRAU(LNET)=CMPLX(0.0,0.0)                                     UPYMAT    187
          BRAL(LNET)=CMPLX(0.0,0.0)                                     UPYMAT    188
         ENDIF                                                          UPYMAT    189
C                                                                       UPYMAT    190
         BRAU(LNET)=BRAU(LNET)+CMPLX(-GBUSX,BBUSX)                      UPYMAT    191
         BRAL(LNET)=BRAL(LNET)+CMPLX(-GBUSX,BBUSX)                      UPYMAT    192
C                                                                       UPYMAT    193
         BBUSX=0.5*VMG-BBUSX                                            UPYMAT    194
C                                                                       UPYMAT    195
         STAIRS(NOLDI)=STAIRS(NOLDI)+CMPLX(GBUSX,BBUSX)                 UPYMAT    196
         STAIRS(NOLDJ)=STAIRS(NOLDJ)+CMPLX(GBUSX,BBUSX)                 UPYMAT    197
      GOTO 2500                                                         UPYMAT    198
C                                                                       UPYMAT    199
 180  CONTINUE                                                          UPYMAT    200
C                                                                       UPYMAT    201
C         14                                                            UPYMAT    202
C   TYPE=MTR                                                            UPYMAT    203
C                                                                       UPYMAT    204
      OGJJ=GJJ                                                          UPYMAT    205
      OBJJ=BJJ                                                          UPYMAT    206
      OGKK=GKK                                                          UPYMAT    207
      OBKK=BKK                                                          UPYMAT    208
      OGJK=GJK                                                          UPYMAT    209
      OBJK=BJK                                                          UPYMAT    210
      OGKJ=GKJ                                                          UPYMAT    211
      OBKJ=BKJ                                                          UPYMAT    212
      READ(IU12,3090) GJJ1,BJJ1,GKK1,BKK1,GJK1,BJK1,GKJ1,BKJ1           UPYMAT    213
      ICOUNT=ICOUNT+1                                                   UPYMAT    214
      NETTOP=1                                                          UPYMAT    215
C                                                                       UPYMAT    216
      LSTATU=0                                                          UPYMAT    217
      ASSIGN 190 TO I2000                                               UPYMAT    218
      GOTO 2000                                                         UPYMAT    219
C                                                                       UPYMAT    220
 190  CONTINUE                                                          UPYMAT    221
C                                                                       UPYMAT    222
C   TRANSFORMER BRANCHES                                                UPYMAT    223
C                                                                       UPYMAT    224
       GJJ = GJJ1-OGJJ                                                  UPYMAT    225
       BJJ = BJJ1-OBJJ                                                  UPYMAT    226
       GKK = GKK1-OGKK                                                  UPYMAT    227
       BKK = BKK1-OBKK                                                  UPYMAT    228
       GJK = GJK1-OGJK                                                  UPYMAT    229
       BJK = BJK1-OBJK                                                  UPYMAT    230
       GKJ = GKJ1-OGKJ                                                  UPYMAT    231
       BKJ = BKJ1-OBKJ                                                  UPYMAT    232
C                                                                       UPYMAT    233
       STAIRS(NOLDI)=STAIRS(NOLDI)+CMPLX(GJJ,BJJ)                       UPYMAT    234
       STAIRS(NOLDJ)=STAIRS(NOLDJ)+CMPLX(GKK,BKK)                       UPYMAT    235
       BRAU(LNET)=BRAU(LNET)+CMPLX(GJK,BJK)                             UPYMAT    236
       BRAL(LNET)=BRAL(LNET)+CMPLX(GKJ,BKJ)                             UPYMAT    237
C                                                                       UPYMAT    238
      GOTO 2500                                                         UPYMAT    239
C                                                                       UPYMAT    240
 200  CONTINUE                                                          UPYMAT    241
C                                                                       UPYMAT    242
C         2   6  12                                                     UPYMAT    243
C  TYPE=ATR,RTR,DTR                                                     UPYMAT    244
C                                                                       UPYMAT    245
      NETTOP=1                                                          UPYMAT    246
C                                                                       UPYMAT    247
      IF(JTYP.GT.6)THEN                                                 UPYMAT    248
      LSTATU=1                                                          UPYMAT    249
      GJJ=-GJJ                                                          UPYMAT    250
      BJJ=-BJJ                                                          UPYMAT    251
      GKK=-GKK                                                          UPYMAT    252
      BKK=-BKK                                                          UPYMAT    253
      GJK=-GJK                                                          UPYMAT    254
      BJK=-BJK                                                          UPYMAT    255
      GKJ=-GKJ                                                          UPYMAT    256
      BKJ=-BKJ                                                          UPYMAT    257
      ELSE                                                              UPYMAT    258
      LSTATU=0                                                          UPYMAT    259
      ENDIF                                                             UPYMAT    260
      ASSIGN 210 TO I2000                                               UPYMAT    261
      GOTO 2000                                                         UPYMAT    262
 210  CONTINUE                                                          UPYMAT    263
C                                                                       UPYMAT    264
C     FOR ADD TRANSFORMER                                               UPYMAT    265
C                                                                       UPYMAT    266
         IF(JTYP.EQ.2)THEN                                              UPYMAT    267
          BRAU(LNET)=CMPLX(0.0,0.0)                                     UPYMAT    268
          BRAL(LNET)=CMPLX(0.0,0.0)                                     UPYMAT    269
         ENDIF                                                          UPYMAT    270
C                                                                       UPYMAT    271
C   TRANSFORMER BRANCHES                                                UPYMAT    272
C                                                                       UPYMAT    273
           STAIRS(NOLDI)=STAIRS(NOLDI)+CMPLX(GJJ,BJJ)                   UPYMAT    274
           STAIRS(NOLDJ)=STAIRS(NOLDJ)+CMPLX(GKK,BKK)                   UPYMAT    275
           BRAU(LNET)=BRAU(LNET)+CMPLX(GJK,BJK)                         UPYMAT    276
           BRAL(LNET)=BRAL(LNET)+CMPLX(GKJ,BKJ)                         UPYMAT    277
C                                                                       UPYMAT    278
      GOTO 2500                                                         UPYMAT    279
C                                                                       UPYMAT    280
 220  CONTINUE                                                          UPYMAT    281
C                                                                       UPYMAT    282
C         19  21  22                                                    UPYMAT    283
C   TYPE=MPL,RCG,FCG                                                    UPYMAT    284
C                                                                       UPYMAT    285
      OXREAL=XREAL                                                      UPYMAT    286
      OXIMAG=XIMAG                                                      UPYMAT    287
      OVMG=VMG                                                          UPYMAT    288
      OVPHS=VPHS                                                        UPYMAT    289
      OVMG1=VMG1                                                        UPYMAT    290
      OVPHS1=VPHS1                                                      UPYMAT    291
      READ(IU12,3060) XREAL1,XIMAG1,VMG1,VPHS1,VMG11,VPHS11             UPYMAT    292
      ICOUNT=ICOUNT+1                                                   UPYMAT    293
      NETTOP=1                                                          UPYMAT    294
C                                                                       UPYMAT    295
      XREAL=XREAL1-OXREAL                                               UPYMAT    296
      XIMAG=XIMAG1-OXIMAG                                               UPYMAT    297
      VMG=VMG1-OVMG                                                     UPYMAT    298
      VPHS=VPHS1-OVPHS                                                  UPYMAT    299
      VMG1=VMG11-OVMG1                                                  UPYMAT    300
      VPHS1=VPHS11-OVPHS1                                               UPYMAT    301
C                                                                       UPYMAT    302
      LSTATU=0                                                          UPYMAT    303
      ASSIGN 250 TO I2000                                               UPYMAT    304
      GOTO 2000                                                         UPYMAT    305
C                                                                       UPYMAT    306
C                                                                       UPYMAT    307
 240  CONTINUE                                                          UPYMAT    308
C                                                                       UPYMAT    309
C          3   7  10  13  16                                            UPYMAT    310
C   ITYP=APL,RPL,RSL,DPL,DSL                                            UPYMAT    311
C                                                                       UPYMAT    312
      NETTOP=1                                                          UPYMAT    313
C                                                                       UPYMAT    314
      IF(JTYP.GT.10) THEN                                               UPYMAT    315
      XREAL=-XREAL                                                      UPYMAT    316
      XIMAG=-XIMAG                                                      UPYMAT    317
      VMG=-VMG                                                          UPYMAT    318
      VPHS=-VPHS                                                        UPYMAT    319
      VMG1=-VMG1                                                        UPYMAT    320
      VPHS1=-VPHS1                                                      UPYMAT    321
      LSTATU=1                                                          UPYMAT    322
      ELSE                                                              UPYMAT    323
      LSTATU=0                                                          UPYMAT    324
      ENDIF                                                             UPYMAT    325
      ASSIGN 250 TO I2000                                               UPYMAT    326
      GOTO 2000                                                         UPYMAT    327
C                                                                       UPYMAT    328
 250  CONTINUE                                                          UPYMAT    329
C                                                                       UPYMAT    330
C     FOR ADD PI LINE                                                   UPYMAT    331
C                                                                       UPYMAT    332
         IF(JTYP.EQ.3)THEN                                              UPYMAT    333
          BRAU(LNET)=CMPLX(0.0,0.0)                                     UPYMAT    334
          BRAL(LNET)=CMPLX(0.0,0.0)                                     UPYMAT    335
         ENDIF                                                          UPYMAT    336
C                                                                       UPYMAT    337
C      PI  BRANCHES                                                     UPYMAT    338
C                                                                       UPYMAT    339
         BRAU(LNET)=BRAU(LNET)+CMPLX(-GBUSX,BBUSX)                      UPYMAT    340
         BRAL(LNET)=BRAL(LNET)+CMPLX(-GBUSX,BBUSX)                      UPYMAT    341
C                                                                       UPYMAT    342
         BBUSX=-BBUSX                                                   UPYMAT    343
C                                                                       UPYMAT    344
C   ACCOUNT THE SHUNTING COMPOMENTS OF PI LINE                          UPYMAT    345
C                                                                       UPYMAT    346
      IF(NOLDI.LT.NOLDJ)THEN                                            UPYMAT    347
      STAIRS(NOLDI)=STAIRS(NOLDI)+CMPLX(VMG+GBUSX,VPHS+BBUSX)           UPYMAT    348
      STAIRS(NOLDJ)=STAIRS(NOLDJ)+CMPLX(VMG1+GBUSX,VPHS1+BBUSX)         UPYMAT    349
      ELSE                                                              UPYMAT    350
      STAIRS(NOLDI)=STAIRS(NOLDI)+CMPLX(VMG1+GBUSX,VPHS1+BBUSX)         UPYMAT    351
      STAIRS(NOLDJ)=STAIRS(NOLDJ)+CMPLX(VMG+GBUSX,VPHS+BBUSX)           UPYMAT    352
      ENDIF                                                             UPYMAT    353
C                                                                       UPYMAT    354
C                                                                       UPYMAT    355
      GOTO 2500                                                         UPYMAT    356
C                                                                       UPYMAT    357
  800  CONTINUE                                                         UPYMAT    358
C                                                                       UPYMAT    359
C                                                                       UPYMAT    360
       IF(ICOUNT.LT.ISCARD)GOTO 90                                      UPYMAT    361
C                                                                       UPYMAT    362
      REWIND IU7                                                        UPYMAT    363
      WRITE(IU7)LLNET                                                   UPYMAT    364
      CALL CMPWR(IU7,0,LLNET,BRAU)                                      UPYMAT    365
      CALL CMPWR(IU7,0,LLNET,BRAL)                                      UPYMAT    366
C                                                                       UPYMAT    367
       RETURN                                                           UPYMAT    368
C                                                                       UPYMAT    369
 2000  CONTINUE                                                         UPYMAT    370
C                                                                       UPYMAT    371
C   MODIFY LINE IMPEDANCE FOR THE MOMITORED LINES                       UPYMAT    372
C                                                                       UPYMAT    373
      IF(NMLINE.NE.0)THEN                                               UPYMAT    374
C-- JNL IS THE POSITION POINTER TO THE END OF THE DATA FOR LINE "NMLINE"UPYMAT    375
      JNL=NMLINE*12                                                     UPYMAT    376
      ITFK=MLFTB(JNL-11)                                                UPYMAT    377
      CALL UPACKI(MTYPI,JJJ,ITFK)                                       UPYMAT    378
      CALL PACKII(MTYPI,LSTATU,ITFK)                                    UPYMAT    379
      MLFTB(JNL-11)=ITFK                                                UPYMAT    380
C                                                                       UPYMAT    381
C  CHECK IF LINE HAS BEEN MONITORED MORE THAN ONCE                      UPYMAT    382
C                                                                       UPYMAT    383
      CALL PACKII(NOLDI,NOLDJ,ITFK)                                     UPYMAT    384
      CALL PACKII(NOLDJ,NOLDI,JTFK)                                     UPYMAT    385
C                                                                       UPYMAT    386
C                                                                       UPYMAT    387
C    ADDED CODE FOR BRANCH MODIFICATION SWITCHING                       UPYMAT    388
C                                                                       UPYMAT    389
      JNL=0                                                             UPYMAT    390
      DO 2010 LL=1,NPFL                                                 UPYMAT    391
      JNL=JNL+12                                                        UPYMAT    392
      IF((MLFTB(JNL-10).EQ.ITFK).OR.(MLFTB(JNL-10).EQ.JTFK))THEN        UPYMAT    393
       JCKT=MACKT(JNL-9)                                                UPYMAT    394
       CALL UNPACK(CID,III,JCKT)                                        UPYMAT    395
       IF(ICKT(1:2).EQ.CID)THEN                                         UPYMAT    396
        JJJ=MLFTB(JNL-11)                                               UPYMAT    397
        CALL UPACKI(MTYPI,JJK,JJJ)                                      UPYMAT    398
        CALL PACKII(MTYPI,LSTATU,JJJ)                                   UPYMAT    399
        MLFTB(JNL-11)=JJJ                                               UPYMAT    400
C                                                                       UPYMAT    401
C    UPDATE THE PARAMETERS OF THE MODIFIED BRANCH                       UPYMAT    402
C                                                                       UPYMAT    403
        IF(JTYP.GE.17 .AND. JTYP.LE.22)THEN                             UPYMAT    404
          IF(JTYP.EQ.17)THEN                                            UPYMAT    405
           BLCF(JNL-4)=XREAL1                                           UPYMAT    406
           BLT(JNL-3)=XIMAG1                                            UPYMAT    407
           GLM(JNL-6)=XREAL1                                            UPYMAT    408
           BLM(JNL-5)=XIMAG1-0.5*VMG1                                   UPYMAT    409
          ELSEIF(JTYP.EQ.18)THEN                                        UPYMAT    410
           IF(MLFTB(JNL-10).EQ.ITFK)THEN                                UPYMAT    411
             BLCF(JNL-4)=-GJK1                                          UPYMAT    412
             BLT(JNL-3)=BJK1                                            UPYMAT    413
             GLM(JNL-6)=GJJ1                                            UPYMAT    414
             BLM(JNL-5)=-BJJ1                                           UPYMAT    415
           ELSE                                                         UPYMAT    416
             BLCF(JNL-4)=-GKJ1                                          UPYMAT    417
             BLT(JNL-3)=BKJ1                                            UPYMAT    418
             GLM(JNL-6)=GKK1                                            UPYMAT    419
             BLM(JNL-5)=-BKK1                                           UPYMAT    420
           ENDIF                                                        UPYMAT    421
          ELSEIF(JTYP.GT.18)THEN                                        UPYMAT    422
           BLCF(JNL-4)=XREAL1                                           UPYMAT    423
           BLT(JNL-3)=XIMAG1                                            UPYMAT    424
           GLM(JNL-6)=XREAL1+VMG1                                       UPYMAT    425
           BLM(JNL-5)=XIMAG1+VPHS1                                      UPYMAT    426
          ENDIF                                                         UPYMAT    427
         ENDIF                                                          UPYMAT    428
        ENDIF                                                           UPYMAT    429
       ENDIF                                                            UPYMAT    430
 2010 CONTINUE                                                          UPYMAT    431
      ENDIF                                                             UPYMAT    432
C                                                                       UPYMAT    433
C   UPDATE THE GA AND BA ARRAY                                          UPYMAT    434
C                                                                       UPYMAT    435
      CID=ICKT(1:2)                                                     UPYMAT    436
      CALL LOLIN2(NOLDI,NOLDJ,CID,LNET)                                 UPYMAT    437
C                                                                       UPYMAT    438
      IF(LNET.GT.LLNET)LLNET=LNET                                       UPYMAT    439
C                                                                       UPYMAT    440
      GBUSX=XREAL                                                       UPYMAT    441
      BBUSX=XIMAG                                                       UPYMAT    442
C                                                                       UPYMAT    443
      GOTO I2000                                                        UPYMAT    444
C                                                                       UPYMAT    445
 2500 CONTINUE                                                          UPYMAT    446
C                                                                       UPYMAT    447
C   CHECK ZERO BRANCH                                                   UPYMAT    448
C                                                                       UPYMAT    449
      ABSU=CABS(BRAU(LNET))                                             UPYMAT    450
      ABSL=CABS(BRAL(LNET))                                             UPYMAT    451
C                                                                       UPYMAT    452
      STAR1=CABS(STAIRS(NOLDI))                                         UPYMAT    453
      STAR2=CABS(STAIRS(NOLDJ))                                         UPYMAT    454
C                                                                       UPYMAT    455
        IF(STAR1.LT.1.E-5)THEN                                          UPYMAT    456
         NISBUS=NISBUS+1                                                UPYMAT    457
         ISBUS(NISBUS)=NOLDI                                            UPYMAT    458
        ENDIF                                                           UPYMAT    459
        IF(STAR2.LT.1.E-5)THEN                                          UPYMAT    460
         NISBUS=NISBUS+1                                                UPYMAT    461
         ISBUS(NISBUS)=NOLDJ                                            UPYMAT    462
        ENDIF                                                           UPYMAT    463
C                                                                       UPYMAT    464
      IF(ABSU.LT.1.E-5) BRAU(LNET)=CMPLX(0.0,1.E-5)                     UPYMAT    465
      IF(ABSL.LT.1.E-5) BRAL(LNET)=CMPLX(0.0,1.E-5)                     UPYMAT    466
      GOTO 800                                                          UPYMAT    467
C                                                                       UPYMAT    468
C                                                                       UPYMAT    469
 3050 FORMAT(I3,1X,2I5,1X,A4,6F10.5,2I5)                                UPYMAT    470
 3060 FORMAT(19X,6F10.5)                                                UPYMAT    471
 3080 FORMAT(I3,1X,2I5,1X,A4,8F10.5,2I5)                                UPYMAT    472
 3090 FORMAT(19X,8F10.5)                                                UPYMAT    473
                                                                        UPYMAT    474
      END                                                               UPYMAT    475
