CFPRIME EDTFIL                                                          EDTFIL      1
C***********************************************************************RIGHTE      1
C*                                                                     *RIGHTE      2
C*        Extended Transient-Midterm Stability Program (ETMSP)         *RIGHTE      3
C*        ====================================================         *RIGHTE      4
C*                                                                     *RIGHTE      5
C*       Copyright (C) (1993) Electric Power Research Institute        *RIGHTE      6
C*                                                                     *RIGHTE      7
C* EPRI reserves all rights in the software and associated             *RIGHTE      8
C* documentation as delivered. The software and its associated         *RIGHTE      9
C* documention or any portion thereof may not be reproduced in any form*RIGHTE     10
C* whatsoever without the consent of EPRI, except as explicity provided*RIGHTE     11
C* for by license. Licensee shall submit a detailed description to EPRI*RIGHTE     12
C* of any changes or modifications to the software within two (2)      *RIGHTE     13
C* months after such changes or modifications are made. At EPRI's sole *RIGHTE     14
C* discretion, the software, as changed or modified, shall be given a  *RIGHTE     15
C* new designation sufficiently different from its then current        *RIGHTE     16
C* designation as to prevent mistake,confusion, or deception as between*RIGHTE     17
C* the current software as changed or modified.                        *RIGHTE     18
C*                                                                     *RIGHTE     19
C* A license under EPRI's rights in the software can be obtained       *RIGHTE     20
C* directly from EPRI.                                                 *RIGHTE     21
C*                                                                     *RIGHTE     22
C* This program and supporting materials may be independently available*RIGHTE     23
C* from Electric Power Software centre (EPSC) for an appropriate       *RIGHTE     24
C* distribution fee. The EPSC is a service of                          *RIGHTE     25
C*                                                                     *RIGHTE     26
C*                    Power Computing Company                          *RIGHTE     27
C*                    1930 Hi Line                                     *RIGHTE     28
C*                    Dallas, Tx 75207                                 *RIGHTE     29
C*                                                                     *RIGHTE     30
C* NEITHER EPRI, ANY MEMBER OF EPRI, NOR ANY PERSON OR  ORGANIZATION   *RIGHTE     31
C* ACTING ON BEHAVE OF THEM:                                           *RIGHTE     32
C*                                                                     *RIGHTE     33
C* 1. MAKE ANY WARRANTY OR REPRESENTATION WHATSOEVER, EXPRESS OR       *RIGHTE     34
C*    IMPLIED, INCLUDING ANY WARRANTY OF MERCHANTABILITY OR FITNESS OR *RIGHTE     35
C*    ANY PURPOSE WITH RESPECT TO THE SOFTWARE OR ITS ASSOCIATED       *RIGHTE     36
C*    DOCUMENTATION; OR                                                *RIGHTE     37
C*                                                                     *RIGHTE     38
C* 2. ASSUMES ANY LIABILITY WHATSOEVER WITH RESPECT TO ANY USE OF THE  *RIGHTE     39
C*    SOFTWARE OR ITS ASSOCIATED DOCUMENTATION OR ANY PORTION THEREOF  *RIGHTE     40
C*    OR WITH RESPECT TO ANY DAMAGES WHICH MAY RESULT FROM SUCH USE.   *RIGHTE     41
C*                                                                     *RIGHTE     42
C* THIS NOTICE MAY NOT BE REMOVED FROM THE SOFTWARE BY ANY USER        *RIGHTE     43
C* THEREOF.                                                            *RIGHTE     44
C*                                                                     *RIGHTE     45
C***********************************************************************RIGHTE     46
      SUBROUTINE EDTFIL(IUX,IUY)                                        EDTFIL      3
CD                                                                      EDTFIL      4
CD    TO PERFORM ON-LINE EDITING FOR A SWITCHING FILE.                  EDTFIL      5
CD                                                                      EDTFIL      6
      INCLUDE 'CNLSTA.INS'                                              EDTFIL      7
      INCLUDE 'CNUNIT.INS'                                              EDTFIL      8
C                                                                       EDTFIL      9
      CHARACTER*160 NCARD                                               EDTFIL     10
      CHARACTER*80  BLANK,SIMBUF,CARD,PMSG,EMSG                         EDTFIL     11
      CHARACTER*50  FILNAM                                              EDTFIL     12
      CHARACTER*10  WORDS(10)                                           EDTFIL     13
      CHARACTER*7   SUBPMT                                              EDTFIL     14
