CFPRIME RELPLT                                                          RELPLT      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 RELPLT(TT,R,X,M,N,NRLY,NC1,T1,T2)                     RELPLT      3
CD                                                                      RELPLT      4
CD          THIS ROUTINE COMPUTES THE RELAY MARGIN                      RELPLT      5
CD                                                                      RELPLT      6
CD          CALLING PARAMETERS :                                        RELPLT      7
CD                                                                      RELPLT      8
CD                          T  - TIME ARRAY                             RELPLT      9
CD                          R  - ARRAY STORES THE REAL PART             RELPLT     10
CD                          X  - ARRAY STORES THE IMAGINARY PART        RELPLT     11
CD                          M  - NOT USED                               RELPLT     12
CD                          N  - NUMBER OF TIME PONITS                  RELPLT     13
CD                       NRLY  - POINTER FOR THE RELAY INFORMATION      RELPLT     14
CD                        NC1  - APPARENT IMPEDANCE CHANNEL NUMBER      RELPLT     15
CD                       T1,T2 - TIME RANGE, FROM AND TO TIME           RELPLT     16
CD                                                                      RELPLT     17
C                                                                       RELPLT     18
      INCLUDE 'PARAM.INS'                                               RELPLT     19
      INCLUDE 'XYARAY.INS'                                              RELPLT     20
      INCLUDE 'CNDATA.INS'                                              RELPLT     21
      INCLUDE 'SOAPC1.INS'                                              RELPLT     22
C                                                                       RELPLT     23
      REAL TT(*),R(*),X(*),CIRCLE(63)                                   RELPLT     24
      REAL TMARG(20,4,1000)                                             RELPLT     25
      INTEGER NELIST(20),LOOKUP(4,3),JTYPE(8)                           RELPLT     26
      CHARACTER*8 MLIST(4)                                              RELPLT     27
      CHARACTER*12 RLIST(20)                                            RELPLT     28
      CHARACTER RLYID*12,STRING*80,MSG*80                               RELPLT     29
      COMMON /RELLOC/TMARG                                              RELPLT     30
      DATA LOOKUP/24,47,70,93,31,54,77,100,38,61,84,108/                RELPLT     31
      DATA ICIRCL/62/,PI/3.14159265/,NELIST/20*0/                       RELPLT     32
      DATA JTYPE/3,2,1,1,3,3,4,6/                                       RELPLT     33
C                                                                       RELPLT     34
      M=0                                                               RELPLT     35
 2100 CONTINUE                                                          RELPLT     36
      RLYID=CRDATA(1,NRLY)//CRDATA(2,NRLY)(1:2)//'('                    RELPLT     37
     *                    //CRDATA(3,NRLY)//')'                         RELPLT     38
      WRITE(LOUT,8000) RLYID,NC1,NC1+1,T1,T2                            RELPLT     39
C                                                                       RELPLT     40
      STRING=' '                                                        RELPLT     41
      ISCHEM=0                                                          RELPLT     42
      IZONE=0                                                           RELPLT     43
      IELM=0                                                            RELPLT     44
      NELM=0                                                            RELPLT     45
      NZONE=0                                                           RELPLT     46
      LWORDS=17                                                         RELPLT     47
      NSCHEM=IRDATA(17,NRLY)                                            RELPLT     48
 2200 CONTINUE                                                          RELPLT     49
      ISCHEM=ISCHEM+1                                                   RELPLT     50
      IF(ISCHEM.GT.NSCHEM) GOTO 2500                                    RELPLT     51
      LWORDS=LWORDS+12                                                  RELPLT     52
      NZONE=NZONE+IRDATA(LWORDS,NRLY)                                   RELPLT     53
 2300 CONTINUE                                                          RELPLT     54
      IF(IZONE.GE.NZONE) GOTO 2200                                      RELPLT     55
      IZONE=IZONE+1                                                     RELPLT     56
      WRITE(STRING(11:13),'(I2,A)') IZONE,')'                           RELPLT     57
      STRING(18:)='      '                                              RELPLT     58
      STRING(18:23)=CRDATA(LWORDS+1,NRLY)//CRDATA(LWORDS+2,NRLY)(1:2)   RELPLT     59
      IF(NELIST(IZONE).EQ.1) STRING(28:)='TO BE PLOTTED'                RELPLT     60
      NELM=NELM+IRDATA(LWORDS+10,NRLY)                                  RELPLT     61
      WRITE(LOUT,'(A)') STRING                                          RELPLT     62
      LWORDS=LWORDS+12                                                  RELPLT     63
 2400 CONTINUE                                                          RELPLT     64
      IF(IELM.GE.NELM) GOTO 2300                                        RELPLT     65
      IELM=IELM+1                                                       RELPLT     66
      ITYPE=IRDATA(LWORDS+1,NRLY)+1                                     RELPLT     67
      LWORDS=LWORDS+JTYPE(ITYPE)+1                                      RELPLT     68
      GOTO 2400                                                         RELPLT     69
