CFPRIME RELMAR                                                          RELMAR      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 RELMAR(T,R,X,M,N,NRLY,NC1,T1,T2)                      RELMAR      3
CD                                                                      RELMAR      4
CD          THIS ROUTINE COMPUTES THE RELAY MARGIN                      RELMAR      5
CD                                                                      RELMAR      6
CD          CALLING PARAMETERS :                                        RELMAR      7
CD                                                                      RELMAR      8
CD                          T  - TIME ARRAY                             RELMAR      9
CD                          R  - ARRAY STORES THE REAL PART             RELMAR     10
CD                          X  - ARRAY STORES THE IMAGINARY PART        RELMAR     11
CD                          M  - NOT USED                               RELMAR     12
CD                          N  - NUMBER OF TIME PONITS                  RELMAR     13
CD                       NRLY  - POINTER FOR THE RELAY INFORMATION      RELMAR     14
CD                        NC1  - APPARENT IMPEDANCE CHANNEL NUMBER      RELMAR     15
CD                       T1,T2 - TIME RANGE, FROM AND TO TIME           RELMAR     16
CD                                                                      RELMAR     17
C                                                                       RELMAR     18
      INCLUDE 'CNDATA.INS'                                              RELMAR     19
      INCLUDE 'SOAPC1.INS'                                              RELMAR     20
C                                                                       RELMAR     21
      REAL T(*),R(*),X(*)                                               RELMAR     22
      REAL TMARG(20,4,1000),BUFF(6),RMMIN(20,4),TMIN(20,4)              RELMAR     23
      INTEGER NELIST(20),LOOKUP(12),JWORDS(8)                           RELMAR     24
      CHARACTER*6 ZLIST(20)                                             RELMAR     25
      CHARACTER*8 MLIST(4)                                              RELMAR     26
      CHARACTER*12 RLIST(20)                                            RELMAR     27
      CHARACTER OBUF*132,DUM18*18,RLYID*12                              RELMAR     28
      COMMON /RELLOC/TMARG                                              RELMAR     29
C                                                                       RELMAR     30
      DATA JWORDS/4,3,3,2,4,4,5,7/                                      RELMAR     31
C                                                                       RELMAR     32
      RLYID=CRDATA(1,NRLY)//CRDATA(2,NRLY)(1:2)//'('                    RELMAR     33
     *                    //CRDATA(3,NRLY)//')'                         RELMAR     34
C                                                                       RELMAR     35
      NC2=NC1+1                                                         RELMAR     36
      WRITE(IREL,8000)RLYID,NC1,NC2,T1,T2                               RELMAR     37
      WRITE(LOUT,8000)RLYID,NC1,NC2,T1,T2                               RELMAR     38
      WRITE(LOUT,8100)                                                  RELMAR     39
C                                                                       RELMAR     40
      DO 100 I=1,20                                                     RELMAR     41
      DO 100 J=1,3                                                      RELMAR     42
      TMIN(I,J)=0.                                                      RELMAR     43
  100 RMMIN(I,J)=999.                                                   RELMAR     44
C                                                                       RELMAR     45
      LWORDS=17                                                         RELMAR     46
      NSCHEM=IRDATA(17,NRLY)                                            RELMAR     47
      ISCHEM=0                                                          RELMAR     48
      NZONE=0                                                           RELMAR     49
      NZ=0                                                              RELMAR     50
C                                                                       RELMAR     51
  200 ISCHEM=ISCHEM+1                                                   RELMAR     52
      LWORDS=LWORDS+12                                                  RELMAR     53
      LZONE=LWORDS                                                      RELMAR     54
      NZONE=NZONE+IRDATA(LZONE,NRLY)                                    RELMAR     55
C                                                                       RELMAR     56
  300 NZ=NZ+1                                                           RELMAR     57
      ZLIST(NZ)=CRDATA(LWORDS+1,NRLY)//CRDATA(LWORDS+2,NRLY)(1:2)       RELMAR     58
      RLIST(NZ)=CRDATA(LWORDS+3,NRLY)//CRDATA(LWORDS+4,NRLY)            RELMAR     59
     *                               //CRDATA(LWORDS+5,NRLY)            RELMAR     60