C                                                                       EDTFIL     15
      DATA WORDS/'SUBSTITUTE','REPLACE   ','INSERT    ','DELETE    '    EDTFIL     16
     *          ,'SHOW      ','NEXT      ','LAST      ','HELP      '    EDTFIL     17
     *          ,'QUIT      ','EXIT      '/                             EDTFIL     18
C                                                                       EDTFIL     19
      BLANK(1:40)='                                        '            EDTFIL     20
      BLANK(41:80)='                                        '           EDTFIL     21
      IVAL=ICHAR('A')-ICHAR('a')                                        EDTFIL     22
C                                                                       EDTFIL     23
      JLENG=32                                                          EDTFIL     24
      IKEY=4                                                            EDTFIL     25
      CALL OPENRE(IUY,FILNAM,JLENG,IKEY,ISTAT,0)                        EDTFIL     26
      ILINE=1                                                           EDTFIL     27
      IEND=0                                                            EDTFIL     28
C                                                                       EDTFIL     29
C  DISPLAY SWITCH FILE ON SCREEN                                        EDTFIL     30
C                                                                       EDTFIL     31
      REWIND IUX                                                        EDTFIL     32
C                                                                       EDTFIL     33
 20   CONTINUE                                                          EDTFIL     34
      READ(IUX,5000,IOSTAT=IOS) CARD                                    EDTFIL     35
      IF(IOS.NE.0) GOTO 1000                                            EDTFIL     36
      IEND=IEND+1                                                       EDTFIL     37
      WRITE(IUY,REC=IEND) CARD                                          EDTFIL     38
      GOTO 20                                                           EDTFIL     39
C                                                                       EDTFIL     40
 240  CONTINUE                                                          EDTFIL     41
      DO 250 I=IFIRST,ILAST                                             EDTFIL     42
      READ(IUY,REC=I) CARD                                              EDTFIL     43
      WRITE(LOUT,5020) I,CARD(1:77)                                     EDTFIL     44
 250  CONTINUE                                                          EDTFIL     45
C                                                                       EDTFIL     46
C  LOCATE LINE                                                          EDTFIL     47
C                                                                       EDTFIL     48
      SUBPMT='SWEDIT '                                                  EDTFIL     49
 300  CONTINUE                                                          EDTFIL     50
      CALL REDLIN(LOUT,LIN,IOERR,0,CARD,SUBPMT,'MSW',SIMBUF,RECORD      EDTFIL     51
     *,IREC,KLAYER,KEND,KREAD,PLAYBA)                                   EDTFIL     52
      IF(IOERR.LT.0)THEN                                                EDTFIL     53
      IF(PLAYBA)CALL PSTOP                                              EDTFIL     54
      GOTO 300                                                          EDTFIL     55
      ENDIF                                                             EDTFIL     56
C                                                                       EDTFIL     57
C  MODIFY THE LINE                                                      EDTFIL     58
C                                                                       EDTFIL     59
      I1=0                                                              EDTFIL     60
 420  I1=I1+1                                                           EDTFIL     61
      IF(I1.LT.78.AND.SIMBUF(I1:I1).EQ.' ') GOTO 420                    EDTFIL     62
C                                                                       EDTFIL     63
      DO 430 II=I1,I1+2                                                 EDTFIL     64
        IF(SIMBUF(II:II).GE.'a'.AND.SIMBUF(II:II).LE.'z')               EDTFIL     65
     +     SIMBUF(II:II)=CHAR(ICHAR(SIMBUF(II:II))+IVAL)                EDTFIL     66
 430  CONTINUE                                                          EDTFIL     67
C                                                                       EDTFIL     68
      DO 440 IKEY=1,10                                                  EDTFIL     69
         IF(SIMBUF(I1:I1+2).EQ.WORDS(IKEY)(1:3)) GOTO 480               EDTFIL     70
 440  CONTINUE                                                          EDTFIL     71
      GOTO 300                                                          EDTFIL     72
C                                                                       EDTFIL     73
 480  CONTINUE                                                          EDTFIL     74
      IF(IKEY-9) 570,500,510                                            EDTFIL     75
C                                                                       EDTFIL     76
C     QUIT                                                              EDTFIL     77
C                                                                       EDTFIL     78
 500  IFLG=0                                                            EDTFIL     79
      GOTO 520                                                          EDTFIL     80