C                                                                       RELPLT     70
 2500 CONTINUE                                                          RELPLT     71
      STRING='           A)    PLOT ALL'                                RELPLT     72
      WRITE(LOUT,'(A)') STRING                                          RELPLT     73
      STRING='           P)    GO TO PLOT'                              RELPLT     74
      WRITE(LOUT,'(A)') STRING                                          RELPLT     75
      DO 2600 I=NZONE+1,12                                              RELPLT     76
 2600 WRITE(LOUT,*)                                                     RELPLT     77
C                                                                       RELPLT     78
 2700 CONTINUE                                                          RELPLT     79
      MSG='SELECT BY THE NUMBER TO PLOT (Q TO QUIT):'                   RELPLT     80
      CALL PMTRED(LOUT,LIN,JERR,41,MSG,'RLY',STRING)                    RELPLT     81
      IF(RECORD) WRITE(IREC,'(A)') STRING                               RELPLT     82
      IF(STRING(1:1).EQ.'Q'.OR.STRING(1:1).EQ.'q') RETURN               RELPLT     83
      IF(STRING(1:1).EQ.'P'.OR.STRING(1:1).EQ.'p') GOTO 2900            RELPLT     84
      IF(STRING(1:1).EQ.'A'.OR.STRING(1:1).EQ.'a')THEN                  RELPLT     85
         DO 2800 I=1,NZONE                                              RELPLT     86
 2800    NELIST(I)=1                                                    RELPLT     87
         GOTO 2100                                                      RELPLT     88
      ENDIF                                                             RELPLT     89
      READ(STRING,*,IOSTAT=IOS) INUM                                    RELPLT     90
      IF(IOS.NE.0.OR.INUM.LE.0.OR.INUM.GT.NZONE) GOTO 2100              RELPLT     91
      NELIST(INUM)=MOD(NELIST(INUM)+1,2)                                RELPLT     92
      GOTO 2100                                                         RELPLT     93
C                                                                       RELPLT     94
 2900 CONTINUE                                                          RELPLT     95
      DO 100 I=1,ICIRCL                                                 RELPLT     96
  100 CIRCLE(I)=SIN((I-1)*PI/122)                                       RELPLT     97
      ICIRCL=2                                                          RELPLT     98
      J1=0                                                              RELPLT     99
      J2=0                                                              RELPLT    100
      JNE=0                                                             RELPLT    101
C                                                                       RELPLT    102
      LWORDS=17                                                         RELPLT    103
      NSCHEM=IRDATA(17,NRLY)                                            RELPLT    104
      ISCHEM=0                                                          RELPLT    105
      NZONE=0                                                           RELPLT    106
      NZ=0                                                              RELPLT    107
C                                                                       RELPLT    108
  200 ISCHEM=ISCHEM+1                                                   RELPLT    109
      IF(ISCHEM.GT.NSCHEM) GOTO 800                                     RELPLT    110
      LWORDS=LWORDS+12                                                  RELPLT    111
      LZONE=LWORDS                                                      RELPLT    112
      NZONE=NZONE+IRDATA(LZONE,NRLY)                                    RELPLT    113
