CFPRIME DLSMON                                                          DLSMON      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 DLSMON(H)                                              DLSMON      3
CD                                                                      DLSMON      4
CD  THIS SUBROUTINE CHECKS THE TRIPPING STATUS OF DOUBLE LENS           DLSMON      5
CD  SHAPE OUT-OF-STEP RELAYS                                            DLSMON      6
CD                                                                      DLSMON      7
      INCLUDE 'PARX.INS'                                                DLSMON      8
      INCLUDE 'CNPT.INS'                                                DLSMON      9
      INCLUDE 'CNAUTO.INS'                                              DLSMON     10
      INCLUDE 'CNVOLT.INS'                                              DLSMON     11
      INCLUDE 'CNFLAG.INS'                                              DLSMON     12
      INCLUDE 'CNB4.INS'                                                DLSMON     13
      INCLUDE 'CNB19.INS'                                               DLSMON     14
      INCLUDE 'CNUNIT.INS'                                              DLSMON     15
C                                                                       DLSMON     16
      CHARACTER*2 CID                                                   DLSMON     17
C                                                                       DLSMON     18
      COMPLEX VOLTK,X,Y                                                 DLSMON     19
      DIMENSION VOLTX(2)                                                DLSMON     20
      EQUIVALENCE (VOLTK,VOLTX(1)),(VOLTX(1),VREAL),(VOLTX(2),VIMAG)    DLSMON     21
C                                                                       DLSMON     22
      LDEB=.FALSE.                                                      DLSMON     23
C                                                                       DLSMON     24
      DO 2400 I=LDLSO,NDLSO                                             DLSMON     25
C                                                                       DLSMON     26
      K = IDATPT(I)                                                     DLSMON     27
C                                                                       DLSMON     28
      ICD1 = IADATA(K+1)                                                DLSMON     29
C                                                                       DLSMON     30
      IF(ICD1.GT.9)GOTO 2400                                            DLSMON     31
C                                                                       DLSMON     32
      ICD4 = IADATA(K+7)                                                DLSMON     33
C * * *                                                                 DLSMON     34
C * * * IF ICD1 = 5, BOTH LOCAL AND REMOTE TRIPPING HAVE BEEN COMPLETED DLSMON     35
C * * *                                                                 DLSMON     36
      IF(ICD1 .EQ. 5) GO TO 2400                                        DLSMON     37
C * * *                                                                 DLSMON     38
C * * *  IF ICD1 = 4 LOCAL TRIPPING IS COMPLETE BUT TRANSFER            DLSMON     39
C * * *  IS STILL IN PROGRESS                                           DLSMON     40
C * * *                                                                 DLSMON     41
      IF(ICD1 .EQ. 4)GO TO 2300                                         DLSMON     42
C                                                                       DLSMON     43
      IF(ICD1 .EQ. 3)GO TO 2200                                         DLSMON     44
C                                                                       DLSMON     45
C  APPARENT IMPEDANCE CALCULATION                                       DLSMON     46
C                                                                       DLSMON     47
      IBUS = IADATA(K+2)                                                DLSMON     48
      JBUS = IADATA(K+3)                                                DLSMON     49
      ITFK = IADATA(K+4)                                                DLSMON     50
      CALL UNPACK (CID, JJJ, ITFK)                                      DLSMON     51
C                                                                       DLSMON     52
      GIJ = ADATA(K+18)                                                 DLSMON     53
      BIJ = ADATA(K+19)                                                 DLSMON     54
      GIO = ADATA(K+20)                                                 DLSMON     55
      BIO = ADATA(K+21)                                                 DLSMON     56
C                                                                       DLSMON     57
      VOLTK=VOLT(IBUS)                                                  DLSMON     58
      EI = VREAL                                                        DLSMON     59
      FI = VIMAG                                                        DLSMON     60
      VOLTK=VOLT(JBUS)                                                  DLSMON     61
      EJ = VREAL                                                        DLSMON     62
      FJ = VIMAG                                                        DLSMON     63
C                                                                       DLSMON     64
      GT=GIJ+GIO                                                        DLSMON     65
      BT=BIJ+BIO                                                        DLSMON     66
      C1R=EI*GT-FI*BT                                                   DLSMON     67
      C1I=EI*BT+FI*GT                                                   DLSMON     68
      C2R=EJ*GIJ-FJ*BIJ                                                 DLSMON     69
      C2I=EJ*BIJ+FJ*GIJ                                                 DLSMON     70
      CTR=C1R-C2R                                                       DLSMON     71
      CTI=C1I-C2I                                                       DLSMON     72
      IF( ABS(CTR)+ ABS(CTI).EQ. 0.0) CTR=0.0001                        DLSMON     73
      ZR=(EI*CTR+FI*CTI)/(CTR*CTR+CTI*CTI)                              DLSMON     74
      ZI=(FI*CTR-EI*CTI)/(CTR*CTR+CTI*CTI)                              DLSMON     75
