CFPRIME RELANS                                                          RELANS      1
C***********************************************************************RIGHTE      1
C*                                                                     *RIGHTE      2
C*               Output Analysis Program for ETMSP (OAP)               *RIGHTE      4
C*               =======================================               *RIGHTE      5
C*                                                                     *RIGHTE     11
C*        copyright @(1993) Electric Power Research Institute          *RIGHTE     12
C*                                                                     *RIGHTE     13
C* EPRI reserves all rights in the software and associated             *RIGHTE     14
C* documentation as delivered. The software and its associated         *RIGHTE     15
C* documention or any portion thereof may not be reproduced in any form*RIGHTE     16
C* whatsoever without the consent of EPRI, except as explicity provided*RIGHTE     17
C* for by license. Licensee shall submit a detailed description to EPRI*RIGHTE     18
C* of any changes or modifications to the software within two (2)      *RIGHTE     19
C* months after such changes or modifications are made. At EPRI's sole *RIGHTE     20
C* discretion, the software, as changed or modified, shall be given a  *RIGHTE     21
C* new designation sufficiently different from its then current        *RIGHTE     22
C* designation as to prevent mistake,confusion, or deception as between*RIGHTE     23
C* the current software as changed or modified.                        *RIGHTE     24
C*                                                                     *RIGHTE     25
C* A license under EPRI's rights in the software can be obtained       *RIGHTE     26
C* directly from EPRI.                                                 *RIGHTE     27
C*                                                                     *RIGHTE     28
C* This program and supporting materials may be independently available*RIGHTE     29
C* from Electric Power Software centre (EPSC) for an appropriate       *RIGHTE     30
C* distribution fee. The EPSC is a service of                          *RIGHTE     31
C*                                                                     *RIGHTE     32
C*                    Power Computing Company                          *RIGHTE     33
C*                    1930 Hi Line                                     *RIGHTE     34
C*                    Dallas, Tx 75207                                 *RIGHTE     35
C*                                                                     *RIGHTE     36
C* NEITHER EPRI, ANY MEMBER OF EPRI, NOR ANY PERSON OR  ORGANIZATION   *RIGHTE     37
C* ACTING ON BEHAVE OF THEM:                                           *RIGHTE     38
C*                                                                     *RIGHTE     39
C* 1. MAKE ANY WARRANTY OR REPRESENTATION WHATSOEVER, EXPRESS OR       *RIGHTE     40
C*    IMPLIED, INCLUDING ANY WARRANTY OF MERCHANTABILITY OR FITNESS OR *RIGHTE     41
C*    ANY PURPOSE WITH RESPECT TO THE SOFTWARE OR ITS ASSOCIATED       *RIGHTE     42
C*    DOCUMENTATION; OR                                                *RIGHTE     43
C*                                                                     *RIGHTE     44
C* 2. ASSUMES ANY LIABILITY WHATSOEVER WITH RESPECT TO ANY USE OF THE  *RIGHTE     45
C*    SOFTWARE OR ITS ASSOCIATED DOCUMENTATION OR ANY PORTION THEREOF  *RIGHTE     46
C*    OR WITH RESPECT TO ANY DAMAGES WHICH MAY RESULT FROM SUCH USE.   *RIGHTE     47
C*                                                                     *RIGHTE     48
C* THIS NOTICE MAY NOT BE REMOVED FROM THE SOFTWARE BY ANY USER        *RIGHTE     49
C* THEREOF.                                                            *RIGHTE     50
C*                                                                     *RIGHTE     51
C***********************************************************************RIGHTE     52
      SUBROUTINE RELANS (X1,Y1,RMARG,IWORDS,BUF)                        RELANS      3
