CFPRIME DDRMON                                                          DDRMON      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 DDRMON(K)                                              DDRMON      3
CD                                                                      DDRMON      4
CD    THIS SUBROUTINE CONTAINS SOLUTION LOGIC FOR THE DEFAULT DISTANCE  DDRMON      5
CD    RELAY.                                                            DDRMON      6
CD                                                                      DDRMON      7
      INCLUDE 'PARX.INS'                                                DDRMON      8
      INCLUDE 'CNPT.INS'                                                DDRMON      9
      INCLUDE 'CNAUTO.INS'                                              DDRMON     10
      INCLUDE 'CNVOLT.INS'                                              DDRMON     11
      INCLUDE 'CNFLAG.INS'                                              DDRMON     12
      INCLUDE 'CNB4.INS'                                                DDRMON     13
      INCLUDE 'CNB19.INS'                                               DDRMON     14
      INCLUDE 'CNUNIT.INS'                                              DDRMON     15
C                                                                       DDRMON     16
      CHARACTER*2 CID                                                   DDRMON     17
C                                                                       DDRMON     18
      COMPLEX VOLTK                                                     DDRMON     19
      DIMENSION VOLTX(2)                                                DDRMON     20
      EQUIVALENCE (VOLTK,VOLTX(1)),(VOLTX(1),VREAL),(VOLTX(2),VIMAG)    DDRMON     21
      DATA CK230/0.125/                                                 DDRMON     22
C                                                                       DDRMON     23
C                                                                       DDRMON     24
      LDEB=(JDEB(37).NE.0)                                              DDRMON     25
C                                                                       DDRMON     26
C    TEST FOR FIRST TEN CYCLE BYPASS                                    DDRMON     27
C                                                                       DDRMON     28
C      IF(MRELAY .NE. 1) GO TO 1000                                     DDRMON     29
C      IF(TS .LE. 0.1667) GO TO 7600                                    DDRMON     30
C                                                                       DDRMON     31
C    NTRIP = 1   NO TRIP                                                DDRMON     32
C          = 2   LOCAL RELAY TRIPPED,REMOTE RELAY STARTED               DDRMON     33
C          = 3   BOTH LOCAL AND REMOTE RELAY TRIPPED,RECLOSING TIMER STADDRMON     34
C          = 4   LOCAL LINE BREAKER RECLOSED                            DDRMON     35
C                                                                       DDRMON     36
      NTRIP = IADATA(K+1)                                               DDRMON     37
      ICD3 = IADATA(K+5)                                                DDRMON     38
      IBUS = IADATA(K+2)                                                DDRMON     39
      JBUS = IADATA(K+3)                                                DDRMON     40
      ITFK = IADATA(K+4)                                                DDRMON     41
      CALL UNPACK (CID, JJJ, ITFK)                                      DDRMON     42
      CKX = ADATA(K+9)                                                  DDRMON     43
      A1 = ADATA(K+22)                                                  DDRMON     44
      B1 = ADATA(K+23)                                                  DDRMON     45
      A2 = ADATA(K+24)                                                  DDRMON     46
      B2 = ADATA(K+25)                                                  DDRMON     47
      VOLTK = VOLT(IBUS)                                                DDRMON     48
      EI = VREAL                                                        DDRMON     49
      FI = VIMAG                                                        DDRMON     50
C                                                                       DDRMON     51
      TAN60 = ADATA(K+21)                                               DDRMON     52
C                                                                       DDRMON     53
      IF(NTRIP.EQ.4)GOTO 7600                                           DDRMON     54
      IF(NTRIP.EQ.3)GOTO 2400                                           DDRMON     55
      IF(NTRIP.EQ.2)GOTO 2150                                           DDRMON     56
C                                                                       DDRMON     57
      VOLTK = VOLT(JBUS)                                                DDRMON     58
      EJ = VREAL                                                        DDRMON     59
      FJ = VIMAG                                                        DDRMON     60
      IF(ADATA(K+18).NE.-1.) GO TO 2600                                 DDRMON     61
      OPOSIT = EI * FJ - EJ * FI                                        DDRMON     62
      ADJCNT = EI * EJ + FI * FJ                                        DDRMON     63
      OPOSIT = ABS(OPOSIT)                                              DDRMON     64
      ADJCNT = ABS(ADJCNT)                                              DDRMON     65
C                                                                       DDRMON     66
      AAA=TAN60*ADJCNT                                                  DDRMON     67
C                                                                       DDRMON     68
      IF(OPOSIT.LE.TAN60 * ADJCNT)GOTO 7600                             DDRMON     69