C                                                                       DLSMON     76
C      TO CHECK-LOCUS                                                   DLSMON     77
C                                                                       DLSMON     78
C    Determine location of locus with respect to relay characteristics. DLSMON     79
C                                                                       DLSMON     80
      IF (ICD1 .EQ. 1)THEN                                              DLSMON     81
         THETA = 0.0174533 * ADATA(K+8)                                 DLSMON     82
         X = CMPLX(COS(THETA)*ADATA(K+9)-ZR,                            DLSMON     83
     &             SIN(THETA)*ADATA(K+9)-ZI)                            DLSMON     84
         Y = CMPLX(-COS(THETA)*ADATA(K+10)-ZR,                          DLSMON     85
     &            -SIN(THETA)*ADATA(K+10)-ZI)                           DLSMON     86
         ALPHA = ATAN2(AIMAG(Y),REAL(Y)) - ATAN2(AIMAG(X),REAL(X))      DLSMON     87
         IF (ALPHA .GE.  3.14159) ALPHA = 6.28318 - ALPHA               DLSMON     88
         IF (ALPHA .LE. -3.14159) ALPHA = 6.28318 + ALPHA               DLSMON     89
         ALPHD = ABS(ALPHA) / 0.0174533                                 DLSMON     90
C                                                                       DLSMON     91
C    Exit subroutine if locus outside of characteristic C.              DLSMON     92
C                                                                       DLSMON     93
         IF (ALPHD .LT. ADATA(K+11))THEN                                DLSMON     94
            ADATA(K+15) = TS                                            DLSMON     95
            IADATA(K+6) = 0                                             DLSMON     96
            RETURN                                                      DLSMON     97
         ENDIF                                                          DLSMON     98
C                                                                       DLSMON     99
C     ALPHD is .GE. limit, ie. locus is                                 DLSMON    100
C     inside characteristics, set flag and record TS.                   DLSMON    101
C                                                                       DLSMON    102
         IF(IADATA(K+6) .EQ. 0)THEN                                     DLSMON    103
           ADATA(K+15) = TS                                             DLSMON    104
           IADATA(K+6) = 1                                              DLSMON    105
           WRITE (IU6,1110) IADATA(K+2), ALPHD, TS                      DLSMON    106
C                                                                       DLSMON    107
         ELSE                                                           DLSMON    108
C                                                                       DLSMON    109
C     If locus has crossed inner blinder, determine elapsed TS between  DLSMON    110
C     outer and inner blinders. If that TS is greater than ADATA(K+13), DLSMON    111
C     set trip flag and record TS.                                      DLSMON    112
C                                                                       DLSMON    113
           IF (ALPHD .GE. ADATA(K+11))THEN                              DLSMON    114
              IF(TS-ADATA(K+15) .GT. ADATA(K+13))THEN                   DLSMON    115
                ADATA(K+17) = TS                                        DLSMON    116
                ICD1 = 2                                                DLSMON    117
                IADATA(K+1) = ICD1                                      DLSMON    118
                WRITE (IU6,1120) IADATA(K+2), ALPHD, TS                 DLSMON    119
C                                                                       DLSMON    120
C          If the TS between blinders is short, reset the               DLSMON    121
C          starting TS (ADATA(K+15))                                    DLSMON    122
C                                                                       DLSMON    123
C                                                                       DLSMON    124
              ELSE                                                      DLSMON    125
                ADATA(K+15) = TS                                        DLSMON    126
              ENDIF                                                     DLSMON    127
C                                                                       DLSMON    128
           ENDIF                                                        DLSMON    129
C                                                                       DLSMON    130
         ENDIF                                                          DLSMON    131
C                                                                       DLSMON    132
      ENDIF                                                             DLSMON    133
C                                                                       DLSMON    134
C  If trip flag is set and breaker TS for monitored line has passed,    DLSMON    135
C  set flag to -1 to allow some other routine to trip the line and to   DLSMON    136
C  allow bypass of subroutine in future TS steps.                       DLSMON    137
c                                                                       DLSMON    138
C      IF (ICD1 .EQ. 2)THEN                                             DLSMON    139
C                                                                       DLSMON    140
C    ACTIVIATES THE REMOTE TRIPPING TIMERS                              DLSMON    141
C    TRIP THE LOCAL LINE                                                DLSMON    142
C                                                                       DLSMON    143
        IF(ICD1.EQ.2.AND.IADATA(K+5).EQ.1)THEN                          DLSMON    144
         ICD1=3                                                         DLSMON    145
         IADATA(K+1)=ICD1                                               DLSMON    146
         IF(ICD4.NE.0)THEN                                              DLSMON    147
           KADD=K+22                                                    DLSMON    148
           CALL RTIMER(KADD,ICD4)                                       DLSMON    149
         ENDIF                                                          DLSMON    150
        ENDIF                                                           DLSMON    151
