CFPRIME DCOMON                                                          DCOMON      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 DCOMON                                                 DCOMON      3
CD                                                                      DCOMON      4
CD   THIS SUBROUTINE CHECKS THE TRIPPING STATUS OF DOUBLE CIRCLES OR    DCOMON      5
C    LENS OUT-OF-STEP RELAYS                                            DCOMON      6
CD                                                                      DCOMON      7
      INCLUDE 'PARX.INS'                                                DCOMON      8
      INCLUDE 'CNPT.INS'                                                DCOMON      9
      INCLUDE 'CNAUTO.INS'                                              DCOMON     10
      INCLUDE 'CNVOLT.INS'                                              DCOMON     11
      INCLUDE 'CNFLAG.INS'                                              DCOMON     12
      INCLUDE 'CNB4.INS'                                                DCOMON     13
      INCLUDE 'CNB19.INS'                                               DCOMON     14
      INCLUDE 'CNUNIT.INS'                                              DCOMON     15
C                                                                       DCOMON     16
      LOGICAL TRPMOD,LHIGH,OUTSTP                                       DCOMON     17
      CHARACTER*2 CID                                                   DCOMON     18
C                                                                       DCOMON     19
      COMPLEX VOLTK                                                     DCOMON     20
      DIMENSION VOLTX(2)                                                DCOMON     21
      EQUIVALENCE (VOLTK,VOLTX(1)),(VOLTX(1),VREAL),(VOLTX(2),VIMAG)    DCOMON     22
C                                                                       DCOMON     23
      LDEB=.FALSE.                                                      DCOMON     24
C                                                                       DCOMON     25
      DO 2400 I=LDCOSR,NDCOSR                                           DCOMON     26
C                                                                       DCOMON     27
      K = IDATPT(I)                                                     DCOMON     28
      ICD1 = IADATA(K+1)                                                DCOMON     29
C                                                                       DCOMON     30
      IF(ICD1.GT.9)GOTO 2400                                            DCOMON     31
C                                                                       DCOMON     32
      ICD4 = IADATA(K+7)                                                DCOMON     33
C                                                                       DCOMON     34
C       IF ICD1 = 5  BOTH LOCAL AND ROMTED TRIPPING HAVE BEEN COMPLETED DCOMON     35
C                                                                       DCOMON     36
      IF(ICD1 .EQ. 5)GOTO 2400                                          DCOMON     37
C * * *                                                                 DCOMON     38
C * * * IF ICD1 = 4, LOCAL LINE TRIPPED, REMOTE TRIPPING IN PROGRESS    DCOMON     39
C * * *                                                                 DCOMON     40
      IF(ICD1 .EQ. 4) GO TO 2350                                        DCOMON     41
C * * *                                                                 DCOMON     42
C * * *  IF ICD1 = 2 LOCAL RELAY TRIPPED,LINE BREAKER NOT OPENNED YET,  DCOMON     43
C * * *  REMOTE TRIP IN PROGRESS                                        DCOMON     44
C * * *                                                                 DCOMON     45
      IF(ICD1 .EQ. 2)GO TO 2300                                         DCOMON     46
C                                                                       DCOMON     47
C  CURRENT AND APPARENT IMPEDANCE CALCULATION                           DCOMON     48
C                                                                       DCOMON     49
      IBUS = IADATA(K+2)                                                DCOMON     50
      JBUS = IADATA(K+3)                                                DCOMON     51
      ITFK = IADATA(K+4)                                                DCOMON     52
      CALL UNPACK (CID, JJJ, ITFK)                                      DCOMON     53
C                                                                       DCOMON     54
      GIJ = ADATA(K+23)                                                 DCOMON     55
      BIJ = ADATA(K+24)                                                 DCOMON     56
      GIO = ADATA(K+25)                                                 DCOMON     57
      BIO = ADATA(K+26)                                                 DCOMON     58
C                                                                       DCOMON     59
      VOLTK=VOLT(IBUS)                                                  DCOMON     60
      EI = VREAL                                                        DCOMON     61
      FI = VIMAG                                                        DCOMON     62
      VOLTK=VOLT(JBUS)                                                  DCOMON     63
      EJ = VREAL                                                        DCOMON     64
      FJ = VIMAG                                                        DCOMON     65