CD                                                                      RELANS      4
CD           THIS ROUTINE COMPUTES THE RELAY MARGIN FOR                 RELANS      5
CD           VARIOUS ELEMENTS :                                         RELANS      6
CD                                                                      RELANS      7
CD                    ITEM 1 - MHO CIRCLE                               RELANS      8
CD                    ITEM 2 - STRAIGHT LINE BLINDER                    RELANS      9
CD                    ITEM 3 - REACTIVE ELEMENT                         RELANS     10
CD                    ITEM 4 - BLINDER PASSING THROUGN ORIGIN           RELANS     11
CD                    ITEM 5 - PEANUT RELAY                             RELANS     12
CD                                                                      RELANS     13
CD           CALLING PARAMETERS :                                       RELANS     14
CD                                                                      RELANS     15
CD                      X1, Y1  -  THE CO-ORDINATES OF THE APPARENT     RELANS     16
CD                                 IMPEDENCE                            RELANS     17
CD                       RMARG  -  THE COMPUTED RALAY MARGIN            RELANS     18
CD                       LWORDS -  POINTER FOR THE RELAY DATA ARRAY     RELANS     19
CD                       IWORDS -  ELEMET NUMBER                        RELANS     20
CD                                                                      RELANS     21
      DIMENSION BUF(6)                                                  RELANS     22
C                                                                       RELANS     23
      IF(X1.LT.1.0E-5) X1=0.0                                           RELANS     24
      IF(Y1.LT.1.0E-5) Y1=0.0                                           RELANS     25
      PI=3.14159                                                        RELANS     26
      ZERO=0.0001                                                       RELANS     27
C THIS SECTION COMPUTES RELAY MARGIN                                    RELANS     28
C                                                                       RELANS     29
      IF(ABS(X1).LE.ZERO.AND.ABS(Y1).LE.ZERO)THEN                       RELANS     30
         RMARG=0.0                                                      RELANS     31
         RETURN                                                         RELANS     32
      ENDIF                                                             RELANS     33
   10 CONTINUE                                                          RELANS     34
      GO TO (100,400,500,600,100,100,700,2100                           RELANS     35
     *      , 50, 50, 50, 50, 50, 50, 50,2000), IWORDS                  RELANS     36
C                                                                       RELANS     37
   50 CONTINUE                                                          RELANS     38
      IWORDS=IWORDS-8                                                   RELANS     39
      GOTO 10                                                           RELANS     40
C                                                                       RELANS     41
C ITEM 1: MHO CIRCLE                                                    RELANS     42
C BUFF(1)=DIST                                                          RELANS     43
C BUFF(2)=CENTRE                                                        RELANS     44
C BUFF(3)=ANGLE                                                         RELANS     45
C                                                                       RELANS     46
  100 CONTINUE                                                          RELANS     47
      X2=BUF(2)*COS(BUF(3)*PI/180.)                                     RELANS     48
      Y2=BUF(2)*SIN(BUF(3)*PI/180)                                      RELANS     49
C X2,Y2 IS THE CENTRE OF THE CIRCLE                                     RELANS     50
      CS=SQRT((X2-X1)**2+(Y2-Y1)**2)                                    RELANS     51
      TS=CS-BUF(1)                                                      RELANS     52
      IF(ABS(TS).GT.0.0001) GO TO 300                                   RELANS     53
  200 RMARG=0.                                                          RELANS     54
      RETURN                                                            RELANS     55
  300 OS=SQRT(X1**2+Y1**2)                                              RELANS     56
      RMARG=ABS(TS/OS)                                                  RELANS     57
      IF (CS.LE.BUF(1)) RMARG=-RMARG                                    RELANS     58
      RETURN                                                            RELANS     59
C ITEM2 , STRAIGHT LINE BLINDER                                         RELANS     60
C BUFF(1)=DIST                                                          RELANS     61
C BUFF(2)=ANGLE                                                         RELANS     62
  400 CONTINUE                                                          RELANS     63
      R=BUF(1)                                                          RELANS     64
      ANG=BUF(2)                                                        RELANS     65
      ANG1=ANG*3.14159/180.                                             RELANS     66
      X2=R*COS(ANG1)                                                    RELANS     67
      Y2=R*SIN(ANG1)                                                    RELANS     68
      SO=X1*X1+Y1*Y1                                                    RELANS     69
      SO=SQRT(SO)                                                       RELANS     70
      C=Y1-X1*TAN(ANG1)                                                 RELANS     71
      RM=TAN(ANG1)                                                      RELANS     72
      RM2=-1./RM                                                        RELANS     73
      C2=Y2-RM2*X2                                                      RELANS     74
      X4=0.                                                             RELANS     75
      Y4=C                                                              RELANS     76
      X3=(C2-C)/(RM-RM2)                                                RELANS     77
      Y3=(RM*C2-C*RM2)/(RM-RM2)                                         RELANS     78
      SB=SQRT((X1-X3)**2+(Y1-Y3)**2)                                    RELANS     79
      PS=SQRT((X1-X4)**2+(Y1-Y4)**2)                                    RELANS     80
      PB=SQRT((X3-X4)**2+(Y3-Y4)**2)                                    RELANS     81
      RMARG=SB/SO                                                       RELANS     82
      IF(PS.LT.PB) RMARG=-RMARG                                         RELANS     83
      RETURN                                                            RELANS     84