C                                                                       DLSMON    152
 2200 CONTINUE                                                          DLSMON    153
C                                                                       DLSMON    154
      IF (ICD1 .EQ. 3)THEN                                              DLSMON    155
         IF (TS-ADATA(K+17) .GE. ADATA(K+14))THEN                       DLSMON    156
           IADATA(K+1) = 4                                              DLSMON    157
           IF(IADATA(K+5).EQ.1)THEN                                     DLSMON    158
C                                                                       DLSMON    159
            NJSELI=IADATA(K+22)                                         DLSMON    160
C                                                                       DLSMON    161
            IF(IASWX.EQ.0)THEN                                          DLSMON    162
             WRITE(ISWFA,4100)TS                                        DLSMON    163
 4100        FORMAT(F10.5)                                              DLSMON    164
             NAWR=NAWR+1                                                DLSMON    165
             IASWX=1                                                    DLSMON    166
            ENDIF                                                       DLSMON    167
C                                                                       DLSMON    168
            IF(NJSELI.NE.0)THEN                                         DLSMON    169
             WRITE(ISWFA,4200)IBUS,JBUS,CID                             DLSMON    170
 4200        FORMAT('DPIA',2I5,1X,A2)                                   DLSMON    171
            ELSE                                                        DLSMON    172
             WRITE(ISWFA,4300)IBUS,JBUS,CID                             DLSMON    173
 4300        FORMAT('DLIA',2I5,1X,A2)                                   DLSMON    174
            ENDIF                                                       DLSMON    175
C                                                                       DLSMON    176
            NAWR=NAWR+1                                                 DLSMON    177
            WRITE (IU6,1130) IADATA(K+2), TS                            DLSMON    178
           ENDIF                                                        DLSMON    179
         ENDIF                                                          DLSMON    180
      ENDIF                                                             DLSMON    181
C                                                                       DLSMON    182
C                                                                       DLSMON    183
C * * * ICD4 IS THE NUMBER OF REMOTE RELAYS ATTACHED TO THIS LOCAL      DLSMON    184
C * * * RELAY.                                                          DLSMON    185
C                                                                       DLSMON    186
 2300 IF(ICD4.EQ.0) GO TO 2400                                          DLSMON    187
C                                                                       DLSMON    188
C * * *                                                                 DLSMON    189
C * * * PROCESS REMOTE RELAY LOGIC                                      DLSMON    190
C * * *                                                                 DLSMON    191
        IF(IADATA(K+1).GT.2 )THEN                                       DLSMON    192
          KADD=K+22                                                     DLSMON    193
          KBUS=K                                                        DLSMON    194
          IPOINT=16                                                     DLSMON    195
          CALL RETRIP(KADD,KBUS,ICD4,IPOINT)                            DLSMON    196
          IF(IADATA(KBUS+IPOINT).EQ.-1)THEN                             DLSMON    197
           ICD1=5                                                       DLSMON    198
           IADATA(K+1) = ICD1                                           DLSMON    199
          ENDIF                                                         DLSMON    200
        ENDIF                                                           DLSMON    201
C                                                                       DLSMON    202
 2400 CONTINUE                                                          DLSMON    203
C                                                                       DLSMON    204
      RETURN                                                            DLSMON    205
 1110 FORMAT(/,' *** DLSR RELAY  AT BUS ',I5,' HAS CROSSED',            DLSMON    206
     #' OUTER BLINDER.'/15X,' CALCULATED ANGLE = ',F8.4,                DLSMON    207
     #' DEG. , TIME = ',F8.4,' SECS.')                                  DLSMON    208
C     .                                                                 DLSMON    209
 1120 FORMAT(/,' *** DLSR RELAY  AT BUS ',I5,' HAS CROSSED',            DLSMON    210
     #' INNER BLINDER.'/15X,' CALCULATED ANGLE = ',F8.4,                DLSMON    211
     #' DEG. , TIME = ',F8.4,' SECS.')                                  DLSMON    212
C     .                                                                 DLSMON    213
 1130 FORMAT(/,' *** DLSR RELAY  AT BUS ',I5,'.  BREAKER',              DLSMON    214
     #' DELAY TIMER TIMED OUT.'/15X,'  AT TIME = ',F8.4,' SECS.')       DLSMON    215
      END                                                               DLSMON    216
