CFPRIME BRFLOS                                                          BRFLOS      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  BRFLOS (JBRK, NOD, CURRNT, POWER)                     BRFLOS      3
CD -------------------------------------------------------------------  BRFLOS      4
CD                                                                      BRFLOS      5
CD              *****     BRFLOS  ROUTINE   *****                       BRFLOS      6
CD                                                                      BRFLOS      7
CD -------------------------------------------------------------------  BRFLOS      8
CD                                                                      BRFLOS      9
CD       PURPOSE:  This routine calculates the current and power        BRFLOS     10
CD                 leaving the node 'NOD' through the breaker 'JBRK'.   BRFLOS     11
CD                                                                      BRFLOS     12
CD       NOTE:     This is a recursive algorithm.                       BRFLOS     13
CD                                                                      BRFLOS     14
CD                                                                      BRFLOS     15
CD       DEFINITION OF LOCAL VARIABLES:                                 BRFLOS     16
CD          (P)    JBRK    -  Breaker number.                           BRFLOS     17
CD                 JBRKNU -  Local copy of breaker number.              BRFLOS     18
CD                 CURR   -  Stack of breaker current values.           BRFLOS     19
CD          (P)    CURRNT -  Breaker current.                           BRFLOS     20
CD                 I      -  Loop counter.                              BRFLOS     21
CD                 CFLOW  -  Line current.                              BRFLOS     22
CD                 INDEX  -  Stack of loop indexes.                     BRFLOS     23
CD                 J      -  Loop counter.                              BRFLOS     24
CD          (P)    NOD    -  Node name.                                 BRFLOS     25
CD                 NODE   -  Local copy of node name.                   BRFLOS     26
CD                 NAME   -  Stack of node names.                       BRFLOS     27
CD                 NUM    -  Stack of breaker numbers.                  BRFLOS     28
CD                 JPOSN   -  Position pointer.                         BRFLOS     29
CD          (P)    POWER  -  Breaker power.                             BRFLOS     30
CD                 POWR   -  Stack of power values.                     BRFLOS     31
CD                 JREMID -  Remote node number.                        BRFLOS     32
CD                 REMOTE -  Remote node name.                          BRFLOS     33
CD                 JSECID -  This node number.                          BRFLOS     34
CD                 JSIGN   -  Indicates sign of calculations.           BRFLOS     35
CD                 JSTACK  -  Stack pointer.                            BRFLOS     36
CD                 THISVD -  Voltage at this node.                      BRFLOS     37
CD                                                                      BRFLOS     38
CD -------------------------------------------------------------------  BRFLOS     39
      INCLUDE 'CNUNIT.INS'                                              BRFLOS     40
      INCLUDE 'PARX.INS'                                                BRFLOS     41
      INCLUDE 'GRDC01.INS'                                              BRFLOS     42
      INCLUDE 'GRDC03.INS'                                              BRFLOS     43
      INCLUDE 'CNMSG.INS'                                               BRFLOS     44
C                                                                       BRFLOS     45
      DIMENSION     CURR(NDCB), POWR(NDCB), INDEX(NDCB), NUM(NDCB)      BRFLOS     46
C                                                                       BRFLOS     47
      CHARACTER*8   NAME(NDCB), NOD, NODE, REMOTE                       BRFLOS     48
C                                                                       BRFLOS     49
C---------------------------------------------------------------------  BRFLOS     50
C                                                                       BRFLOS     51
C     AsSIGN the parameters to local variables, to prevent              BRFLOS     52
C     overwriting them.                                                 BRFLOS     53
C                                                                       BRFLOS     54
      NODE = NOD                                                        BRFLOS     55
      JBRKNU = JBRK                                                     BRFLOS     56
C                                                                       BRFLOS     57
      JSIGN = 1                                                         BRFLOS     58
      JSTACK = 0                                                        BRFLOS     59
      CURRNT = 0.0                                                      BRFLOS     60
      POWER = 0.0                                                       BRFLOS     61
C                                                                       BRFLOS     62
      IF (NODE .EQ. 'GROUND') THEN                                      BRFLOS     63
         WRITE(MSG(1),9000)                                             BRFLOS     64
         WRITE(MSG(2),9010) DCBNMR(JBRKNU)                              BRFLOS     65
         WRITE(MSG(3),9020)                                             BRFLOS     66
         CALL PRTMSG(3)                                                 BRFLOS     67
         GO TO 160                                                      BRFLOS     68
      END IF                                                            BRFLOS     69