C ITEM3, REACTIVE ELEMENT                                               RELANS     85
  500 CONTINUE                                                          RELANS     86
      SB=BUF(1)-Y1                                                      RELANS     87
      OS=SQRT(X1**2+Y1**2)                                              RELANS     88
      RMARG=ABS(SB/OS)                                                  RELANS     89
      IF (Y1.GT.0..AND.BUF(1).GT.Y1) RETURN                             RELANS     90
      IF (Y1.LT.0..AND.BUF(1).LT.Y1) RETURN                             RELANS     91
      RMARG=-RMARG                                                      RELANS     92
      RETURN                                                            RELANS     93
C ITEM 4 , BLINDER PASSING THROUGN ORIGIN                               RELANS     94
  600 CONTINUE                                                          RELANS     95
      IF (Y1.NE.0.AND.X1.NE.0) ANG1=ATAN(Y1/X1)                         RELANS     96
      IF (Y1.NE.0.AND.X1.EQ.0) ANG1=PI/2                                RELANS     97
      IF (Y1.EQ.0.AND.X1.NE.0) ANG1=0.                                  RELANS     98
      ANG2=BUF(1)*PI/180.                                               RELANS     99
      OS=SQRT(X1**2+Y1**2)                                              RELANS    100
      SB=OS*SIN(ANG1-ANG2)                                              RELANS    101
      RMARG=ABS(SB/OS)                                                  RELANS    102
      PS=ABS(X1/COS(ANG1))                                              RELANS    103
      IF (PS.LE.SB) RMARG=-RMARG                                        RELANS    104
      RETURN                                                            RELANS    105
  700 CONTINUE                                                          RELANS    106
C THIS PROGRAM WILL CALCULATE RELAY MARGIN                              RELANS    107
C FOR PEANUT RELAY                                                      RELANS    108
      ZER0=.0001                                                        RELANS    109
      SMAL=9999.                                                        RELANS    110
      REACH=BUF(1)                                                      RELANS    111
      THETA=BUF(2)*PI/180.                                              RELANS    112
      PK1=BUF(3)                                                        RELANS    113
      PK2=BUF(4)                                                        RELANS    114
C DEFINE ALPHA                                                          RELANS    115
      ALPHA=(1.-PK2)*PK1*PI/(1+PK1+PK2-3*PK1*PK2)                       RELANS    116
C DEFINE ALIM1,ALIM2                                                    RELANS    117
C ALIM1 IS 90 DEGREES TO THE RIGHT OF THE ZR AXIS                       RELANS    118
C ALIM2 IS 90 DEGREES TO THE LEFT OF THE ZR AXIS                        RELANS    119
      ALIM1=THETA-PI/2                                                  RELANS    120
      ALIM2=THETA+PI/2                                                  RELANS    121
      IF(ABS(Y1).GT.ZERO.AND.ABS(X1).GT.ZERO) ANG1=ATAN(ABS(Y1/X1))     RELANS    122
      IF(ABS(Y1).GT.ZERO.AND.ABS(X1).LT.ZERO) ANG1=PI/2.                RELANS    123
      IF(ABS(Y1).LT.ZERO.AND.ABS(X1).GT.ZERO) ANG1=0.                   RELANS    124
      IF (ABS(X1).GT.ZERO.OR.ABS(Y1).GT.ZERO) GO TO 800                 RELANS    125