C * * *                                                                 DDRMON     70
C * * *  60 DEGREE TEST POSITIVE   CHECK FOR IMPEDANCE VALUES           DDRMON     71
C * * *                                                                 DDRMON     72
 2600 ILVOLT = 0                                                        DDRMON     73
      EIJ = EI - EJ                                                     DDRMON     74
      FIJ = FI - FJ                                                     DDRMON     75
      EFSQ = EIJ * EIJ + FIJ * FIJ                                      DDRMON     76
      IF(EFSQ.LT.0.0001) RETURN                                         DDRMON     77
      CKEFI = CKX * EI - FI                                             DDRMON     78
      ECKFI = EI + CKX * FI                                             DDRMON     79
      ALPH1 = (CKEFI * EIJ + ECKFI * FIJ )/ EFSQ                        DDRMON     80
      BETA1 = (ECKFI * EIJ - CKEFI * FIJ ) / EFSQ                       DDRMON     81
      ALF1SQ = ALPH1 * ALPH1                                            DDRMON     82
      BET1SQ = BETA1 * BETA1                                            DDRMON     83
      Z21 = ALF1SQ + BET1SQ - 2. * (ALPH1 * A2 + BETA1 * B2)            DDRMON     84
      IZ2 = 1                                                           DDRMON     85
      IF(Z21.GT.0.) GO TO 2800                                          DDRMON     86
      IZ2 = 2                                                           DDRMON     87
      IF(CKX.GT.CK230) GO TO 6400                                       DDRMON     88
 2800 EJI = - EIJ                                                       DDRMON     89
      FJI = - FIJ                                                       DDRMON     90
      CKEFJ = CKX * EJ - FJ                                             DDRMON     91
      ECKFJ = EJ + CKX * FJ                                             DDRMON     92
      ALPH2 = (CKEFJ * EJI + ECKFJ * FJI ) / EFSQ                       DDRMON     93
      BETA2 = (ECKFJ * EJI - CKEFJ * FJI ) / EFSQ                       DDRMON     94
      ALF2SQ = ALPH2 * ALPH2                                            DDRMON     95
      BET2SQ = BETA2 * BETA2                                            DDRMON     96
      IF(ILVOLT.EQ.1) GO TO 6600                                        DDRMON     97
      Z22 = ALF2SQ + BET2SQ - 2. * (ALPH2 * A2 + BETA2 * B2 )           DDRMON     98
      IF(Z22.GT.0.) GO TO 3400                                          DDRMON     99
      IF(IZ2.NE.2) GO TO 3000                                           DDRMON    100
      IZ2 = 4                                                           DDRMON    101
      GO TO 3200                                                        DDRMON    102
 3000 IZ2 = 3                                                           DDRMON    103
 3200 IF(CKX.GT.CK230) GO TO 6400                                       DDRMON    104
C * * *                                                                 DDRMON    105
C * * *  COMPUTE Z11                                                    DDRMON    106
C * * *                                                                 DDRMON    107
 6400 Z11 = ALF1SQ + BET1SQ - 2. * (ALPH1 * A1 + BETA1 * B1 )           DDRMON    108
      IF(Z11.LE.0.) GO TO 4400                                          DDRMON    109
      IF(IZ2.GT.2) GO TO 6600                                           DDRMON    110
      ILVOLT = 1                                                        DDRMON    111
      GO TO 2800                                                        DDRMON    112
 6600 ILVOLT = 0                                                        DDRMON    113
      Z12 = ALF2SQ + BET2SQ - 2. * (ALPH2 * A1 + BETA2 * B1)            DDRMON    114
      IF(Z12.LE.0.) GO TO 4400                                          DDRMON    115
      IF(IZ2.EQ.1) GO TO 3600                                           DDRMON    116
      GO TO 6000                                                        DDRMON    117
C                                                                       DDRMON    118
 3400 GO TO ( 3600, 6000, 6000, 4400), IZ2                              DDRMON    119
C                                                                       DDRMON    120
 3600 CONTINUE                                                          DDRMON    121
C                                                                       DDRMON    122
      GOTO 7300                                                         DDRMON    123
C                                                                       DDRMON    124
 6000 IF(ADATA(K+18).EQ.-1.0)THEN                                       DDRMON    125
        ADATA(K+18)=ADATA(K+17)+TS                                      DDRMON    126
      ENDIF                                                             DDRMON    127
C                                                                       DDRMON    128
       IF(ADATA(K+18).GT.TS+0.0001)GOTO 7300                            DDRMON    129
C                                                                       DDRMON    130
 4400 CONTINUE                                                          DDRMON    131
C                                                                       DDRMON    132
       IF(NTRIP.EQ.2)GOTO 2150                                          DDRMON    133
        NTRIP=2                                                         DDRMON    134
C                                                                       DDRMON    135
C                                                                       DDRMON    136
C      ACTIVIATE THE REMOTE TRIPPING TIMER AND RECLOSING TIMER          DDRMON    137
C                                                                       DDRMON    138
      IF(IDRRR.NE.0)THEN                                                DDRMON    139
        KADD=K+27                                                       DDRMON    140
        CALL RTIMER(KADD,IDRRR)                                         DDRMON    141
      ENDIF                                                             DDRMON    142
