CFPRIME RDLINE                                                          RDLINE      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 RDLINE(NRLY,MLINE)                                     RDLINE      3
CD                                                                      RDLINE      4
CD        THIS ROUTINE OPENS THE RELAY DATA BASE FILE  AND              RDLINE      5
CD        READS IN THE RELAY DATA                                       RDLINE      6
CD                                                                      RDLINE      7
CD        CALLING PARAMETER :                                           RDLINE      8
CD                                                                      RDLINE      9
CD                     NRLY - POINTER FOR THE RELAY DATA                RDLINE     10
CD                                                                      RDLINE     11
C                                                                       RDLINE     12
      INCLUDE 'SOAPC1.INS'                                              RDLINE     13
      INCLUDE 'CNDATA.INS'                                              RDLINE     14
      PARAMETER(MLENG=128,MAXSTN=4096)                                  RDLINE     15
C                                                                       RDLINE     16
      COMMON /RFNAME/ RNAME,LRNAME                                      RDLINE     17
      CHARACTER*80 RNAME                                                RDLINE     18
      DIMENSION IHREC(22),JCNAME(12*MAXSTN),JSNAME(6*MAXSTN)            RDLINE     19
     *   ,MEXLIN(3*MAXSTN)                                              RDLINE     20
      COMMON /RLNAME/ ICNAME(12,MAXSTN),ISNAME(6,MAXSTN),NSTAT          RDLINE     21
     *   ,NEXLIN(3,MAXSTN),JNEXLI                                       RDLINE     22
      CHARACTER*4 CNAME(12,MAXSTN),SNAME(6,MAXSTN)                      RDLINE     23
      CHARACTER*12 RLYID,STNAME                                         RDLINE     24
      EQUIVALENCE (ICNAME(1,1),CNAME(1,1),JCNAME(1))                    RDLINE     25
      EQUIVALENCE (ISNAME(1,1),SNAME(1,1),JSNAME(1))                    RDLINE     26
      EQUIVALENCE (NEXLIN(1,1),MEXLIN(1))                               RDLINE     27
      CHARACTER*80 MSG,STRING                                           RDLINE     28
      LOGICAL IEND                                                      RDLINE     29
C                                                                       RDLINE     30
      SAVE NOENTY                                                       RDLINE     31
      DATA NOENTY/0/                                                    RDLINE     32
C                                                                       RDLINE     33
      JJREC=ICNAME(10,NRLY)                                             RDLINE     34
      IWORDS=ICNAME(11,NRLY)                                            RDLINE     35
      LREC=(IWORDS+MLENG-1)/MLENG                                       RDLINE     36
C                                                                       RDLINE     37
C  READ RDATA ARRAYS                                                    RDLINE     38
C                                                                       RDLINE     39
      KK=-MLENG                                                         RDLINE     40
      DO 220 I=1,LREC                                                   RDLINE     41
      KK=KK+MLENG                                                       RDLINE     42
      CALL DAFLWR(LU55,1,JJREC,RDATA(KK+1,MLINE),MLENG,IEND)            RDLINE     43
      IF(IEND) THEN                                                     RDLINE     44
         WRITE(LOUT,1000)                                               RDLINE     45
         RETURN                                                         RDLINE     46
      ENDIF                                                             RDLINE     47
 220  CONTINUE                                                          RDLINE     48
      RETURN                                                            RDLINE     49
C                                                                       RDLINE     50
      ENTRY RLHEAD                                                      RDLINE     51
      IF(NOENTY.NE.0) RETURN                                            RDLINE     52
      CALL OPENFI(LU55,RNAME,LRNAME,IERR,'OLD',2)                       RDLINE     53
      IF(IERR.NE.0)THEN                                                 RDLINE     54
         WRITE(LOUT,'(A)') ' *** RELAY DATA BASE FILE OPEN ERROR'       RDLINE     55
         RETURN                                                         RDLINE     56
      ENDIF                                                             RDLINE     57
C                                                                       RDLINE     58
      JREC=1                                                            RDLINE     59
      CALL DAIWR4(LU55,1,JREC,IHREC(1),22,IEND)                         RDLINE     60
      IF(IEND) THEN                                                     RDLINE     61
         WRITE(LOUT,1000)                                               RDLINE     62
         RETURN                                                         RDLINE     63
      ENDIF                                                             RDLINE     64