C RMARG IS ZERO                                                         RELANS    126
      RMARG=0.                                                          RELANS    127
      RETURN                                                            RELANS    128
  800 IF (X1.GE.0.AND.Y1.GE.0.) IQUAD=1                                 RELANS    129
      IF (X1.GE.0.AND.Y1.LT.0.) IQUAD=4                                 RELANS    130
      IF (X1.LE.0.AND.Y1.GT.0.) IQUAD=2                                 RELANS    131
      IF (X1.LE.0.AND.Y1.LE.0.) IQUAD=3                                 RELANS    132
C ABOVE IS TO DETERMINE WHICH QUADRANT S LIES IN                        RELANS    133
      GO TO (1100,1300,900,1000), IQUAD                                 RELANS    134
C THIRD QUADRANT HERE, RMARG=0                                          RELANS    135
  900 RMARG=1.                                                          RELANS    136
      RETURN                                                            RELANS    137
C FOURTH QUADRANT HERE                                                  RELANS    138
 1000 ANG1=-ANG1                                                        RELANS    139
      A1=-PI/2.                                                         RELANS    140
      A2=THETA                                                          RELANS    141
      GO TO 1400                                                        RELANS    142
C FIRST QUADRANT                                                        RELANS    143
 1100 IF (ANG1.LE.THETA) GO TO 1200                                     RELANS    144
      A1=THETA                                                          RELANS    145
      A2=PI                                                             RELANS    146
      GO TO 1400                                                        RELANS    147
 1200 A1=0.                                                             RELANS    148
      A2=THETA                                                          RELANS    149
      GO TO 1400                                                        RELANS    150
C SECOND QUADRNAT                                                       RELANS    151
 1300 ANG1=PI-ANG1                                                      RELANS    152
      A1=PI/2.                                                          RELANS    153
      A2=PI                                                             RELANS    154
 1400 STEP=PI/180.                                                      RELANS    155
 1500 A1=A1+STEP                                                        RELANS    156
      REG1=THETA-ALPHA                                                  RELANS    157
      REG2=THETA+ALPHA                                                  RELANS    158
      IF (A1.GT.REG1.AND.A1.LT.REG2) GO TO 1600                         RELANS    159
      A11=A1                                                            RELANS    160
      IF(A11.GT.REG2) A11=2*THETA-A1                                    RELANS    161
      ZL=REACH/(COS(THETA-A11)+SIN(THETA-A11)/                          RELANS    162
     1 TAN(PK2*(PI-2*(THETA-A11))/(1+PK2)))                             RELANS    163
      GO TO 1700                                                        RELANS    164
 1600 ZL=REACH/(COS(THETA-A1)+SIN(THETA-A1)*TAN((1+PK1)                 RELANS    165
     1 *(THETA-A1)/2/PK1))                                              RELANS    166
 1700 IF(ZL.LT.0.) ZL=0.                                                RELANS    167
      X=ZL*COS(A1)                                                      RELANS    168
      Y=ZL*SIN(A1)                                                      RELANS    169
      D1=(X1-X)**2+(Y1-Y)**2                                            RELANS    170
      IF (D1.LT.SMAL) THEN                                              RELANS    171
                         SMAL=D1                                        RELANS    172
                         ANGS=A1                                        RELANS    173
                      END IF                                            RELANS    174
      IF (A1.LE.A2) GO TO 1500                                          RELANS    175
      RMARG=SQRT(SMAL/(X1**2+Y1**2))                                    RELANS    176
      IF(ANGS.GT.REG1.AND.ANGS.LT.REG2) GO TO 1800                      RELANS    177
      IF(ANGS.GT.REG2) ANGS=2*THETA-ANGS                                RELANS    178
      ZL=REACH/(COS(THETA-ANGS)+SIN(THETA-ANGS)/TAN(PK2*(PI-2*          RELANS    179
     1(THETA-ANGS))/(1+PK2)))                                           RELANS    180
      GO TO 1900                                                        RELANS    181
 1800 ZL=REACH/(COS(THETA-ANGS)+SIN(THETA-ANGS)*TAN((1+PK1)*(THETA-     RELANS    182
     1ANGS)/2/PK1))                                                     RELANS    183
 1900 DIST=SQRT(X1**2+Y1**2)                                            RELANS    184
      IF(ZL.LT.0.) ZL=0.                                                RELANS    185
      IF(DIST.LE.ZL) RMARG=-RMARG                                       RELANS    186
      RETURN                                                            RELANS    187