C                                                                       DDRMON    143
        IF(ADATA(K+19).GT.0.0 .AND.                                     DDRMON    144
     &     ADATA(K+20).EQ.-1.0)ADATA(K+20)=ADATA(K+19)+TS               DDRMON    145
C                                                                       DDRMON    146
C    GET THE LINE INFORMATION AND WRITE INTO IU12                       DDRMON    147
C                                                                       DDRMON    148
       ICD3=IADATA(K+5)                                                 DDRMON    149
       IF(ICD3.EQ.2)GOTO 2150                                           DDRMON    150
C                                                                       DDRMON    151
       NJSELI=IADATA(K+27)                                              DDRMON    152
C                                                                       DDRMON    153
       IF(IASWX.EQ.0)THEN                                               DDRMON    154
        WRITE(ISWFA,1100)TS                                             DDRMON    155
        NAWR=NAWR+1                                                     DDRMON    156
        IASWX=1                                                         DDRMON    157
       ENDIF                                                            DDRMON    158
C                                                                       DDRMON    159
       IF(NJSELI.NE.0)THEN                                              DDRMON    160
        WRITE(ISWFA,1200)IBUS,JBUS,CID                                  DDRMON    161
       ELSE                                                             DDRMON    162
        WRITE(ISWFA,1300)IBUS,JBUS,CID                                  DDRMON    163
       ENDIF                                                            DDRMON    164
       NAWR=NAWR+1                                                      DDRMON    165
C                                                                       DDRMON    166
C  REMOTE TRIPPING LOGIC                                                DDRMON    167
C                                                                       DDRMON    168
 2150 ICD4=IADATA(K+7)                                                  DDRMON    169
C * * *                                                                 DDRMON    170
C * * * ICD4 IS THE NUMBER OF REMOTE RELAYS ATTACHED TO THIS LOCAL      DDRMON    171
C * * * RELAY.  TTIMR1 IS THE TRANSFER TRIP TIMER.                      DDRMON    172
C * * *                                                                 DDRMON    173
C                                                                       DDRMON    174
C   CALL RETRIP TO PROCESS REMOTE RELAY LOGIC                           DDRMON    175
C                                                                       DDRMON    176
C                                                                       DDRMON    177
      IF(ICD4 .EQ. 0) GO TO 2400                                        DDRMON    178
       KADD=K+27                                                        DDRMON    179
       KBUS=K                                                           DDRMON    180
       IPOINT=8                                                         DDRMON    181
       CALL RETRIP(KADD,KBUS,IDRRR,IPOINT)                              DDRMON    182
       IF(IADATA(KBUS+IPOINT).EQ.-1)IADATA(K+1)=3                       DDRMON    183
C                                                                       DDRMON    184
 2400 CONTINUE                                                          DDRMON    185
C                                                                       DDRMON    186
C    RECLOSING LOGIC                                                    DDRMON    187
C                                                                       DDRMON    188
      IF(ICD3.EQ.2)GOTO 7300                                            DDRMON    189
      IF(ADATA(K+21).LE.TS)THEN                                         DDRMON    190
       NTRIP=4                                                          DDRMON    191
       ADATA(K+18)=-1.                                                  DDRMON    192
       ADATA(K+20)=-1.                                                  DDRMON    193
C                                                                       DDRMON    194
C    GET THE LINE INFORMATION AND WRITE INTO IU12                       DDRMON    195
C                                                                       DDRMON    196
       NJSELI=IADATA(K+27)                                              DDRMON    197
C                                                                       DDRMON    198
       IF(IASWX.EQ.0)THEN                                               DDRMON    199
        WRITE(ISWFA,1100)TS                                             DDRMON    200
        NAWR=NAWR+1                                                     DDRMON    201
        IASWX=1                                                         DDRMON    202
       ENDIF                                                            DDRMON    203
C                                                                       DDRMON    204
       IF(NJSELI.NE.0)THEN                                              DDRMON    205
        WRITE(ISWFA,1400)IBUS,JBUS,CID                                  DDRMON    206
       ELSE                                                             DDRMON    207
        WRITE(ISWFA,1500)IBUS,JBUS,CID                                  DDRMON    208
       ENDIF                                                            DDRMON    209
       NAWR=NAWR+1                                                      DDRMON    210
      ENDIF                                                             DDRMON    211
C                                                                       DDRMON    212
 7300 IADATA(K+1)=NTRIP                                                 DDRMON    213
C                                                                       DDRMON    214
 7600 RETURN                                                            DDRMON    215
 1100   FORMAT(F10.5)                                                   DDRMON    216
 1200   FORMAT('DPIA',2I5,1X,A2)                                        DDRMON    217
 1300   FORMAT('DLIA',2I5,1X,A2)                                        DDRMON    218
 1400   FORMAT('RPIA',2I5,1X,A2)                                        DDRMON    219
 1500   FORMAT('RLIA',2I5,1X,A2)                                        DDRMON    220
      END                                                               DDRMON    221