C                                                                       RDLINE     65
      NOENTY=IHREC(12)                                                  RDLINE     66
      JREC=IHREC(16)                                                    RDLINE     67
      LREC=IHREC(17)                                                    RDLINE     68
      KK=-MLENG                                                         RDLINE     69
      DO 110 LL=1,LREC                                                  RDLINE     70
      KK=KK+MLENG                                                       RDLINE     71
      CALL DAIWR4(LU55,1,JREC,JCNAME(KK+1),MLENG,IEND)                  RDLINE     72
      IF(IEND) THEN                                                     RDLINE     73
         WRITE(LOUT,1000)                                               RDLINE     74
         RETURN                                                         RDLINE     75
      ENDIF                                                             RDLINE     76
 110  CONTINUE                                                          RDLINE     77
C                                                                       RDLINE     78
      JREC=IHREC(18)                                                    RDLINE     79
      LREC=IHREC(19)                                                    RDLINE     80
      NSTAT=IHREC(22)                                                   RDLINE     81
      KK=-MLENG                                                         RDLINE     82
      DO 120 LL=1,LREC                                                  RDLINE     83
      KK=KK+MLENG                                                       RDLINE     84
      CALL DAIWR4(LU55,1,JREC,JSNAME(KK+1),MLENG,IEND)                  RDLINE     85
      IF(IEND)THEN                                                      RDLINE     86
         WRITE(LOUT,1000)                                               RDLINE     87
         RETURN                                                         RDLINE     88
      ENDIF                                                             RDLINE     89
  120 CONTINUE                                                          RDLINE     90
      JREC=IHREC(20)                                                    RDLINE     91
      LREC=IHREC(21)                                                    RDLINE     92
      JNEXLI=IHREC(15)                                                  RDLINE     93
      KK=-MLENG                                                         RDLINE     94
      DO 140 LL=1,LREC                                                  RDLINE     95
      KK=KK+MLENG                                                       RDLINE     96
      CALL DAIWR4(LU55,1,JREC,MEXLIN(KK+1),MLENG,IEND)                  RDLINE     97
      IF(IEND)THEN                                                      RDLINE     98
         WRITE(LOUT,1000)                                               RDLINE     99
         RETURN                                                         RDLINE    100
      ENDIF                                                             RDLINE    101
  140 CONTINUE                                                          RDLINE    102
      RETURN                                                            RDLINE    103
C                                                                       RDLINE    104
      ENTRY FNSTAT(STNAME,J)                                            RDLINE    105
      J=0                                                               RDLINE    106
      ILARGE=NSTAT+1                                                    RDLINE    107
   80 ISMALL=J                                                          RDLINE    108
   50 J=(ILARGE+ISMALL)/2                                               RDLINE    109
      IF(J.EQ.ISMALL)THEN                                               RDLINE    110
         J=0                                                            RDLINE    111
         RETURN                                                         RDLINE    112
      ENDIF                                                             RDLINE    113
      IF(SNAME(1,J).GT.STNAME(1:4)) GOTO 70                             RDLINE    114
      IF(SNAME(1,J).LT.STNAME(1:4)) GOTO 80                             RDLINE    115
      IF(SNAME(2,J).GT.STNAME(5:8)) GOTO 70                             RDLINE    116
      IF(SNAME(2,J).LT.STNAME(5:8)) GOTO 80                             RDLINE    117
      IF(SNAME(3,J).GT.STNAME(9:12)) GOTO 70                            RDLINE    118
      IF(SNAME(3,J).LT.STNAME(9:12)) GOTO 80                            RDLINE    119
      L=J                                                               RDLINE    120
      J=ISNAME(4,L)                                                     RDLINE    121
      K=ISNAME(6,L)                                                     RDLINE    122
      IF(K.EQ.0) RETURN                                                 RDLINE    123
      M=0                                                               RDLINE    124
      WRITE(LOUT,'(/////)')                                             RDLINE    125
   20 M=M+1                                                             RDLINE    126
      I=MOD(M-1,3)                                                      RDLINE    127
      WRITE(STRING(I*24+1:),2000) M,CNAME(1,J)//CNAME(2,J)(1:2)//'('//  RDLINE    128
     *   CNAME(3,J)//')'                                                RDLINE    129
      IF(I.EQ.2) WRITE(LOUT,'(A)') STRING                               RDLINE    130
      J=NEXLIN(1,K)                                                     RDLINE    131
      K=NEXLIN(3,K)                                                     RDLINE    132
      IF(K.NE.0) GOTO 20                                                RDLINE    133
      IF(I.NE.2) WRITE(LOUT,'(A)') STRING                               RDLINE    134
      DO 60 I=1,15-M/3                                                  RDLINE    135
   60 WRITE(LOUT,*)                                                     RDLINE    136
      MSG='Select by the number'                                        RDLINE    137
   30 CALL PMTRED(LOUT,LIN,JERR,20,MSG,'RLY',STRING)                    RDLINE    138
      IF(RECORD) WRITE(IREC,'(A)') STRING                               RDLINE    139
      READ(STRING,*,IOSTAT=IOS) N                                       RDLINE    140
      IF(IOS.NE.0.OR.N.LT.1.OR.N.GT.M) GOTO 30                          RDLINE    141
      J=ISNAME(4,L)                                                     RDLINE    142
      K=ISNAME(6,L)                                                     RDLINE    143
   40 N=N-1                                                             RDLINE    144
      IF(N.EQ.0) RETURN                                                 RDLINE    145
      J=NEXLIN(1,K)                                                     RDLINE    146
      K=NEXLIN(3,K)                                                     RDLINE    147
      GOTO 40                                                           RDLINE    148
   70 ILARGE=J                                                          RDLINE    149
      GOTO 50                                                           RDLINE    150