C                                                                       RELANS    188
C                                                                       RELANS    189
C                                                                       RELANS    190
 2000 CONTINUE                                                          RELANS    191
      IWORDS=IWORDS-8                                                   RELANS    192
      ALPHA=BUF(3)*PI/180.                                              RELANS    193
      ALPHB=BUF(6)*PI/180.                                              RELANS    194
      XA=BUF(2)*COS(ALPHA)                                              RELANS    195
      YA=BUF(2)*SIN(ALPHA)                                              RELANS    196
      XB=BUF(5)*COS(ALPHB)                                              RELANS    197
      YB=BUF(5)*SIN(ALPHB)                                              RELANS    198
      CAB=(XA-XB)*(XA-XB)+(YA-YB)*(YA-YB)                               RELANS    199
      QCAB=SQRT(CAB)                                                    RELANS    200
      IF(QCAB.GE.(BUF(1)+BUF(4)))THEN                                   RELANS    201
C                                                                       RELANS    202
C  ERROR                                                                RELANS    203
C                                                                       RELANS    204
         RETURN                                                         RELANS    205
      ENDIF                                                             RELANS    206
      BELTA=ACOS((BUF(1)*BUF(1)-BUF(4)*BUF(4)+CAB)/2/QCAB/BUF(1))       RELANS    207
      BELTB=ACOS((BUF(4)*BUF(4)-BUF(1)*BUF(1)+CAB)/2/QCAB/BUF(4))       RELANS    208
      THETA=SIGN(ACOS((XB-XA)/QCAB),YB-YA)                              RELANS    209
      THETB=THETA-SIGN(PI,THETA)                                        RELANS    210
C                                                                       RELANS    211
      XG1=XA+BUF(1)*COS(THETA-BELTA)                                    RELANS    212
      YG1=YA+BUF(1)*SIN(THETA-BELTA)                                    RELANS    213
      XG2=XA+BUF(1)*COS(THETA+BELTA)                                    RELANS    214
      YG2=YA+BUF(1)*SIN(THETA+BELTA)                                    RELANS    215
C                                                                       RELANS    216
C                                                                       RELANS    217
C                                                                       RELANS    218
 2100 CONTINUE                                                          RELANS    219
      SO=SQRT(X1*X1+Y1*Y1)                                              RELANS    220
      QSA=SQRT((X1-XA)*(X1-XA)+(Y1-YA)*(Y1-YA))                         RELANS    221
      ANGA=ABS(SIGN(ACOS((X1-XA)/QSA),Y1-YA)-THETA)                     RELANS    222
      IF(ANGA.GT.PI) ANGA=2*PI-ANGA                                     RELANS    223
C                                                                       RELANS    224
      QSB=SQRT((X1-XB)*(X1-XB)+(Y1-YB)*(Y1-YB))                         RELANS    225
      ANGB=ABS(SIGN(ACOS((X1-XB)/QSB),Y1-YB)-THETB)                     RELANS    226
      IF(ANGB.GT.PI) ANGB=2*PI-ANGB                                     RELANS    227
C                                                                       RELANS    228
      IF(ANGA.LE.BELTA.AND.ANGB.LE.BELTB)THEN                           RELANS    229
         RMARG=AMAX1(QSA-BUF(1),QSB-BUF(4))/SO                          RELANS    230
      ELSEIF(ANGA.LE.BELTA)THEN                                         RELANS    231
         RMARG=(QSA-BUF(1))/SO                                          RELANS    232
      ELSEIF(ANGB.LE.BELTB)THEN                                         RELANS    233
         RMARG=(QSB-BUF(4))/SO                                          RELANS    234
      ELSE                                                              RELANS    235
         RMARG=AMIN1((XG1-X1)*(XG1-X1)+(YG1-Y1)*(YG1-Y1)                RELANS    236
     *              ,(XG2-X1)*(XG2-X1)+(YG2-Y1)*(YG2-Y1))               RELANS    237
         RMARG=SQRT(RMARG)/SO                                           RELANS    238
      ENDIF                                                             RELANS    239
      RETURN                                                            RELANS    240
      END                                                               RELANS    241