C                                                                       RELPLT    114
  300 CONTINUE                                                          RELPLT    115
      IF(NZ.GE.NZONE) GOTO 200                                          RELPLT    116
      NZ=NZ+1                                                           RELPLT    117
      RLIST(NZ)=CRDATA(LWORDS+3,NRLY)//CRDATA(LWORDS+4,NRLY)            RELPLT    118
     *                               //CRDATA(LWORDS+5,NRLY)            RELPLT    119
C                                                                       RELPLT    120
      NELM=IRDATA(LWORDS+10,NRLY)                                       RELPLT    121
      NE=0                                                              RELPLT    122
      LWORDS=LWORDS+12                                                  RELPLT    123
C                                                                       RELPLT    124
      K=0                                                               RELPLT    125
      DO 400 IM=1,NELM-1                                                RELPLT    126
         IMARK=INDEX(RLIST(NZ)(K+1:12),'/')+K                           RELPLT    127
         IF(IMARK.NE.K)THEN                                             RELPLT    128
            MLIST(IM)=RLIST(NZ)(K+1:IMARK-1)                            RELPLT    129
            K=IMARK+1                                                   RELPLT    130
         ELSE                                                           RELPLT    131
            MLIST(IM)=RLIST(NZ)(K+1:12)                                 RELPLT    132
         ENDIF                                                          RELPLT    133
  400 CONTINUE                                                          RELPLT    134
      MLIST(NELM)=RLIST(NZ)(K+1:12)                                     RELPLT    135
C                                                                       RELPLT    136
  500 NE=NE+1                                                           RELPLT    137
      IF(NE.GT.NELM) GOTO 300                                           RELPLT    138
      NFLAG=IRDATA(LWORDS+1,NRLY)                                       RELPLT    139
      IF(NELIST(NZ).EQ.0)THEN                                           RELPLT    140
         LWORDS=LWORDS+JTYPE(NFLAG+1)+1                                 RELPLT    141
         GOTO 500                                                       RELPLT    142
      ENDIF                                                             RELPLT    143
      JNE=JNE+1                                                         RELPLT    144
      XARAY(1001-JNE,6)=NFLAG                                           RELPLT    145
C                                                                       RELPLT    146
      GOTO (520,530,540,510,510,550,560) NFLAG                          RELPLT    147
C                                                                       RELPLT    148
  510 CONTINUE                                                          RELPLT    149
      J1=J1+245                                                         RELPLT    150
      IF(J1.GE.1000)THEN                                                RELPLT    151
         ICIRCL=ICIRCL+1                                                RELPLT    152
         J1=245                                                         RELPLT    153
      ENDIF                                                             RELPLT    154
      R1=RDATA(LWORDS+2,NRLY)                                           RELPLT    155
      X1=RDATA(LWORDS+3,NRLY)*COS(RDATA(LWORDS+4,NRLY)*PI/180)          RELPLT    156
      Y1=RDATA(LWORDS+3,NRLY)*SIN(RDATA(LWORDS+4,NRLY)*PI/180)          RELPLT    157
      DO 700 I=1,62                                                     RELPLT    158
         R2=R1*CIRCLE(I)                                                RELPLT    159
         XARAY(J1-182-I,ICIRCL)=X1+R2                                   RELPLT    160
         XARAY(J1-184+I,ICIRCL)=X1-R2                                   RELPLT    161
         XARAY(J1-60-I,ICIRCL)=X1-R2                                    RELPLT    162
         XARAY(J1-62+I,ICIRCL)=X1+R2                                    RELPLT    163
         YARAY(J1-245+I,ICIRCL)=Y1+R2                                   RELPLT    164
         YARAY(J1-123+I,ICIRCL)=Y1-R2                                   RELPLT    165
         YARAY(J1-121-I,ICIRCL)=Y1+R2                                   RELPLT    166
         YARAY(J1+1-I,ICIRCL)=Y1-R2                                     RELPLT    167
  700 CONTINUE                                                          RELPLT    168
      LWORDS=LWORDS+4                                                   RELPLT    169
      GOTO 500                                                          RELPLT    170