C                                                                       DCOMON     66
      GT=GIJ+GIO                                                        DCOMON     67
      BT=BIJ+BIO                                                        DCOMON     68
      C1R=EI*GT-FI*BT                                                   DCOMON     69
      C1I=EI*BT+FI*GT                                                   DCOMON     70
      C2R=EJ*GIJ-FJ*BIJ                                                 DCOMON     71
      C2I=EJ*BIJ+FJ*GIJ                                                 DCOMON     72
      CTR=C1R-C2R                                                       DCOMON     73
      CTI=C1I-C2I                                                       DCOMON     74
      CURRNT=SQRT(CTR*CTR+CTI*CTI)                                      DCOMON     75
      IF( ABS(CTR)+ ABS(CTI).EQ. 0.0) CTR=0.0001                        DCOMON     76
      ZR=(EI*CTR+FI*CTI)/(CTR*CTR+CTI*CTI)                              DCOMON     77
      ZI=(FI*CTR-EI*CTI)/(CTR*CTR+CTI*CTI)                              DCOMON     78
C                                                                       DCOMON     79
C      TO CHECK-LOCUS                                                   DCOMON     80
C                                                                       DCOMON     81
C ------                                                                DCOMON     82
C   CHECK ZONE AND STORE THE ZONE NO.                                   DCOMON     83
C ------                                                                DCOMON     84
      IZONE=0                                                           DCOMON     85
      TRPMOD=.FALSE.                                                    DCOMON     86
C                                                                       DCOMON     87
      XR=ADATA(K+11)*COS(ADATA(K+10))                                   DCOMON     88
      XI=ADATA(K+11)*SIN(ADATA(K+10))                                   DCOMON     89
      DZR=ZR-XR                                                         DCOMON     90
      DZI=ZI-XI                                                         DCOMON     91
      S=2.0*SQRT(DZR*DZR+DZI*DZI)                                       DCOMON     92
C                                                                       DCOMON     93
      TRPMOD=IADATA(K+6).GT.0                                           DCOMON     94
      II=IABS(IADATA(K+6))                                              DCOMON     95
C                                                                       DCOMON     96
C                                                                       DCOMON     97
      IF(II.EQ.1 )THEN                                                  DCOMON     98
C                                                                       DCOMON     99
        IF(S .LT. ADATA(K+9))THEN                                       DCOMON    100
          IZONE=1                                                       DCOMON    101
        ELSE                                                            DCOMON    102
          XR=ADATA(K+14)*COS(ADATA(K+13))                               DCOMON    103
          XI=ADATA(K+14)*SIN(ADATA(K+13))                               DCOMON    104
          DZR=ZR-XR                                                     DCOMON    105
          DZI=ZI-XI                                                     DCOMON    106
          S1=2.0*SQRT(DZR*DZR+DZI*DZI)                                  DCOMON    107
          IF( S1.LT.ADATA(K+12) )IZONE=2                                DCOMON    108
        ENDIF                                                           DCOMON    109
      ENDIF                                                             DCOMON    110
C                                                                       DCOMON    111
      IF(II.EQ.2)THEN                                                   DCOMON    112
        XR=ADATA(K+14)*COS(ADATA(K+13))                                 DCOMON    113
        XI=ADATA(K+14)*SIN(ADATA(K+13))                                 DCOMON    114
        DZR=ZR-XR                                                       DCOMON    115
        DZI=ZI-XI                                                       DCOMON    116
        S1=2.0*SQRT(DZR*DZR+DZI*DZI)                                    DCOMON    117
        IF(S.GT.S1)S1=S                                                 DCOMON    118
        IF(S1.LT. ADATA(K+9))IZONE=1                                    DCOMON    119
        IF(S1.LT. ADATA(K+12))IZONE=2                                   DCOMON    120
      ENDIF                                                             DCOMON    121
C                                                                       DCOMON    122
C                                                                       DCOMON    123
C                                                                       DCOMON    124
C  --------                                                             DCOMON    125
C  CHECK BLINDER                                                        DCOMON    126
C  --------                                                             DCOMON    127
C                                                                       DCOMON    128
      IBLIN1=0                                                          DCOMON    129
      IBLIN2=0                                                          DCOMON    130
      IF(IZONE.NE.0)THEN                                                DCOMON    131
        IF (ADATA(K+17).NE.0)THEN                                       DCOMON    132
          ISTART=K+17                                                   DCOMON    133
          CALL CHECKB(ISTART,IBLIN1,ZR,ZI)                              DCOMON    134
        ENDIF                                                           DCOMON    135
        IF (ADATA(K+21).NE.0)THEN                                       DCOMON    136
          ISTART=K+21                                                   DCOMON    137
          CALL CHECKB(ISTART,IBLIN2,ZR,ZI)                              DCOMON    138
        ENDIF                                                           DCOMON    139
      ENDIF                                                             DCOMON    140