C                                                                       RDLINE    151
      ENTRY FLINE(STNAME,J)                                             RDLINE    152
      J=0                                                               RDLINE    153
      ILARGE=NOENTY+1                                                   RDLINE    154
  380 ISMALL=J                                                          RDLINE    155
  350 J=(ILARGE+ISMALL)/2                                               RDLINE    156
      IF(J.EQ.ISMALL)THEN                                               RDLINE    157
         J=0                                                            RDLINE    158
         RETURN                                                         RDLINE    159
      ENDIF                                                             RDLINE    160
      IF(CNAME(1,J).GT.STNAME(1:4)) GOTO 370                            RDLINE    161
      IF(CNAME(1,J).LT.STNAME(1:4)) GOTO 380                            RDLINE    162
      IF(CNAME(2,J).GT.STNAME(5:8)) GOTO 370                            RDLINE    163
      IF(CNAME(2,J).LT.STNAME(5:8)) GOTO 380                            RDLINE    164
      IF(STNAME(9:12).EQ.'    ') GOTO 400                               RDLINE    165
      IF(CNAME(3,J).EQ.STNAME(9:12)) RETURN                             RDLINE    166
      IF(CNAME(3,J).LT.STNAME(9:12)) GOTO 380                           RDLINE    167
  370 ILARGE=J                                                          RDLINE    168
      GOTO 350                                                          RDLINE    169
C                                                                       RDLINE    170
  400 IF(CNAME(1,J-1).EQ.CNAME(1,J).AND.CNAME(2,J-1).EQ.CNAME(2,J))THEN RDLINE    171
         J=J-1                                                          RDLINE    172
         GOTO 400                                                       RDLINE    173
      ENDIF                                                             RDLINE    174
  440 L=J                                                               RDLINE    175
  500 L=L+1                                                             RDLINE    176
      IF(CNAME(1,L).EQ.CNAME(1,J).AND.CNAME(2,L).EQ.CNAME(2,J))THEN     RDLINE    177
         IF(J.EQ.L-1)THEN                                               RDLINE    178
            WRITE(LOUT,'(/////)')                                       RDLINE    179
            WRITE(LOUT,2000) L-J,CNAME(1,J)//CNAME(2,J)(1:2)//'('//     RDLINE    180
     *         CNAME(3,J)//')'                                          RDLINE    181
         ENDIF                                                          RDLINE    182
         WRITE(LOUT,2000) L-J+1,CNAME(1,L)//CNAME(2,L)(1:2)//'('//      RDLINE    183
     *         CNAME(3,L)//')'                                          RDLINE    184
         GOTO 500                                                       RDLINE    185
      ENDIF                                                             RDLINE    186
      L=L-J                                                             RDLINE    187
      IF(L.EQ.1) RETURN                                                 RDLINE    188
      DO 510 I=1,15-L                                                   RDLINE    189
  510 WRITE(LOUT,*)                                                     RDLINE    190
      MSG='Select by the number'                                        RDLINE    191
      CALL PMTRED(LOUT,LIN,JERR,20,MSG,'RLY',STRING)                    RDLINE    192
      IF(RECORD) WRITE(IREC,'(A)') STRING                               RDLINE    193
      READ(STRING,*,IOSTAT=IOS) N                                       RDLINE    194
      IF(IOS.NE.0.OR.N.LT.1.OR.N.GT.L) GOTO 440                         RDLINE    195
      J=J+N-1                                                           RDLINE    196
      RETURN                                                            RDLINE    197
C                                                                       RDLINE    198
 1000 FORMAT(' *** ERROR READING RELAY DATA BASE')                      RDLINE    199
 2000 FORMAT(I10,'. ',A)                                                RDLINE    200
      END                                                               RDLINE    201