C                                                                       BRFLOS     70
20    CONTINUE                                                          BRFLOS     71
C     --------------------------------------                            BRFLOS     72
C     Start processing for this breaker/node.                           BRFLOS     73
C     --------------------------------------                            BRFLOS     74
C                                                                       BRFLOS     75
      IF (IBSTAT(JBRKNU) .EQ. IOPEND) THEN                              BRFLOS     76
         CURRNT = 0.0                                                   BRFLOS     77
         POWER = 0.0                                                    BRFLOS     78
         GO TO 160                                                      BRFLOS     79
      END IF                                                            BRFLOS     80
C                                                                       BRFLOS     81
C     Determine the node index.                                         BRFLOS     82
C                                                                       BRFLOS     83
      JSECID = 0                                                        BRFLOS     84
      DO 40 I = 1, NONODR                                               BRFLOS     85
         IF (IDCNOD(I) .EQ. NODE) JSECID=NODIDX(I)                      BRFLOS     86
40    CONTINUE                                                          BRFLOS     87
      IF (JSECID .EQ. 0) THEN                                           BRFLOS     88
         THISVD = 0.0                                                   BRFLOS     89
      ELSE                                                              BRFLOS     90
         THISVD = VDCNOD(JSECID)                                        BRFLOS     91
      END IF                                                            BRFLOS     92
C                                                                       BRFLOS     93
C     Accumulate the total converter current at this node.              BRFLOS     94
C                                                                       BRFLOS     95
      DO 60 I = 1, ICDC                                                 BRFLOS     96
         JPOSN = IDC(I)                                                 BRFLOS     97
         IF (NODE .EQ. DCCNMR(JPOSN)(1:8)) THEN                         BRFLOS     98
            POWER = POWER + (THISVD * XDCONV(JPOSN))                    BRFLOS     99
            CURRNT = CURRNT + (XDCONV(JPOSN) * 1000.0)                  BRFLOS    100
         ELSE IF (NODE .EQ. DCCNMR(JPOSN)(9:16)) THEN                   BRFLOS    101
            POWER = POWER - (THISVD * XDCONV(JPOSN))                    BRFLOS    102
            CURRNT = CURRNT - (XDCONV(JPOSN) * 1000.0)                  BRFLOS    103
         END IF                                                         BRFLOS    104
60    CONTINUE                                                          BRFLOS    105
C                                                                       BRFLOS    106
C     Accumulate total line current for this node.                      BRFLOS    107
C                                                                       BRFLOS    108
      DO 100 I = 1, ILDC                                                BRFLOS    109
         JPOSN = IDCL(I)                                                BRFLOS    110
         IF (NODE .EQ. DCLNMR(JPOSN)(1:8) .OR.                          BRFLOS    111
     1       NODE .EQ. DCLNMR(JPOSN)(9:16)) THEN                        BRFLOS    112
            IF (NODE .EQ. DCLNMR(JPOSN)(1:8)) THEN                      BRFLOS    113
               REMOTE = DCLNMR(JPOSN)(9:16)                             BRFLOS    114
            ELSE                                                        BRFLOS    115
               REMOTE = DCLNMR(JPOSN)(1:8)                              BRFLOS    116
            END IF                                                      BRFLOS    117
            JREMID = 0                                                  BRFLOS    118
            DO 80 J = 1, NONODR                                         BRFLOS    119
               IF (REMOTE .EQ. IDCNOD(J)) JREMID=NODIDX(J)              BRFLOS    120
80          CONTINUE                                                    BRFLOS    121
            IF (JREMID .NE. 0) THEN                                     BRFLOS    122
               CFLOW  = (VDCNOD(JREMID) - THISVD) / RDCOHM(JPOSN)       BRFLOS    123
            ELSE                                                        BRFLOS    124
               CFLOW  = (0.0 - THISVD) / RDCOHM(JPOSN)                  BRFLOS    125
            END IF                                                      BRFLOS    126
            POWER = POWER + (CFLOW * THISVD)                            BRFLOS    127
            CURRNT = CURRNT + (CFLOW * 1000.0)                          BRFLOS    128
         END IF                                                         BRFLOS    129
100   CONTINUE                                                          BRFLOS    130
C                                                                       BRFLOS    131
C     Accumulate the total breaker current for this node.               BRFLOS    132
C                                                                       BRFLOS    133
      I = 1                                                             BRFLOS    134
C                                                                       BRFLOS    135
120   CONTINUE                                                          BRFLOS    136
C     ------------------------------------                              BRFLOS    137
C     Continue processing the next breaker.                             BRFLOS    138
C     ------------------------------------                              BRFLOS    139
C                                                                       BRFLOS    140
      IF (I .GT. IBDC) GO TO 160                                        BRFLOS    141
         JPOSN = IDCB(I)                                                BRFLOS    142
         IF (DCBNMR(JPOSN)(1:8) .EQ. NODE .OR.                          BRFLOS    143
     1       DCBNMR(JPOSN)(9:16) .EQ. NODE) THEN                        BRFLOS    144
            IF (JPOSN .NE. JBRKNU) THEN                                 BRFLOS    145