C                                                                       DCOMON    141
C    -VE OF IZONE MEAN BEHIND THE BLINDER                               DCOMON    142
C                                                                       DCOMON    143
      IF (IBLIN1.EQ.1 .OR. IBLIN2.EQ.1) IZONE=-IZONE                    DCOMON    144
C                                                                       DCOMON    145
C   CHECK AND UPDATE FOR ZONE CHANGE                                    DCOMON    146
C                                                                       DCOMON    147
      IF(IADATA(K+31).NE.IZONE )IADATA(K+31)=IZONE                      DCOMON    148
C                                                                       DCOMON    149
C ------------------                                                    DCOMON    150
C                                                                       DCOMON    151
C  CHECK AGAINST THE THREHOLD CURRENT                                   DCOMON    152
C                                                                       DCOMON    153
C -------------------                                                   DCOMON    154
C                                                                       DCOMON    155
      LHIGH=CURRNT.GT.ADATA(K+15)                                       DCOMON    156
                                                                        DCOMON    157
C ----                                                                  DCOMON    158
C                                                                       DCOMON    159
C   START INTER ZONE TRAVEL TIME                                        DCOMON    160
C                                                                       DCOMON    161
C ---                                                                   DCOMON    162
      IF(IZONE.EQ.2 .AND. LHIGH)THEN                                    DCOMON    163
C                                                                       DCOMON    164
C   IADATA(K+29)=0 TIMER NOT STARTED | IADATA(K+30)=0 TIMER TIMEOUT     DCOMON    165
C                                                                       DCOMON    166
        IF(IADATA(K+29).EQ.0 .AND. IADATA(K+30).EQ.0)THEN               DCOMON    167
          IADATA(K+29) = 1                                              DCOMON    168
          ADATA(K+34)=TS+ADATA(K+8)                                     DCOMON    169
        ENDIF                                                           DCOMON    170
      ENDIF                                                             DCOMON    171
C ------                                                                DCOMON    172
C                                                                       DCOMON    173
C  CHECK ITER-ZONE TIME                                                 DCOMON    174
C                                                                       DCOMON    175
C ------                                                                DCOMON    176
      IF(IADATA(K+29).NE.0 .AND. IADATA(K+30).NE.1)THEN                 DCOMON    177
         IADATA(K+29) = 2                                               DCOMON    178
         IF(ADATA(K+34).LT.TS)IADATA(K+30)=1                            DCOMON    179
      ENDIF                                                             DCOMON    180
C ------                                                                DCOMON    181
C                                                                       DCOMON    182
C   CHECK OUT OF STEP                                                   DCOMON    183
C                                                                       DCOMON    184
C ------                                                                DCOMON    185
      OUTSTP=IADATA(K+30).EQ.1                                          DCOMON    186
C                                                                       DCOMON    187
      IF((IADATA(K+5).EQ.1))THEN                                        DCOMON    188
        IF(IADATA(K+32).EQ.0 .AND. IADATA(K+33).EQ.0)THEN               DCOMON    189
C                                                                       DCOMON    190
          IF(OUTSTP .AND. TRPMOD)THEN                                   DCOMON    191
            IADATA(K+32)=1                                              DCOMON    192
            ADATA(K+35)=ADATA(K+16)+TS                                  DCOMON    193
C ------                                                                DCOMON    194
C   ACTIVIATE REMOTE RELAYS                                             DCOMON    195
C ------                                                                DCOMON    196
            ICD1=2                                                      DCOMON    197
            IADATA(K+1) = ICD1                                          DCOMON    198
            IF(ICD4.NE.0)THEN                                           DCOMON    199
              KADD=K+36                                                 DCOMON    200
              CALL RTIMER(KADD,ICD4)                                    DCOMON    201
            ENDIF                                                       DCOMON    202
          ENDIF                                                         DCOMON    203
        ENDIF                                                           DCOMON    204
      ENDIF                                                             DCOMON    205
C                                                                       DCOMON    206
 2300  CONTINUE                                                         DCOMON    207
C -----                                                                 DCOMON    208
C  CHECK SELF TRIP TIMER                                                DCOMON    209
C -----                                                                 DCOMON    210
        IF(IADATA(K+32).NE.0 .AND. IADATA(K+33).NE.1)THEN               DCOMON    211
          ICD1=3                                                        DCOMON    212
          IADATA(K+1)=ICD1                                              DCOMON    213
          IADATA(K+32)=2                                                DCOMON    214
          IF(ADATA(K+35).LT.TS)IADATA(K+33)=1                           DCOMON    215
        ENDIF                                                           DCOMON    216