C                                                                       RELPLT    171
  520 CONTINUE                                                          RELPLT    172
      J2=J2+1                                                           RELPLT    173
      XARAY(J2,6)=RDATA(LWORDS+2,NRLY)                                  RELPLT    174
      YARAY(J2,6)=RDATA(LWORDS+3,NRLY)                                  RELPLT    175
      LWORDS=LWORDS+3                                                   RELPLT    176
      GOTO 500                                                          RELPLT    177
C                                                                       RELPLT    178
  530 CONTINUE                                                          RELPLT    179
      J2=J2+1                                                           RELPLT    180
      XARAY(J2,6)=RDATA(LWORDS+2,NRLY)                                  RELPLT    181
      YARAY(J2,6)=-90                                                   RELPLT    182
      LWORDS=LWORDS+3                                                   RELPLT    183
      GOTO 500                                                          RELPLT    184
C                                                                       RELPLT    185
  540 CONTINUE                                                          RELPLT    186
      J2=J2+1                                                           RELPLT    187
      XARAY(J2,6)=0                                                     RELPLT    188
      YARAY(J2,6)=90-RDATA(LWORDS+2,NRLY)                               RELPLT    189
      LWORDS=LWORDS+2                                                   RELPLT    190
      GOTO 500                                                          RELPLT    191
C                                                                       RELPLT    192
  550 CONTINUE                                                          RELPLT    193
      IF(J1+245.GE.1000)THEN                                            RELPLT    194
         ICIRCL=ICIRCL+1                                                RELPLT    195
         J1=0                                                           RELPLT    196
      ENDIF                                                             RELPLT    197
      REACH=RDATA(LWORDS+2,NRLY)                                        RELPLT    198
      THETA=RDATA(LWORDS+3,NRLY)*PI/180                                 RELPLT    199
      PK1=RDATA(LWORDS+4,NRLY)                                          RELPLT    200
      PK2=RDATA(LWORDS+5,NRLY)                                          RELPLT    201
      ALPHA=(PK2-1.)*PK1*PI/(1+PK1+PK2-3*PK1*PK2)                       RELPLT    202
      ANGS=-PI/2                                                        RELPLT    203
      DELTA=PI/244                                                      RELPLT    204
      DO 600 I=2,122                                                    RELPLT    205
         ANGS=ANGS+DELTA                                                RELPLT    206
         IF(ANGS.GT.ALPHA)THEN                                          RELPLT    207
            ZL=REACH/(COS(ANGS)+SIN(ANGS)*TAN((1+PK1)                   RELPLT    208
     *         *ANGS/2/PK1))                                            RELPLT    209
         ELSE                                                           RELPLT    210
            ZL=REACH/(COS(ANGS)-SIN(ANGS)/TAN(PK2*(PI+2                 RELPLT    211
     *         *ANGS)/(1+PK2)))                                         RELPLT    212
         ENDIF                                                          RELPLT    213
         XARAY(J1+I,ICIRCL)=ZL*COS(THETA+ANGS)                          RELPLT    214
         YARAY(J1+I,ICIRCL)=ZL*SIN(THETA+ANGS)                          RELPLT    215
         XARAY(J1+246-I,ICIRCL)=ZL*COS(THETA-ANGS)                      RELPLT    216
         YARAY(J1+246-I,ICIRCL)=ZL*SIN(THETA-ANGS)                      RELPLT    217
  600 CONTINUE                                                          RELPLT    218
      XARAY(J1+1,ICIRCL)=0                                              RELPLT    219
      YARAY(J1+1,ICIRCL)=0                                              RELPLT    220
      XARAY(J1+123,ICIRCL)=REACH*COS(THETA)                             RELPLT    221
      YARAY(J1+123,ICIRCL)=REACH*SIN(THETA)                             RELPLT    222
      XARAY(J1+245,ICIRCL)=0                                            RELPLT    223
      YARAY(J1+245,ICIRCL)=0                                            RELPLT    224
      J1=J1+245                                                         RELPLT    225
      LWORDS=LWORDS+5                                                   RELPLT    226
      GOTO 500                                                          RELPLT    227