C                                                                       BRFLOS    146
C              Get the current for this new breaker by storing          BRFLOS    147
C              the environment on the stack and starting the            BRFLOS    148
C              routine over.                                            BRFLOS    149
C                                                                       BRFLOS    150
               JSTACK = JSTACK + 1                                      BRFLOS    151
               NAME(JSTACK) = NODE                                      BRFLOS    152
               NUM(JSTACK) = JBRKNU                                     BRFLOS    153
               CURR(JSTACK) = CURRNT                                    BRFLOS    154
               POWR(JSTACK) = POWER                                     BRFLOS    155
               INDEX(JSTACK) = I                                        BRFLOS    156
C                                                                       BRFLOS    157
C              Establish the starting environment for the new           BRFLOS    158
C              breaker.                                                 BRFLOS    159
C                                                                       BRFLOS    160
               JBRKNU = JPOSN                                           BRFLOS    161
               CURRNT = 0.0                                             BRFLOS    162
               POWER = 0.0                                              BRFLOS    163
               IF (DCBNMR(JBRKNU)(1:8) .EQ. NODE) THEN                  BRFLOS    164
                  NODE = DCBNMR(JBRKNU)(9:16)                           BRFLOS    165
               ELSE                                                     BRFLOS    166
                  NODE = DCBNMR(JBRKNU)(1:8)                            BRFLOS    167
               END IF                                                   BRFLOS    168
C                                                                       BRFLOS    169
               DO 140 J = 1, JSTACK                                     BRFLOS    170
C                                                                       BRFLOS    171
C                 If the new node is in the stack, then a               BRFLOS    172
C                 "BREAKER RING' has been detected, and the current     BRFLOS    173
C                 cannot be determined.                                 BRFLOS    174
C                                                                       BRFLOS    175
                  IF (NAME(J) .EQ. NODE) THEN                           BRFLOS    176
                     WRITE(MSG(1),9100)                                 BRFLOS    177
                     WRITE(MSG(2),9110) NAME(1)                         BRFLOS    178
                     WRITE(MSG(3),9120) DCBNMR(NUM(1))                  BRFLOS    179
                     WRITE(MSG(4),9130) NODE                            BRFLOS    180
                     CALL PRTMSG(4)                                     BRFLOS    181
C                                                                       BRFLOS    182
C                    Remove this node from consideration all together.  BRFLOS    183
C                                                                       BRFLOS    184
                     GO TO 160                                          BRFLOS    185
                  END IF                                                BRFLOS    186
140            CONTINUE                                                 BRFLOS    187
C                                                                       BRFLOS    188
               IF (NODE .EQ. 'GROUND') THEN                             BRFLOS    189
C                                                                       BRFLOS    190
C                 A closed breaker to GROUND has been found in the      BRFLOS    191
C                 solution path. This makes the current on this         BRFLOS    192
C                 path impossible to determine. To solve for the        BRFLOS    193
C                 original breaker current then, the solution must      BRFLOS    194
C                 be backed up to the given breaker and node and the    BRFLOS    195
C                 current on the OTHER node determined. This current    BRFLOS    196
C                 will be the negative of the desired current.          BRFLOS    197
C                                                                       BRFLOS    198
                  IF (JSIGN .EQ. -1) THEN                               BRFLOS    199
C                                                                       BRFLOS    200
C                    Both nodes for the given breaker have been         BRFLOS    201
C                    processed and a closed breaker to GROUND has       BRFLOS    202
C                    been found in each path.                           BRFLOS    203
C                                                                       BRFLOS    204
                     WRITE(MSG(1),9200) NAME(1)                         BRFLOS    205
                     WRITE(MSG(2),9210) DCBNMR(NUM(1))                  BRFLOS    206
                     WRITE(MSG(3),9220)                                 BRFLOS    207
                     CALL PRTMSG(3)                                     BRFLOS    208
                     JSTACK = 0                                         BRFLOS    209
                     GO TO 160                                          BRFLOS    210
                  ELSE                                                  BRFLOS    211
                     JSIGN = -1                                         BRFLOS    212
                     JSTACK = 0                                         BRFLOS    213
                     JBRKNU = NUM(1)                                    BRFLOS    214
                     IF (DCBNMR(JBRKNU)(1:8) .EQ. NAME(1)) THEN         BRFLOS    215
                        NODE = DCBNMR(JBRKNU)(9:16)                     BRFLOS    216
                     ELSE                                               BRFLOS    217
                        NODE = DCBNMR(JBRKNU)(1:8)                      BRFLOS    218
                     END IF                                             BRFLOS    219
                     IF (NODE .EQ. 'GROUND') THEN                       BRFLOS    220
                        WRITE(MSG(1),9200) NAME(1)                      BRFLOS    221
                        WRITE(MSG(2),9210) DCBNMR(NUM(1))               BRFLOS    222
                        WRITE(MSG(3),9220)                              BRFLOS    223
                        CALL PRTMSG(3)                                  BRFLOS    224
                        GO TO 160                                       BRFLOS    225
                     END IF                                             BRFLOS    226
                  END IF                                                BRFLOS    227
               END IF                                                   BRFLOS    228