C -----                                                                 DCOMON    217
C  RESET INTER-ZONE TIMER                                               DCOMON    218
C -----                                                                 DCOMON    219
      IF(IZONE.NE.2 .AND. IADATA(K+29).NE.0)THEN                        DCOMON    220
        IADATA(K+29)=0                                                  DCOMON    221
        ADATA(K+35)=0.0                                                 DCOMON    222
      ENDIF                                                             DCOMON    223
c                                                                       DCOMON    224
C      IF (ADATA(K+8) .EQ. 1)THEN                                       DCOMON    225
C         IF (TS-ADATA(K+20) .GE. ADATA(K+15))THEN                      DCOMON    226
C            ADATA(K+8) = -1                                            DCOMON    227
C            WRITE (LOUT,1130) IADATA(K+2), TS                          DCOMON    228
C         ENDIF                                                         DCOMON    229
C      ENDIF                                                            DCOMON    230
C                                                                       DCOMON    231
      IF(ICD1 .NE. 3) GO TO 2350                                        DCOMON    232
C                                                                       DCOMON    233
C    GET THE LINE INFORMATION AND WRITE INTO IU12                       DCOMON    234
C                                                                       DCOMON    235
       ICD1=4                                                           DCOMON    236
       IADATA(K+1)=ICD1                                                 DCOMON    237
C                                                                       DCOMON    238
      IF(IADATA(K+5).EQ.1)THEN                                          DCOMON    239
       NJSELI=IADATA(K+28)                                              DCOMON    240
C                                                                       DCOMON    241
       IF(IASWX.EQ.0)THEN                                               DCOMON    242
        WRITE(ISWFA,4100)TS                                             DCOMON    243
 4100   FORMAT(F10.5)                                                   DCOMON    244
        NAWR=NAWR+1                                                     DCOMON    245
        IASWX=1                                                         DCOMON    246
       ENDIF                                                            DCOMON    247
C                                                                       DCOMON    248
       IF(NJSELI.NE.0)THEN                                              DCOMON    249
        WRITE(ISWFA,4200)IBUS,JBUS,CID                                  DCOMON    250
 4200   FORMAT('DPIA',2I5,1X,A2)                                        DCOMON    251
       ELSE                                                             DCOMON    252
        WRITE(ISWFA,4300)IBUS,JBUS,CID                                  DCOMON    253
 4300   FORMAT('DLIA',2I5,1X,A2)                                        DCOMON    254
       ENDIF                                                            DCOMON    255
C                                                                       DCOMON    256
       NAWR=NAWR+1                                                      DCOMON    257
C                                                                       DCOMON    258
      ENDIF                                                             DCOMON    259
C                                                                       DCOMON    260
C   ACTIVIATE THE RECLOSING TIMER                                       DCOMON    261
C                                                                       DCOMON    262
C      IF(ADATA(K+20).EQ.-1.0)ADATA(K+20)=ADATA(K+19)+TS                DCOMON    263
C                                                                       DCOMON    264
C                                                                       DCOMON    265
C * * * ICD4 IS THE NUMBER OF REMOTE RELAYS ATTACHED TO THIS LOCAL      DCOMON    266
C * * * RELAY.  TTIMR1 IS THE TRANSFER TRIP TIMER.                      DCOMON    267
C * * *                                                                 DCOMON    268
 2350 IF(ICD4.EQ.0) GO TO 2400                                          DCOMON    269
C                                                                       DCOMON    270
C * * *                                                                 DCOMON    271
C * * * PROCESS REMOTE RELAY LOGIC                                      DCOMON    272
C * * *                                                                 DCOMON    273
       IF(IADATA(K+5).EQ.1)THEN                                         DCOMON    274
        IF(IADATA(K+1).GE.2 .AND.IADATA(K+2).LE.4)THEN                  DCOMON    275
          KADD=K+36                                                     DCOMON    276
          KBUS=K                                                        DCOMON    277
          IPOINT=8                                                      DCOMON    278
          CALL RETRIP(KADD,KBUS,ICD4,IPOINT)                            DCOMON    279
          IF(IADATA(KBUS+IPOINT).EQ.-1)THEN                             DCOMON    280
           ICD1=4                                                       DCOMON    281
           IADATA(K+1) = ICD1                                           DCOMON    282
          ENDIF                                                         DCOMON    283
        ENDIF                                                           DCOMON    284
       ENDIF                                                            DCOMON    285
C                                                                       DCOMON    286
 2400 CONTINUE                                                          DCOMON    287
      RETURN                                                            DCOMON    288
      END                                                               DCOMON    289