C                                                                       RELMAR     61
      NELM=IRDATA(LWORDS+10,NRLY)                                       RELMAR     62
      NELIST(NZ)=NELM                                                   RELMAR     63
      NE=0                                                              RELMAR     64
      LWORDS=LWORDS+12                                                  RELMAR     65
C                                                                       RELMAR     66
      K=0                                                               RELMAR     67
      DO 400 IM=1,NELM-1                                                RELMAR     68
         IMARK=INDEX(RLIST(NZ)(K+1:12),'/')+K                           RELMAR     69
         IF(IMARK.NE.K)THEN                                             RELMAR     70
            MLIST(IM)=RLIST(NZ)(K+1:IMARK-1)                            RELMAR     71
            K=IMARK+1                                                   RELMAR     72
         ELSE                                                           RELMAR     73
            MLIST(IM)=RLIST(NZ)(K+1:12)                                 RELMAR     74
         ENDIF                                                          RELMAR     75
  400 CONTINUE                                                          RELMAR     76
      MLIST(NELM)=RLIST(NZ)(K+1:12)                                     RELMAR     77
C                                                                       RELMAR     78
  500 NE=NE+1                                                           RELMAR     79
      IWORDS=IRDATA(LWORDS+1,NRLY)+9                                    RELMAR     80
      BUFF(1)=RDATA(LWORDS+2,NRLY)                                      RELMAR     81
      BUFF(2)=RDATA(LWORDS+3,NRLY)                                      RELMAR     82
      BUFF(3)=RDATA(LWORDS+4,NRLY)                                      RELMAR     83
      BUFF(4)=RDATA(LWORDS+5,NRLY)                                      RELMAR     84
      BUFF(5)=RDATA(LWORDS+6,NRLY)                                      RELMAR     85
      BUFF(6)=RDATA(LWORDS+7,NRLY)                                      RELMAR     86
      DO 600 NP=1,N                                                     RELMAR     87
         IF(T(NP).LT.T1.OR.T(NP).GT.T2) GOTO 600                        RELMAR     88
         CALL RELANS(R(NP),X(NP),RMARG,IWORDS,BUFF)                     RELMAR     89
         TMARG(NZ,NE,NP)=RMARG*100.                                     RELMAR     90
         IF(TMARG(NZ,NE,NP).LT.RMMIN(NZ,NE))THEN                        RELMAR     91
            RMMIN(NZ,NE)=TMARG(NZ,NE,NP)                                RELMAR     92
            TMIN(NZ,NE)=T(NP)                                           RELMAR     93
         END IF                                                         RELMAR     94
  600 CONTINUE                                                          RELMAR     95
C                                                                       RELMAR     96
      LWORDS=LWORDS+JWORDS(IWORDS)                                      RELMAR     97
      IF (NE.EQ.1) THEN                                                 RELMAR     98
         ASSIGN 8200 TO I1050                                           RELMAR     99
         IF (ABS(RMMIN(NZ,NE)).GE.100) ASSIGN 8300 TO I1050             RELMAR    100
         WRITE(LOUT,I1050) ZLIST(NZ),MLIST(NE),RMMIN(NZ,NE),TMIN(NZ,NE) RELMAR    101
      ELSE                                                              RELMAR    102
         ASSIGN 8400 TO I1060                                           RELMAR    103
         IF (ABS(RMMIN(NZ,NE)).GE.100) ASSIGN 8500 TO I1060             RELMAR    104
         WRITE(LOUT,I1060) MLIST(NE),RMMIN(NZ,NE),TMIN(NZ,NE)           RELMAR    105
      ENDIF                                                             RELMAR    106
C                                                                       RELMAR    107
      IF(NE.LT.NELM)GOTO 500                                            RELMAR    108
      IF(NZ.LT.NZONE)GOTO 300                                           RELMAR    109
      IF(ISCHEM.LT.NSCHEM) GOTO 200                                     RELMAR    110
C                                                                       RELMAR    111
      WRITE(LOUT,8600)                                                  RELMAR    112
      IZONE=NZONE                                                       RELMAR    113
      NSTART=0                                                          RELMAR    114
  700 IF (IZONE.LE.0) RETURN                                            RELMAR    115
      WRITE(IREL,8700)                                                  RELMAR    116
      MAXZON=IZONE                                                      RELMAR    117
      DO 800 I=1,132                                                    RELMAR    118
  800 OBUF(I:I)=' '                                                     RELMAR    119