C                                                                       BRFLOS    229
               GO TO 20                                                 BRFLOS    230
C                                                                       BRFLOS    231
            END IF                                                      BRFLOS    232
         END IF                                                         BRFLOS    233
         I = I + 1                                                      BRFLOS    234
         GO TO 120                                                      BRFLOS    235
C                                                                       BRFLOS    236
160   CONTINUE                                                          BRFLOS    237
C     ---------------------------------------                           BRFLOS    238
C     End of processing for this breaker/node.                          BRFLOS    239
C     ---------------------------------------                           BRFLOS    240
C                                                                       BRFLOS    241
C     The current has been calculated for this breaker. If this was     BRFLOS    242
C     an intermediate step for the calculation of the original          BRFLOS    243
C     breaker, then add the current to the old total and continue       BRFLOS    244
C     with the interrupted processing.                                  BRFLOS    245
C                                                                       BRFLOS    246
      IF (JSTACK .GT. 0) THEN                                           BRFLOS    247
C                                                                       BRFLOS    248
C        Pop the stack.                                                 BRFLOS    249
C                                                                       BRFLOS    250
         CURRNT = CURR(JSTACK) + CURRNT                                 BRFLOS    251
         POWER = POWR(JSTACK) + POWER                                   BRFLOS    252
         I = INDEX(JSTACK) + 1                                          BRFLOS    253
         JBRKNU = NUM(JSTACK)                                           BRFLOS    254
         NODE = NAME(JSTACK)                                            BRFLOS    255
         JSTACK = JSTACK - 1                                            BRFLOS    256
C                                                                       BRFLOS    257
         GO TO 120                                                      BRFLOS    258
      END IF                                                            BRFLOS    259
C                                                                       BRFLOS    260
      CURRNT = CURRNT * JSIGN                                           BRFLOS    261
      POWER = POWER * JSIGN                                             BRFLOS    262
C                                                                       BRFLOS    263
C                                                                       BRFLOS    264
C---------------------------------------------------------------------  BRFLOS    265
C                                                                       BRFLOS    266
      RETURN                                                            BRFLOS    267
C                                                                       BRFLOS    268
C---------------------------------------------------------------------  BRFLOS    269
C                                                                       BRFLOS    270
 9000 FORMAT(' *** MTDC ERROR THE CURRENT LEAVING "GROUND" THROUGH')    BRFLOS    271
 9010 FORMAT(14X,'BREAKER "',A17,'" CANNOT BE DETERMINED.')             BRFLOS    272
 9020 FORMAT(14X,'THIS IS A PROGRAM ERROR.')                            BRFLOS    273
 9100 FORMAT(' *** MTDC WARNING A BREAKER RING HAS BEEN DETECTED'       BRFLOS    274
     *,' WHILE CALCULATING')                                            BRFLOS    275
 9110 FORMAT(14X,'THE CURRENT LEAVING NODE "',A8,' THROUGH')            BRFLOS    276
 9120 FORMAT(14X,'BREAKER "',A17,'".')                                  BRFLOS    277
 9130 FORMAT(14X,'NODE "',A8,'" HAS BEEN REMOVE FROM CONSIDERATION.')   BRFLOS    278
 9200 FORMAT(                                                           BRFLOS    279
     *' *** MTDC ERROR THE CURRENT LEAVING NODE "',A8,'" THROUGH')      BRFLOS    280
 9210 FORMAT(14X,'BREAKER "',A17,'" CANNOT BE DETERMINED.  BECAUSE')    BRFLOS    281
 9220 FORMAT(14X                                                        BRFLOS    282
     *,'BOTH NODES FOR THE BREAKER ARE CONNECTED TO "GROUND".')         BRFLOS    283
C                                                                       BRFLOS    284
C---------------------------------------------------------------------  BRFLOS    285
C                                                                       BRFLOS    286
      END                                                               BRFLOS    287