C                                                                       EDTFIL     81
C     EXIT                                                              EDTFIL     82
C                                                                       EDTFIL     83
 510  IFLG=1                                                            EDTFIL     84
C                                                                       EDTFIL     85
 520  CALL CLOSEF(IUX)                                                  EDTFIL     86
      IUX=IU60                                                          EDTFIL     87
      IF(IFLG.EQ.0)THEN                                                 EDTFIL     88
        IKEY=9                                                          EDTFIL     89
        LO=0                                                            EDTFIL     90
        CALL OPENRE(IUX,FILNAM,JLENG,IKEY,IEBK,LO)                      EDTFIL     91
      ELSE                                                              EDTFIL     92
        PMSG='ENTER FILE NAME: '                                        EDTFIL     93
        EMSG='ERROR IN OPENING SPECIFIED FILE'                          EDTFIL     94
        LPMSG=17                                                        EDTFIL     95
        LEMSG=31                                                        EDTFIL     96
        IKEY=10                                                         EDTFIL     97
        JLENG=0                                                         EDTFIL     98
        CALL FILEMG(IUX,LPMSG,PMSG,LEMSG,EMSG,SUBPMT,IKEY,JLENG,IEBK)   EDTFIL     99
      ENDIF                                                             EDTFIL    100
C                                                                       EDTFIL    101
      IF(IEBK.NE.0)THEN                                                 EDTFIL    102
        IF(PLAYBA)CALL PSTOP                                            EDTFIL    103
        RETURN                                                          EDTFIL    104
      ENDIF                                                             EDTFIL    105
C                                                                       EDTFIL    106
      DO 550 I=1,IEND                                                   EDTFIL    107
        READ(IUY,REC=I) CARD                                            EDTFIL    108
        WRITE(IUX,5000) CARD                                            EDTFIL    109
 550  CONTINUE                                                          EDTFIL    110
C                                                                       EDTFIL    111
      CALL CLOSEF(IUY)                                                  EDTFIL    112
      REWIND IUX                                                        EDTFIL    113
      RETURN                                                            EDTFIL    114
C                                                                       EDTFIL    115
 570  I1=I1+INDEX(SIMBUF(I1+1:80),' ')                                  EDTFIL    116
      I2=INDEX(SIMBUF,':')                                              EDTFIL    117
      IF(I2.EQ.0) I2=80                                                 EDTFIL    118
      IF(IKEY.LT.6) READ(SIMBUF(I1:I2-1),*,IOSTAT=IOS) ILINE            EDTFIL    119
      IF(ILINE.LT.0.OR.ILINE.GT.IEND.OR.(ILINE.EQ.0.AND.IKEY.NE.3))     EDTFIL    120
     * GOTO 1000                                                        EDTFIL    121
      I1=I2                                                             EDTFIL    122
      NCARD(1:80)=BLANK                                                 EDTFIL    123
      NCARD(81:160)=BLANK                                               EDTFIL    124
C                                                                       EDTFIL    125
C  KEYWORDS  SUB, REP  INS  DEL  SHOW  NEXT  LAST  HELP                 EDTFIL    126
      GOTO ( 600, 700, 800, 900, 1000, 1100, 1200, 1400) IKEY           EDTFIL    127
C                                                                       EDTFIL    128
 600  CONTINUE                                                          EDTFIL    129
      READ(IUY,REC=ILINE) CARD                                          EDTFIL    130
      IF(I1.EQ.80) GOTO 1000                                            EDTFIL    131
      I2=INDEX(SIMBUF(I1+1:80),':')+I1                                  EDTFIL    132
      IF(I1.EQ.I2.OR.I1+1.EQ.I2) GOTO 1000                              EDTFIL    133
      I3=INDEX(SIMBUF(I2+1:80),':')+I2                                  EDTFIL    134
      IF(I3.EQ.I2) GOTO 1000                                            EDTFIL    135
      I4=INDEX(CARD,SIMBUF(I1+1:I2-1))                                  EDTFIL    136
      IF(I4.EQ.0)THEN                                                   EDTFIL    137