C                                                                       RELMAR    120
      OBUF(1:24)=' TIME     R      X      '                             RELMAR    121
      IS=25                                                             RELMAR    122
      LOOKUP(1)=24                                                      RELMAR    123
      DO 900 NZ=1,IZONE                                                 RELMAR    124
         I=INDEX(ZLIST(NZ+NSTART),' ')                                  RELMAR    125
         IF(I.EQ.0) I=6                                                 RELMAR    126
         J=INDEX(RLIST(NZ+NSTART),' ')                                  RELMAR    127
         IF(J.EQ.0) J=12                                                RELMAR    128
         DUM18=ZLIST(NZ+NSTART)(1:I)//RLIST(NZ+NSTART)(1:J)             RELMAR    129
         I=MIN0(I+J-1,18)+5                                             RELMAR    130
         NELM=NELIST(NZ+NSTART)                                         RELMAR    131
         J=NELM*7+2                                                     RELMAR    132
         IS=IS+MAX0(I,J)                                                RELMAR    133
         IF(IS.GT.133) GOTO 910                                         RELMAR    134
         LOOKUP(NZ+1)=IS+1                                              RELMAR    135
         IE=LOOKUP(NZ)+1                                                RELMAR    136
         WRITE(OBUF(IE:),'(A)') DUM18(1:I-5)                            RELMAR    137
  900 CONTINUE                                                          RELMAR    138
  910 CONTINUE                                                          RELMAR    139
      MAXZON=NZ-1                                                       RELMAR    140
      WRITE(IREL,8900) OBUF                                             RELMAR    141
      OBUF(1:23)=' --------------------  '                              RELMAR    142
      DO 960 NZ=1,MAXZON                                                RELMAR    143
         J=LOOKUP(NZ+1)                                                 RELMAR    144
         DO 950 I=LOOKUP(NZ),J-4                                        RELMAR    145
            OBUF(I:I)='-'                                               RELMAR    146
  950    CONTINUE                                                       RELMAR    147
         OBUF(J-3:J-1)='   '                                            RELMAR    148
  960 CONTINUE                                                          RELMAR    149
      WRITE(IREL,8900) OBUF(1:J-1)                                      RELMAR    150
C                                                                       RELMAR    151
      DO 1400 NP=1,N                                                    RELMAR    152
         IF (T(NP).LT.T1.OR.T(NP).GT.T2) GOTO 1400                      RELMAR    153
         DO 1000  I=1,132                                               RELMAR    154
 1000    OBUF(I:I)=' '                                                  RELMAR    155
         WRITE(OBUF(2:7),'(F6.3)') T(NP)                                RELMAR    156
         WRITE(OBUF(9:14),'(F6.3)') R(NP)                               RELMAR    157
         WRITE(OBUF(16:21),'(F6.3)') X(NP)                              RELMAR    158
         DO 1300 NZ=1,MAXZON                                            RELMAR    159
            NELM=NELIST(NZ+NSTART)                                      RELMAR    160
            IS=LOOKUP(NZ)-7                                             RELMAR    161
            DO 1200  NE=1,NELM                                          RELMAR    162
               IS=IS+7                                                  RELMAR    163
               WRITE(OBUF(IS:),'(F6.1)',IOSTAT=IOS)                     RELMAR    164
     *            TMARG(NZ+NSTART,NE,NP)                                RELMAR    165
               IF(IOS.NE.0)                                             RELMAR    166
     *            WRITE(OBUF(IS-1:),'(G7.1)') TMARG(NZ+NSTART,NE,NP)    RELMAR    167
 1200       CONTINUE                                                    RELMAR    168
 1300    CONTINUE                                                       RELMAR    169
         WRITE(IREL,8900) OBUF                                          RELMAR    170
 1400 CONTINUE                                                          RELMAR    171