C                                                                       RELPLT    228
  560 CONTINUE                                                          RELPLT    229
      RA=RDATA(LWORDS+2,NRLY)                                           RELPLT    230
      XA=RDATA(LWORDS+3,NRLY)*COS(RDATA(LWORDS+4,NRLY)*PI/180)          RELPLT    231
      YA=RDATA(LWORDS+3,NRLY)*SIN(RDATA(LWORDS+4,NRLY)*PI/180)          RELPLT    232
      RB=RDATA(LWORDS+5,NRLY)                                           RELPLT    233
      XB=RDATA(LWORDS+6,NRLY)*COS(RDATA(LWORDS+7,NRLY)*PI/180)          RELPLT    234
      YB=RDATA(LWORDS+6,NRLY)*SIN(RDATA(LWORDS+7,NRLY)*PI/180)          RELPLT    235
      CAB=(XA-XB)*(XA-XB)+(YA-YB)*(YA-YB)                               RELPLT    236
      QCAB=SQRT(CAB)                                                    RELPLT    237
      IF(QCAB.GE.(RA+RB))THEN                                           RELPLT    238
C                                                                       RELPLT    239
C  ERROR                                                                RELPLT    240
C                                                                       RELPLT    241
         GOTO 590                                                       RELPLT    242
      ENDIF                                                             RELPLT    243
      BELTA=ACOS((RA*RA-RB*RB+CAB)/2/QCAB/RA)                           RELPLT    244
      BELTB=ACOS((RB*RB-RA*RA+CAB)/2/QCAB/RB)                           RELPLT    245
      THETA=SIGN(ACOS((XB-XA)/QCAB),YB-YA)                              RELPLT    246
      THETB=THETA-SIGN(PI,THETA)                                        RELPLT    247
      IF(J1.GE.755)THEN                                                 RELPLT    248
         ICIRCL=ICIRCL+1                                                RELPLT    249
         J1=0                                                           RELPLT    250
      ENDIF                                                             RELPLT    251
      DELTA=BELTA/61                                                    RELPLT    252
      ANGA=THETA-BELTA                                                  RELPLT    253
      DELTB=BELTB/61                                                    RELPLT    254
      ANGB=THETB-BELTB                                                  RELPLT    255
      DO 570 I=1,123                                                    RELPLT    256
         XARAY(J1+I,ICIRCL)=XA+RA*COS(ANGA)                             RELPLT    257
         YARAY(J1+I,ICIRCL)=YA+RA*SIN(ANGA)                             RELPLT    258
         ANGA=ANGA+DELTA                                                RELPLT    259
         XARAY(J1+I+122,ICIRCL)=XB+RB*COS(ANGB)                         RELPLT    260
         YARAY(J1+I+122,ICIRCL)=YB+RB*SIN(ANGB)                         RELPLT    261
         ANGB=ANGB+DELTB                                                RELPLT    262
  570 CONTINUE                                                          RELPLT    263
      J1=J1+245                                                         RELPLT    264
C                                                                       RELPLT    265
  590 CONTINUE                                                          RELPLT    266
      LWORDS=LWORDS+7                                                   RELPLT    267
      GOTO 500                                                          RELPLT    268
C                                                                       RELPLT    269
  800 CONTINUE                                                          RELPLT    270
      M=J1                                                              RELPLT    271
      XARAY(1000-JNE,6)=-1                                              RELPLT    272
      NC1=ICIRCL                                                        RELPLT    273
      ICIRCL=62                                                         RELPLT    274
      RETURN                                                            RELPLT    275
C                                                                       RELPLT    276
 8000 FORMAT(////,' RELAY ID: ',A12,4X,'APP IMP CHANNEL NUMBERS:'       RELPLT    277
     *,2I6,//,' TIME RANGE: FROM',F7.3,' (SEC) TO',F7.3,' (SEC)',//)    RELPLT    278
      END                                                               RELPLT    279