C        ERROR MESSAGE                                                  EDTFIL    138
         GOTO 1000                                                      EDTFIL    139
      ENDIF                                                             EDTFIL    140
      IF(I4.NE.1) NCARD(1:I4-1)=CARD(1:I4-1)                            EDTFIL    141
      IF(I2+1.NE.I3) NCARD(I4:I4+I3-I2-2)=SIMBUF(I2+1:I3-1)             EDTFIL    142
      NCARD(I4+I3-I2-1:80+I1+I3-2*I2)=CARD(I4+I2-I1-1:80)               EDTFIL    143
      WRITE(IUY,REC=ILINE) NCARD(1:80)                                  EDTFIL    144
      IF(NCARD(81:160).EQ.BLANK) GOTO 1000                              EDTFIL    145
 650  CONTINUE                                                          EDTFIL    146
      DO 680 I=IEND,ILINE+1,-1                                          EDTFIL    147
      READ(IUY,REC=I) CARD                                              EDTFIL    148
      WRITE(IUY,REC=I+1) CARD                                           EDTFIL    149
 680  CONTINUE                                                          EDTFIL    150
      WRITE(IUY,REC=ILINE+1) NCARD(81:160)                              EDTFIL    151
      IEND=IEND+1                                                       EDTFIL    152
      GOTO 1000                                                         EDTFIL    153
C                                                                       EDTFIL    154
C  REPLACE OLD LINE                                                     EDTFIL    155
C                                                                       EDTFIL    156
 700  CONTINUE                                                          EDTFIL    157
      IF(I1.EQ.80) GOTO 1000                                            EDTFIL    158
      NCARD(1:80-I1)=SIMBUF(I1+1:80)                                    EDTFIL    159
      WRITE(IUY,REC=ILINE) NCARD(1:80)                                  EDTFIL    160
      GOTO 1000                                                         EDTFIL    161
C                                                                       EDTFIL    162
C  INSERT NEW LINE                                                      EDTFIL    163
C                                                                       EDTFIL    164
 800  CONTINUE                                                          EDTFIL    165
      ILINE=ILINE-1                                                     EDTFIL    166
      NCARD(81:160-I1)=SIMBUF(I1+1:80)                                  EDTFIL    167
      GOTO 650                                                          EDTFIL    168
C                                                                       EDTFIL    169
C  DELETE A LINE                                                        EDTFIL    170
C                                                                       EDTFIL    171
 900  CONTINUE                                                          EDTFIL    172
      IEND=IEND-1                                                       EDTFIL    173
      DO 950 I=ILINE,IEND                                               EDTFIL    174
      READ(IUY,REC=I+1) CARD                                            EDTFIL    175
      WRITE(IUY,REC=I) CARD                                             EDTFIL    176
 950  CONTINUE                                                          EDTFIL    177
C                                                                       EDTFIL    178
C  DISPLAY ABOUT A LINE                                                 EDTFIL    179
C                                                                       EDTFIL    180
 1000 CONTINUE                                                          EDTFIL    181
      IFIRST=MAX(ILINE-10,1)                                            EDTFIL    182
      ILAST=MIN(ILINE+11,IEND)                                          EDTFIL    183
      IF((ILAST-IFIRST).LT.21)THEN                                      EDTFIL    184
         IF(IFIRST.NE.1) IFIRST=MAX(1,IEND-21)                          EDTFIL    185
         IF(ILAST.NE.IEND) ILAST=MIN(IEND,IFIRST+21)                    EDTFIL    186
      ENDIF                                                             EDTFIL    187
      GOTO 240                                                          EDTFIL    188
C                                                                       EDTFIL    189
C  DISPLAY NEXT PAGE                                                    EDTFIL    190
C                                                                       EDTFIL    191
 1100 CONTINUE                                                          EDTFIL    192
      ILINE=ILAST                                                       EDTFIL    193
      GOTO 1000                                                         EDTFIL    194
C                                                                       EDTFIL    195
C  DISPLAY LAST PAGE                                                    EDTFIL    196
C                                                                       EDTFIL    197
 1200 CONTINUE                                                          EDTFIL    198
      ILINE=IFIRST                                                      EDTFIL    199
      GOTO 1000                                                         EDTFIL    200
C                                                                       EDTFIL    201
C  DISPLAY HELP SCREEN                                                  EDTFIL    202
C                                                                       EDTFIL    203
 1400 CONTINUE                                                          EDTFIL    204
      CARD='MSWITDA  '                                                  EDTFIL    205
      CALL HELPSC(CARD(1:50),4)                                         EDTFIL    206
      GOTO 300                                                          EDTFIL    207
C                                                                       EDTFIL    208
 5000 FORMAT(A80)                                                       EDTFIL    209
 5020 FORMAT(I3,1X,A)                                                   EDTFIL    210
      END                                                               EDTFIL    211