C                                                                       RELMAR    172
      DO 1600 I=1,132                                                   RELMAR    173
 1600 OBUF(I:I)=' '                                                     RELMAR    174
      OBUF(1:23)=' --------------------  '                              RELMAR    175
      DO 1700 NZ=1,MAXZON                                               RELMAR    176
         J=LOOKUP(NZ+1)                                                 RELMAR    177
         DO 1650 I=LOOKUP(NZ),J-4                                       RELMAR    178
            OBUF(I:I)='-'                                               RELMAR    179
 1650    CONTINUE                                                       RELMAR    180
         OBUF(J-3:J-1)='   '                                            RELMAR    181
 1700 CONTINUE                                                          RELMAR    182
      WRITE(IREL,8900) OBUF(1:J-1)                                      RELMAR    183
C                                                                       RELMAR    184
      DO 1750 I=1,132                                                   RELMAR    185
 1750 OBUF(I:I)=' '                                                     RELMAR    186
      OBUF(1:12)=' MIN MARGIN:'                                         RELMAR    187
      DO 1800 NZ=1,MAXZON                                               RELMAR    188
         NELM=NELIST(NZ+NSTART)                                         RELMAR    189
         IS=LOOKUP(NZ)-7                                                RELMAR    190
         DO 1800 NE=1,NELM                                              RELMAR    191
            IS=IS+7                                                     RELMAR    192
            WRITE(OBUF(IS:),'(F6.1)',IOSTAT=IOS) RMMIN(NZ+NSTART,NE)    RELMAR    193
            IF(IOS.NE.0)                                                RELMAR    194
     *         WRITE(OBUF(IS-1:),'(G7.1)') RMMIN(NZ+NSTART,NE)          RELMAR    195
 1800 CONTINUE                                                          RELMAR    196
      WRITE(IREL,8900) OBUF                                             RELMAR    197
      DO 1900  I=1,132                                                  RELMAR    198
 1900 OBUF(I:I)=' '                                                     RELMAR    199
      OBUF(1:23)=' OCCURRED AT TIME (SEC)'                              RELMAR    200
      DO 2000 NZ=1,MAXZON                                               RELMAR    201
         NELM=NELIST(NZ+NSTART)                                         RELMAR    202
         IS=LOOKUP(NZ)-7                                                RELMAR    203
         DO 2000 NE=1,NELM                                              RELMAR    204
            IS=IS+7                                                     RELMAR    205
 2000 WRITE(OBUF(IS:),'(F6.3)') TMIN(NZ+NSTART,NE)                      RELMAR    206
      WRITE(IREL,8900) OBUF                                             RELMAR    207
      IZONE=IZONE-MAXZON                                                RELMAR    208
      NSTART=NSTART+MAXZON                                              RELMAR    209
      GOTO 700                                                          RELMAR    210
C                                                                       RELMAR    211
 8000 FORMAT(//,' RELAY ID: ',A12,4X,'APP IMP CHANNEL NUMBERS:'         RELMAR    212
     *,2I6,//,' TIME RANGE: FROM',F7.3,' (SEC) TO',F7.3,' (SEC)')       RELMAR    213
 8100 FORMAT(//' ZONE NAME   RELAY MODEL   MIN MARGIN   '               RELMAR    214
     *,'OCCURRED AT TIME (SEC)',/,' ---------   -----------   '         RELMAR    215
     *,'----------   ----------------------')                           RELMAR    216
 8200 FORMAT(3X,A6,6X,A8,F12.2,F19.3)                                   RELMAR    217
 8300 FORMAT(3X,A6,6X,A8,G14.3,F17.3)                                   RELMAR    218
 8400 FORMAT(15X,A8,F12.2,F19.3)                                        RELMAR    219
 8500 FORMAT(15X,A8,G14.3,F17.3)                                        RELMAR    220
 8600 FORMAT(/,' ---------   -----------   ----------'                  RELMAR    221
     *,'   ----------------------')                                     RELMAR    222
 8700 FORMAT(//)                                                        RELMAR    223
 8800 FORMAT(1X,20('-'),T24,20('-'),T47,20('-'),T70,20('-'),            RELMAR    224
     *         T93,20('-')/)                                            RELMAR    225
 8900 FORMAT(1X,A)                                                      RELMAR    226
      END                                                               RELMAR    227
