CFPRIME FILRUN                                                          FILRUN      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
C                                                                       FILRUN      3
       SUBROUTINE FILRUN (IEBK)                                         FILRUN      4
CD                                                                      FILRUN      5
CD  This subroutine reads in the information in the control file,       FILRUN      6
CD  organizes the information and stores it in a scratch file.          FILRUN      7
CD                                                                      FILRUN      8
C---------------------------------------------------------------------  FILRUN      9
C                                                        Include files  FILRUN     10
C                                                                       FILRUN     11
      INCLUDE 'PARX.INS'                                                FILRUN     12
      INCLUDE 'CNPT.INS'                                                FILRUN     13
      INCLUDE 'CNB0.INS'                                                FILRUN     14
      INCLUDE 'CNB4.INS'                                                FILRUN     15
      INCLUDE 'CNB19.INS'                                               FILRUN     16
      INCLUDE 'CNUNIT.INS'                                              FILRUN     17
      INCLUDE 'CNLUN.INS'                                               FILRUN     18
      INCLUDE 'CNIMPR.INS'                                              FILRUN     19
      INCLUDE 'CNULTC.INS'                                              FILRUN     20
      INCLUDE 'CNMSG.INS'                                               FILRUN     21
      INCLUDE 'CNREC1.INS'                                              FILRUN     22
      INCLUDE 'CNLSTA.INS'                                              FILRUN     23
      INCLUDE 'CNFRUN.INS'                                              FILRUN     24
      INCLUDE 'CNTMDA.INS'                                              FILRUN     25
      INCLUDE 'CNFLAG.INS'                                              FILRUN     26
C---------------------------------------------------------------------  FILRUN     27
C                                                      Local Variables  FILRUN     28
C                                                                       FILRUN     29
       LOGICAL       LCASE, INITIL, SIMLAT, RLDFLG, DYDFLG              FILRUN     30
C                                                                       FILRUN     31
       CHARACTER*8   KYWRD2(13)                                         FILRUN     32
       CHARACTER*10  KWORD, KYWRD1(12)                                  FILRUN     33
       CHARACTER*12  CASEID,BLNK12                                      FILRUN     34
       CHARACTER*20  LFFRMT,BLNK20                                      FILRUN     35
       CHARACTER*50  FILNAM, LFDAFN, SWFLNM, INDYFN, SVDYFN             FILRUN     36
       CHARACTER*50  RLDAFN, OUTSFN, TASWFN, RESLFN, DYDAFN, BLNK50     FILRUN     37
       CHARACTER*80  CARD, STRING, PMSG, EMSG, REFGEN, BLNK80           FILRUN     38
       CHARACTER*80  TITLE(6)                                           FILRUN     39
C                                                                       FILRUN     40
       EQUIVALENCE   (TITLE(1), ITITLE(1,1))                            FILRUN     41
       EQUIVALENCE   (CASEID, ICASID(1))                                FILRUN     42
C                                                                       FILRUN     43
       DATA KYWRD1 / 'CASE', 'LOADFLOW', 'DYNAMIC', 'BPADYN', 'RELAY',  FILRUN     44
     +               'OUTPUT', 'SWITCHING', 'TAB DATA', 'TAB IC',       FILRUN     45
     +               'ANALYSIS', 'INITIALIZE', 'WRT DATA' /             FILRUN     46
C                                                                       FILRUN     47
       DATA KYWRD2 / 'CASEID', 'TITLE1', 'TITLE2', 'TITLE3', 'TITLE4',  FILRUN     48
     +               'TITLE5', 'TITLE6', 'CHKGENID', 'SYSTEM',          FILRUN     49
     +               'ALGEBRA', 'IMPLICIT', 'CHECKS', 'REFGBS' /        FILRUN     50
C---------------------------------------------------------------------  FILRUN     51
C                                                       Initialization  FILRUN     52
C                                                                       FILRUN     53
       BLNK12 = '           '                                           FILRUN     54
       BLNK20 = '                   '                                   FILRUN     55
       BLNK50 = '                                                  '    FILRUN     56
       BLNK80 = BLNK20 // BLNK20 // BLNK20 // BLNK20                    FILRUN     57
       IUFRUN = IU55                                                    FILRUN     58
C                                                                       FILRUN     59
       LDEB=.FALSE.                                                     FILRUN     60
       LFID = 'BASE CASE 1'                                             FILRUN     61
       LFNUMB = 99                                                      FILRUN     62
       LFREC = 0                                                        FILRUN     63
       LFDAFN = BLNK50                                                  FILRUN     64
       LFFRMT = 'PTI'                                                   FILRUN     65
       INDYFN = BLNK50                                                  FILRUN     66
       SVDYFN = BLNK50                                                  FILRUN     67
       IBPAFL = -1                                                      FILRUN     68
       RLDAFN = BLNK50                                                  FILRUN     69
       OUTSFN = BLNK50                                                  FILRUN     70
       SWFLNM = BLNK50                                                  FILRUN     71
       TASWFN = BLNK50                                                  FILRUN     72
       RESLFN = BLNK50                                                  FILRUN     73
       DYDAFN = BLNK50                                                  FILRUN     74
       ISWSM = 0                                                        FILRUN     75
       LCASE = .FALSE.                                                  FILRUN     76
       INITIL = .FALSE.                                                 FILRUN     77
       SIMLAT = .FALSE.                                                 FILRUN     78
       NLFR = 0                                                         FILRUN     79
       BSNAMR = BLNK12                                                  FILRUN     80
       REFGEN = BLNK80                                                  FILRUN     81
C                                                                       FILRUN     82
       CALL MOVE (0, IFSPTR, IFSPTR, NFSPTR)                            FILRUN     83
       CALL MOVE (0, INXPTR, INXPTR, MXRECS)                            FILRUN     84
C                                                                       FILRUN     85
       KEY1 = 0                                                         FILRUN     86
       JREC = 0                                                         FILRUN     87
C                    Prompt for name of control file and open the file  FILRUN     88
       PMSG = 'ENTER CONTROL FILE NAME: '                               FILRUN     89
       LMSG = 25                                                        FILRUN     90
 900   CALL PMTRED (LOUT, LIN, IEBK, LMSG, PMSG, 'FIL', STRING, KREAD,  FILRUN     91
     +              PLAYBA)                                             FILRUN     92
       IK = IFNBLK (STRING, 79)                                         FILRUN     93
       IF (IK .EQ. 0) GOTO 900                                          FILRUN     94
C                                                                       FILRUN     95
       IF (STRING(1:1) .EQ. '*') THEN                                   FILRUN     96
         IUFRUN = LIN                                                   FILRUN     97
       ELSE                                                             FILRUN     98
         FILNAM = STRING(IK:IK+49)                                      FILRUN     99
         CALL PARSIU (FILNAM, LEN, IU, LO)                              FILRUN    100
         IF (IU .LT. 0) GOTO 950                                        FILRUN    101
         IF (IU .GT. 0) THEN                                            FILRUN    102
           STRING = FILNAM(1:LO)                                        FILRUN    103
           FILNAM = STRING(1:LO)                                        FILRUN    104
           IUFRUN = IU                                                  FILRUN    105
           CALL FBOKEP (IUFRUN, IBACK)                                  FILRUN    106
           IF (IBACK .LT. 0) GOTO 950                                   FILRUN    107
         ENDIF                                                          FILRUN    108
         IKEY = 1                                                       FILRUN    109
         LO = INDEX (FILNAM, ' ')                                       FILRUN    110
         JLENG = 0                                                      FILRUN    111
         CALL OPENRE (IUFRUN, FILNAM, JLENG, IKEY, ISTAT, LO)           FILRUN    112
         IF (ISTAT .NE. 0) GOTO 950                                     FILRUN    113
         LUNITS(IUFRUN) = .TRUE.                                        FILRUN    114
       ENDIF                                                            FILRUN    115
C                                                                       FILRUN    116
       GOTO 990                                                         FILRUN    117
C                                                                       FILRUN    118
 950   MSG(1) = ' *** ERROR OPENING CONTROL FILE'                       FILRUN    119
       CALL PRTMSG(1)                                                   FILRUN    120
       IEBK = 1                                                         FILRUN    121
       GOTO 8900                                                        FILRUN    122
C                       Open scratch file (direct access, unformatted)  FILRUN    123
 990   JLENG = 50                                                       FILRUN    124
       IKEY = 4                                                         FILRUN    125
       CALL OPENRE (IU56, FILNAM, JLENG, IKEY, ISTAT, 0)                FILRUN    126
       LUNITS(IU56) = .TRUE.                                            FILRUN    127
C                   Open scratch files for dynamic data and relay data  FILRUN    128
C                              Both are to be sequential and formatted  FILRUN    129
       IKEY = 9                                                         FILRUN    130
       LO = 0                                                           FILRUN    131
       JLENG = 0                                                        FILRUN    132
       FILNAM = BLNK50                                                  FILRUN    133
       CALL OPENRE (IU50, FILNAM, JLENG, IKEY, ISTAT, LO)               FILRUN    134
       LUNITS(IU50) = .TRUE.                                            FILRUN    135
       CALL OPENRE (IU54, FILNAM, JLENG, IKEY, ISTAT, LO)               FILRUN    136
       LUNITS(IU54) = .TRUE.                                            FILRUN    137
C---------------------------------------------------------------------  FILRUN    138
C                               Get the first keyword (must be RESULT)  FILRUN    139
C                                                                       FILRUN    140
       CALL GETLIN (IUFRUN, CARD)                                       FILRUN    141
C                                                                       FILRUN    142
       I1 = INDEX (CARD, '[')                                           FILRUN    143
       IF (I1 .EQ. 0) GOTO 1000                                         FILRUN    144
       I2 = INDEX (CARD, ']')                                           FILRUN    145
       IF (I2 .LT. I1+4) GOTO 1000                                      FILRUN    146
C                                                                       FILRUN    147
       IF (I2 .GT. I1+11) I2 = I1 + 11                                  FILRUN    148
       KWORD = CARD(I1+1:I2-1)                                          FILRUN    149
       IF (KWORD(1:3) .EQ. 'RES') GOTO 1010                             FILRUN    150
C                                                                       FILRUN    151
 1000  IEBK = 1                                                         FILRUN    152
       WRITE (LOUT, '(/, A, /)')                                        FILRUN    153
     +       ' *** ERROR - FIRST KEYWORD NOT PROPERLY SPECIFIED'        FILRUN    154
       GOTO 8900                                                        FILRUN    155
C---------------------------------------------------------------------  FILRUN    156
C       Open warning/error message, progress report, simulation result  FILRUN    157
C         and simulation binary files and print the first page headers  FILRUN    158
C                                                                       FILRUN    159
 1010  CALL GETLIN (IUFRUN, CARD)                                       FILRUN    160
C                                                                       FILRUN    161
       IK = INDEX (CARD, '=')                                           FILRUN    162
       IF (IK .EQ. 0) GOTO 2000                                         FILRUN    163
       STRING = CARD(IK+1:80)                                           FILRUN    164
C                                                                       FILRUN    165
       CALL FSTLST (STRING, 80, IFCHR, ILCHR)                           FILRUN    166
       IF (IFCHR .EQ. 0) GOTO 2000                                      FILRUN    167
       IF ((ILCHR-IFCHR+1) .GT. 50) GOTO 2000                           FILRUN    168
       FILNAM = STRING(IFCHR:ILCHR)                                     FILRUN    169
C                                                                       FILRUN    170
       II = 0                                                           FILRUN    171
       DO 1020 JJ = 1, 50                                               FILRUN    172
         IF (II .EQ. 0) THEN                                            FILRUN    173
           IF (FILNAM(JJ:JJ) .EQ. ' ') GOTO 1020                        FILRUN    174
           II = JJ                                                      FILRUN    175
         ENDIF                                                          FILRUN    176
         IF (FILNAM(JJ:JJ) .GE. 'A' .AND.                               FILRUN    177
     +       FILNAM(JJ:JJ) .LE. 'Z') THEN                               FILRUN    178
           LCASE = .FALSE.                                              FILRUN    179
         ELSE IF (FILNAM(JJ:JJ) .GE. 'a' .AND.                          FILRUN    180
     +            FILNAM(JJ:JJ) .LE. 'z') THEN                          FILRUN    181
           LCASE = .TRUE.                                               FILRUN    182
         ELSE IF (FILNAM(JJ:JJ) .NE. ' ') THEN                          FILRUN    183
           GOTO 1020                                                    FILRUN    184
         ENDIF                                                          FILRUN    185
         GOTO 1030                                                      FILRUN    186
 1020  CONTINUE                                                         FILRUN    187
C                                           Invalid file specification  FILRUN    188
       GOTO 2000                                                        FILRUN    189
C                                                                       FILRUN    190
 1030  STRING = FILNAM(II:50)                                           FILRUN    191
       FILNAM = STRING(1:50)                                            FILRUN    192
       CALL PARSIU (FILNAM, LEN, IU, LO)                                FILRUN    193
C                                                                       FILRUN    194
       IF (IU .LT. 0) GOTO 2000                                         FILRUN    195
C                                                                       FILRUN    196
       IF (IU .GT. 0) THEN                                              FILRUN    197
         STRING = FILNAM(1:LO)                                          FILRUN    198
         FILNAM = STRING(1:LO)                                          FILRUN    199
         IU16 = IU                                                      FILRUN    200
         CALL FBOKEP (IU16, IBACK)                                      FILRUN    201
         IF (IBACK .LT. 0) GOTO 2000                                    FILRUN    202
 1040    IU = IU + 1                                                    FILRUN    203
         IU6 = IU                                                       FILRUN    204
         CALL FBOKEP (IU6, IBACK)                                       FILRUN    205
         IF (IBACK .LT. 0) GOTO 1040                                    FILRUN    206
 1050    IU = IU + 1                                                    FILRUN    207
         IU8 = IU                                                       FILRUN    208
         CALL FBOKEP (IU8, IBACK)                                       FILRUN    209
         IF (IBACK .LT. 0) GOTO 1050                                    FILRUN    210
       ENDIF                                                            FILRUN    211
C                                                        Open MSG file  FILRUN    212
       I1 = INDEX (FILNAM, ' ')                                         FILRUN    213
       IF (LCASE) THEN                                                  FILRUN    214
         FILNAM(I1:I1+3) = '.msg'                                       FILRUN    215
       ELSE                                                             FILRUN    216
         FILNAM(I1:I1+3) = '.MSG'                                       FILRUN    217
       ENDIF                                                            FILRUN    218
       LO = I1 + 3                                                      FILRUN    219
       IKEY = 6                                                         FILRUN    220
       JLENG = 133                                                      FILRUN    221
       CALL OPENRE (IU16, FILNAM, JLENG, IKEY, ISTAT, LO)               FILRUN    222
       IF (ISTAT .NE. 0) THEN                                           FILRUN    223
         WRITE (LOUT, '(/, A, /)')                                      FILRUN    224
     +   ' *** ERROR OPENING WARNING AND ERROR MESSAGES FILE.'          FILRUN    225
         GOTO 2000                                                      FILRUN    226
       ELSE                                                             FILRUN    227
         LUNITS(IU16) = .TRUE.                                          FILRUN    228
       ENDIF                                                            FILRUN    229
       EMSG = 'WARNING AND ERROR MESSAGES REPORT'                       FILRUN    230
       LMSG = 33                                                        FILRUN    231
       CALL PHEAD (IU16, LMSG, EMSG)                                    FILRUN    232
C                                                        Open PRG file  FILRUN    233
       IF (LCASE) THEN                                                  FILRUN    234
         FILNAM(I1:I1+3) = '.prg'                                       FILRUN    235
       ELSE                                                             FILRUN    236
         FILNAM(I1:I1+3) = '.PRG'                                       FILRUN    237
       ENDIF                                                            FILRUN    238
       IKEY = 6                                                         FILRUN    239
       JLENG = 133                                                      FILRUN    240
       CALL OPENRE (IU6, FILNAM, JLENG, IKEY, ISTAT, LO)                FILRUN    241
       IF (ISTAT .NE. 0) THEN                                           FILRUN    242
         MSG(1) = ' *** ERROR OPENING PROGRAM PROGRESS REPORT FILE.'    FILRUN    243
         CALL PRTMSG (1)                                                FILRUN    244
         GOTO 2000                                                      FILRUN    245
       ELSE                                                             FILRUN    246
         LUNITS(IU6) = .TRUE.                                           FILRUN    247
       ENDIF                                                            FILRUN    248
       EMSG = 'PROGRAM PROGRESS REPORT'                                 FILRUN    249
       LMSG = 23                                                        FILRUN    250
       CALL PHEAD (IU6, LMSG, EMSG)                                     FILRUN    251
C                                                        Open BIN file  FILRUN    252
       IF (LCASE) THEN                                                  FILRUN    253
         FILNAM(I1:I1+3) = '.bin'                                       FILRUN    254
       ELSE                                                             FILRUN    255
         FILNAM(I1:I1+3) = '.BIN'                                       FILRUN    256
       ENDIF                                                            FILRUN    257
       IKEY = 5                                                         FILRUN    258
       JLENG = 128                                                      FILRUN    259
       CALL OPENRE (IU8, FILNAM, JLENG, IKEY, ISTAT, LO)                FILRUN    260
       IF (ISTAT .NE. 0) THEN                                           FILRUN    261
         MSG(1) = ' *** ERROR OPENING SIMULATION RESULT ' //            FILRUN    262
     +            'BINARY FILE.'                                        FILRUN    263
         CALL PRTMSG (1)                                                FILRUN    264
         GOTO 2000                                                      FILRUN    265
       ELSE                                                             FILRUN    266
         LUNITS(IU8) = .TRUE.                                           FILRUN    267
       ENDIF                                                            FILRUN    268
C                               Successfully opened all required files  FILRUN    269
       IF (LCASE) THEN                                                  FILRUN    270
         WRITE (LOUT, 9000)                                             FILRUN    271
     +         FILNAM(1:I1)//'msg', IU16, FILNAM(1:I1)//'prg', IU6,     FILRUN    272
     +         FILNAM(1:LO), IU8                                        FILRUN    273
       ELSE                                                             FILRUN    274
         WRITE (LOUT, 9000)                                             FILRUN    275
     +         FILNAM(1:I1)//'MSG', IU16, FILNAM(1:I1)//'PRG', IU6,     FILRUN    276
     +         FILNAM(1:LO), IU8                                        FILRUN    277
       ENDIF                                                            FILRUN    278
       GOTO 2150                                                        FILRUN    279
C---------------------------------------------------------------------  FILRUN    280
C                               Improper specification of result files  FILRUN    281
C                                                                       FILRUN    282
 2000  WRITE (LOUT, '(/, A, /)')                                        FILRUN    283
     +       ' *** ERROR - IMPROPER SPECIFICATION OF RESULT FILES'      FILRUN    284
       IEBK = 1                                                         FILRUN    285
       GOTO 8900                                                        FILRUN    286
C---------------------------------------------------------------------  FILRUN    287
C                                                       Invalid syntax  FILRUN    288
C                                                                       FILRUN    289
 2100  IOS = 0                                                          FILRUN    290
       IEBK = 1                                                         FILRUN    291
       WRITE (MSG(1), 9100)                                             FILRUN    292
       WRITE (MSG(2), 9200)                                             FILRUN    293
       MSG(3) = ' ' // CARD(1:79)                                       FILRUN    294
       CALL PRTMSG(3)                                                   FILRUN    295
C---------------------------------------------------------------------  FILRUN    296
C                                   Get a line of data and the keyword  FILRUN    297
 2150  CALL GETLIN (IUFRUN, CARD)                                       FILRUN    298
C                                                                       FILRUN    299
       I1 = INDEX (CARD, '[')                                           FILRUN    300
       IF (I1 .EQ. 0) GOTO 2300                                         FILRUN    301
       I2 = INDEX (CARD, ']')                                           FILRUN    302
C                                                                       FILRUN    303
       IF (I2 .LT. I1+4) THEN                                           FILRUN    304
         KEY1 = 0                                                       FILRUN    305
         GOTO 2100                                                      FILRUN    306
       ENDIF                                                            FILRUN    307
C                                                                       FILRUN    308
       IF (I2 .GT. I1+11) I2 = I1 + 11                                  FILRUN    309
       KWORD = CARD(I1+1:I2-1)                                          FILRUN    310
C                                                                       FILRUN    311
C                   Special keywords are: SIMULATE and END              FILRUN    312
C                                                                       FILRUN    313
       IF (KWORD(1:3) .EQ. 'END') GOTO 5000                             FILRUN    314
C                                                                       FILRUN    315
       IF (KWORD(1:3) .EQ. 'SIM') THEN                                  FILRUN    316
         SIMLAT = .TRUE.                                                FILRUN    317
         KEY1 = 0                                                       FILRUN    318
         GOTO 2150                                                      FILRUN    319
       ENDIF                                                            FILRUN    320
C                                                                       FILRUN    321
       DO 2200 II = 1, 12                                               FILRUN    322
         IF (KWORD(1:3) .EQ. KYWRD1(II)(1:3)) THEN                      FILRUN    323
           KEY1 = II                                                    FILRUN    324
C                                                                       FILRUN    325
           IF (KEY1 .EQ. 8) THEN                                        FILRUN    326
             IK = INDEX (KWORD, 'DATA')                                 FILRUN    327
             IF (IK .EQ. 0) KEY1 = 9                                    FILRUN    328
           ENDIF                                                        FILRUN    329
C                                                                       FILRUN    330
           IF (KEY1 .EQ. 11) INITIL = .TRUE.                            FILRUN    331
C                                                            Next line  FILRUN    332
           GOTO 2150                                                    FILRUN    333
         ENDIF                                                          FILRUN    334
 2200  CONTINUE                                                         FILRUN    335
C                                                                       FILRUN    336
       KEY1 = 0                                                         FILRUN    337
       GOTO 2100                                                        FILRUN    338
C---------------------------------------------------------------------  FILRUN    339
C                                                                       FILRUN    340
 2300  IF (KEY1 .EQ. 0) THEN                                            FILRUN    341
         IEBK = 1                                                       FILRUN    342
         WRITE (MSG(1), 9100)                                           FILRUN    343
         WRITE (MSG(2), 9300)                                           FILRUN    344
         MSG(3) = ' ' // CARD(1:79)                                     FILRUN    345
         CALL PRTMSG(3)                                                 FILRUN    346
C---------------------------------------------------------------------  FILRUN    347
C                                   Read in program control parameters  FILRUN    348
C                                                                       FILRUN    349
       ELSE IF (KEY1 .EQ. 1) THEN                                       FILRUN    350
C                                                                       FILRUN    351
         I1 = IFNBLK (CARD, 79)                                         FILRUN    352
         IF (I1 .EQ. 0) GOTO 2100                                       FILRUN    353
C                                                                       FILRUN    354
         I2 = IFBLK (CARD(I1+1:80), 80-I1-1)                            FILRUN    355
         IF (I2 .EQ. 0 .OR. I2 .LT. 6) GOTO 2100                        FILRUN    356
C                                                                       FILRUN    357
         KWORD = CARD(I1:I1+5)                                          FILRUN    358
C                                                                       FILRUN    359
         DO 2400 II = 1, 13                                             FILRUN    360
           IF (KWORD(1:6) .EQ. KYWRD2(II)(1:6)) THEN                    FILRUN    361
             KEY2 = II                                                  FILRUN    362
             GOTO 2500                                                  FILRUN    363
           ENDIF                                                        FILRUN    364
 2400    CONTINUE                                                       FILRUN    365
C                                                                       FILRUN    366
         GOTO 2100                                                      FILRUN    367
C                                                                       FILRUN    368
 2500    IK = INDEX (CARD, '=')                                         FILRUN    369
         IF ((IK .EQ. 0) .AND.                                          FILRUN    370
     +       (KEY2 .EQ. 1 .OR. KEY2 .GT. 7)) GOTO 2100                  FILRUN    371
         STRING = CARD(IK+1:80)                                         FILRUN    372
C                                                                       FILRUN    373
         IF (KEY2 .EQ. 1) THEN                                          FILRUN    374
C                                                                       FILRUN    375
           CALL FSTLST (STRING, 80, IFCHR, ILCHR)                       FILRUN    376
           IF (IFCHR .NE. 0) THEN                                       FILRUN    377
             IF ((ILCHR-IFCHR+1) .GT. 12) GOTO 2100                     FILRUN    378
             CASEID = STRING(IFCHR:ILCHR)                               FILRUN    379
           ELSE                                                         FILRUN    380
             CASEID = BLNK12                                            FILRUN    381
           ENDIF                                                        FILRUN    382
C                                                                       FILRUN    383
         ELSE IF (KEY2 .LE. 7) THEN                                     FILRUN    384
C                                                                Title  FILRUN    385
           CALL GETLIN (IUFRUN, STRING)                                 FILRUN    386
           TITLE(KEY2-1) = STRING                                       FILRUN    387
C                                                                       FILRUN    388
         ELSE IF (KEY2 .EQ. 8) THEN                                     FILRUN    389
C                                                                       FILRUN    390
             IK = INDEX (STRING, 'N')                                   FILRUN    391
             IF (IK .NE. 0) THEN                                        FILRUN    392
               IBGSTA = 1                                               FILRUN    393
             ELSE                                                       FILRUN    394
               IBGSTA = 0                                               FILRUN    395
             ENDIF                                                      FILRUN    396
C                                                                       FILRUN    397
         ELSE IF (KEY2 .EQ. 9) THEN                                     FILRUN    398
C                                               System base quantities  FILRUN    399
           IF (INDEX (CARD(I2:80), 'NET') .NE. 0) THEN                  FILRUN    400
             READ (STRING, *, IOSTAT = IOS) XCMMX                       FILRUN    401
           ELSE IF (INDEX (CARD(I2:80), 'FRQ') .NE. 0) THEN             FILRUN    402
             READ (STRING, *, IOSTAT = IOS) FQBASE                      FILRUN    403
           ELSE IF (INDEX (CARD(I2:80), 'MVA') .NE. 0) THEN             FILRUN    404
             READ (STRING, *, IOSTAT = IOS) BASPC                       FILRUN    405
           ELSE                                                         FILRUN    406
             GOTO 2100                                                  FILRUN    407
           ENDIF                                                        FILRUN    408
C                                                                       FILRUN    409
         ELSE IF (KEY2 .EQ. 10) THEN                                    FILRUN    410
C                                                 Algebraic parameters  FILRUN    411
           IF (INDEX (CARD(I2:80), 'PRF') .NE. 0) THEN                  FILRUN    412
             READ (STRING, *, IOSTAT = IOS) MPRITE                      FILRUN    413
           ELSE IF (INDEX (CARD(I2:80), 'SIM') .NE. 0) THEN             FILRUN    414
             READ (STRING, *, IOSTAT = IOS) MAXIT                       FILRUN    415
           ELSE IF (INDEX (CARD(I2:80), 'VOL') .NE. 0) THEN             FILRUN    416
             READ (STRING, *, IOSTAT = IOS) ERTOL                       FILRUN    417
           ELSE IF (INDEX (CARD(I2:80), 'LOV') .NE. 0) THEN             FILRUN    418
             READ (STRING, *, IOSTAT = IOS) VTHZL                       FILRUN    419
           ELSE IF (INDEX (CARD(I2:80), 'HIV') .NE. 0) THEN             FILRUN    420
             READ (STRING, *, IOSTAT = IOS) VTHZH                       FILRUN    421
           ELSE IF (INDEX (CARD(I2:80), 'ZIL') .NE. 0) THEN             FILRUN    422
             READ (STRING, *, IOSTAT = IOS) ZILTOL                      FILRUN    423
           ELSE IF (INDEX (CARD(I2:80), 'ALG') .NE. 0) THEN             FILRUN    424
             IK = INDEX (STRING, 'ITER')                                FILRUN    425
             IF (IK .NE. 0) THEN                                        FILRUN    426
               NREFUC = 0                                               FILRUN    427
             ELSE                                                       FILRUN    428
               NREFUC = 1                                               FILRUN    429
             ENDIF                                                      FILRUN    430
           ELSE IF (INDEX (CARD(I2:80), 'CHK') .NE. 0) THEN             FILRUN    431
             READ (STRING, *, IOSTAT = IOS) MULTSW                      FILRUN    432
           ELSE                                                         FILRUN    433
             GOTO 2100                                                  FILRUN    434
           ENDIF                                                        FILRUN    435
C                                                                       FILRUN    436
         ELSE IF (KEY2 .EQ. 11) THEN                                    FILRUN    437
C                                               Integration parameters  FILRUN    438
           IF (INDEX (CARD(9:80), 'ITR') .NE. 0) THEN                   FILRUN    439
             READ (STRING, *, IOSTAT = IOS) MAXNIT                      FILRUN    440
           ELSE IF (INDEX (CARD(9:80), 'JAC') .NE. 0) THEN              FILRUN    441
             READ (STRING, *, IOSTAT = IOS) IJMCT                       FILRUN    442
           ELSE IF (INDEX (CARD(9:80), 'TOL') .NE. 0) THEN              FILRUN    443
             READ (STRING, *, IOSTAT = IOS) RESTOL                      FILRUN    444
           ELSE IF (INDEX (CARD(9:80), 'THR') .NE. 0) THEN              FILRUN    445
             READ (STRING, *, IOSTAT = IOS) TVAPDC                      FILRUN    446
           ELSE IF (INDEX (CARD(9:80), 'SST') .NE. 0) THEN              FILRUN    447
             READ (STRING, *, IOSTAT = IOS) DTMIN                       FILRUN    448
           ELSE                                                         FILRUN    449
             GOTO 2100                                                  FILRUN    450
           ENDIF                                                        FILRUN    451
C                                                                       FILRUN    452
         ELSE IF (KEY2 .EQ. 12) THEN                                    FILRUN    453
C                                  Data and stability check parameters  FILRUN    454
           IF (INDEX (CARD(I2:80), 'SDR') .NE. 0) THEN                  FILRUN    455
             READ (STRING, *, IOSTAT = IOS) ZDTOL                       FILRUN    456
           ELSE IF (INDEX (CARD(I2:80), 'GLO') .NE. 0) THEN             FILRUN    457
             READ (STRING, *, IOSTAT = IOS) GVTMIN                      FILRUN    458
           ELSE IF (INDEX (CARD(I2:80), 'GHI') .NE. 0) THEN             FILRUN    459
             READ (STRING, *, IOSTAT = IOS) GVTMAX                      FILRUN    460
           ELSE IF (INDEX (CARD(I2:80), 'BLO') .NE. 0) THEN             FILRUN    461
             READ (STRING, *, IOSTAT = IOS) BUVMIN                      FILRUN    462
           ELSE IF (INDEX (CARD(I2:80), 'BHI') .NE. 0) THEN             FILRUN    463
             READ (STRING, *, IOSTAT = IOS) BUVMAX                      FILRUN    464
           ELSE IF (INDEX (CARD(I2:80), 'GEN') .NE. 0) THEN             FILRUN    465
             READ (STRING, *, IOSTAT = IOS) XMAXSD                      FILRUN    466
           ELSE IF (INDEX (CARD(I2:80), 'MIN') .NE. 0) THEN             FILRUN    467
             READ (STRING, *, IOSTAT = IOS) TMIN                        FILRUN    468
           ELSE IF (INDEX (CARD(I2:80), 'AUT') .NE. 0) THEN             FILRUN    469
             IF (INDEX (STRING, 'Y') .NE. 0) THEN                       FILRUN    470
               MTFLAG = 1                                               FILRUN    471
             ELSE                                                       FILRUN    472
               MTFLAG = 0                                               FILRUN    473
             ENDIF                                                      FILRUN    474
           ELSE                                                         FILRUN    475
             GOTO 2100                                                  FILRUN    476
           ENDIF                                                        FILRUN    477
C                                                                       FILRUN    478
         ELSE                                                           FILRUN    479
C                                    Reference generator specification  FILRUN    480
           REFGEN = STRING                                              FILRUN    481
C                                                                       FILRUN    482
         ENDIF                                                          FILRUN    483
C                                                    Error during read  FILRUN    484
         IF (IOS .NE. 0) GOTO 2100                                      FILRUN    485
C---------------------------------------------------------------------  FILRUN    486
C                                     Read in Load Flow specifications  FILRUN    487
C                                                                       FILRUN    488
       ELSE IF (KEY1 .EQ. 2) THEN                                       FILRUN    489
C                                                                       FILRUN    490
         I1 = IFNBLK (CARD, 79)                                         FILRUN    491
         IF (I1 .EQ. 0 .OR. I1 .GT. 77) GOTO 2100                       FILRUN    492
C                                                                       FILRUN    493
         KWORD = CARD(I1:I1+2)                                          FILRUN    494
C                                                                       FILRUN    495
         IK = INDEX (CARD, '=')                                         FILRUN    496
         IF (IK .EQ. 0) GOTO 2100                                       FILRUN    497
         STRING = CARD(IK+1:80)                                         FILRUN    498
C                                                                       FILRUN    499
         IF (KWORD(1:3) .EQ. 'IDE') THEN                                FILRUN    500
C                                                   Load flow identity  FILRUN    501
           CALL FSTLST (STRING, 80, IFCHR, ILCHR)                       FILRUN    502
           IF (IFCHR .NE. 0) THEN                                       FILRUN    503
             IF ((ILCHR-IFCHR+1) .GT. 12) GOTO 2100                     FILRUN    504
             LFID = STRING(IFCHR:ILCHR)                                 FILRUN    505
           ELSE                                                         FILRUN    506
             LFID = BLNK12                                              FILRUN    507
           ENDIF                                                        FILRUN    508
C                                                                       FILRUN    509
         ELSE IF (KWORD(1:3) .EQ. 'NUM') THEN                           FILRUN    510
C                                                     Load flow number  FILRUN    511
           READ (STRING, *, IOSTAT = IOS) LFNUMB                        FILRUN    512
C                                                                       FILRUN    513
         ELSE IF (KWORD(1:3) .EQ. 'REC') THEN                           FILRUN    514
C                                                     Load flow record  FILRUN    515
           READ (STRING, *, IOSTAT = IOS) LFREC                         FILRUN    516
C                                                                       FILRUN    517
         ELSE IF (KWORD(1:3) .EQ. 'INP') THEN                           FILRUN    518
C                                                       Load flow file  FILRUN    519
           CALL FSTLST (STRING, 80, IFCHR, ILCHR)                       FILRUN    520
           IF (IFCHR .NE. 0) THEN                                       FILRUN    521
             IF ((ILCHR-IFCHR+1) .GT. 50) GOTO 2100                     FILRUN    522
             LFDAFN = STRING(IFCHR:ILCHR)                               FILRUN    523
           ELSE                                                         FILRUN    524
             LFDAFN = BLNK50                                            FILRUN    525
           ENDIF                                                        FILRUN    526
C                                                                       FILRUN    527
         ELSE IF (KWORD(1:3) .EQ. 'FOR') THEN                           FILRUN    528
C                                                     Load flow format  FILRUN    529
           CALL FSTLST (STRING, 80, IFCHR, ILCHR)                       FILRUN    530
           IF (IFCHR .NE. 0) THEN                                       FILRUN    531
             IF ((ILCHR-IFCHR+1) .GT. 20) GOTO 2100                     FILRUN    532
             LFFRMT = STRING(IFCHR:ILCHR)                               FILRUN    533
           ELSE                                                         FILRUN    534
             LFFRMT = BLNK20                                            FILRUN    535
           ENDIF                                                        FILRUN    536
C                                                                       FILRUN    537
         ELSE                                                           FILRUN    538
           GOTO 2100                                                    FILRUN    539
         ENDIF                                                          FILRUN    540
C                                                    Error during read  FILRUN    541
         IF (IOS .NE. 0) GOTO 2100                                      FILRUN    542
C---------------------------------------------------------------------  FILRUN    543
C                                       Read in Dynamic data file name  FILRUN    544
C                                                                       FILRUN    545
       ELSE IF (KEY1 .EQ. 3) THEN                                       FILRUN    546
C                                                                       FILRUN    547
         I1 = IFNBLK (CARD, 79)                                         FILRUN    548
         IF (I1 .EQ. 0 .OR. I1 .GT. 77) THEN                            FILRUN    549
           KWORD = 'DAT'                                                FILRUN    550
         ELSE                                                           FILRUN    551
           KWORD = CARD(I1:I1+2)                                        FILRUN    552
         ENDIF                                                          FILRUN    553
C                                                                       FILRUN    554
         IK = INDEX (CARD, '=')                                         FILRUN    555
         IF (KWORD(1:3) .EQ. 'INP' .OR.                                 FILRUN    556
     +       KWORD(1:3) .EQ. 'BSV' .OR.                                 FILRUN    557
     +       KWORD(1:3) .EQ. 'ESV') THEN                                FILRUN    558
           IF (IK .EQ. 0) GOTO 2100                                     FILRUN    559
           STRING = CARD(IK+1:80)                                       FILRUN    560
         ELSE                                                           FILRUN    561
           KWORD = 'DAT'                                                FILRUN    562
         ENDIF                                                          FILRUN    563
C                                                                       FILRUN    564
         IF (KWORD(1:3) .EQ. 'INP') THEN                                FILRUN    565
C                                         Input dynamic data file name  FILRUN    566
           CALL FSTLST (STRING, 80, IFCHR, ILCHR)                       FILRUN    567
           IF (IFCHR .NE. 0) THEN                                       FILRUN    568
             IF ((ILCHR-IFCHR+1) .GT. 50) GOTO 2100                     FILRUN    569
             INDYFN = STRING(IFCHR:ILCHR)                               FILRUN    570
           ELSE                                                         FILRUN    571
             INDYFN = BLNK50                                            FILRUN    572
           ENDIF                                                        FILRUN    573
C                                           Open the dynamic data file  FILRUN    574
           STRING = INDYFN                                              FILRUN    575
           IK = IFNBLK (STRING, 49)                                     FILRUN    576
           INDYFN = STRING(IK:50)                                       FILRUN    577
           CALL PARSIU (INDYFN, LEN, IU, LO)                            FILRUN    578
           IF (IU .LT. 0) GOTO 8700                                     FILRUN    579
           IF (IU .GT. 0) THEN                                          FILRUN    580
             STRING = INDYFN(1:LO)                                      FILRUN    581
             INDYFN = STRING(1:LO)                                      FILRUN    582
             IU61 = IU                                                  FILRUN    583
             CALL FBOKEP (IU61, IBACK)                                  FILRUN    584
             IF (IBACK .LT. 0) GOTO 8700                                FILRUN    585
           ENDIF                                                        FILRUN    586
           IKEY = 8                                                     FILRUN    587
           LO = INDEX (INDYFN, ' ')                                     FILRUN    588
           JLENG = 0                                                    FILRUN    589
           CALL OPENRE (IU61, INDYFN, JLENG, IKEY, ISTAT, LO)           FILRUN    590
           IF (ISTAT .NE. 0) GOTO 8700                                  FILRUN    591
           LUNITS(IU61) = .TRUE.                                        FILRUN    592
C                Transfer dynamic data from the specified file to IU50  FILRUN    593
 2600      READ (IU61, '(A80)', IOSTAT = IOS) STRING                    FILRUN    594
           IF (STRING(1:5) .NE. '  END' .AND.                           FILRUN    595
     +         IOS .GE. 0) THEN                                         FILRUN    596
             WRITE (IU50, '(A80)') STRING                               FILRUN    597
             DYDFLG = .TRUE.                                            FILRUN    598
             GOTO 2600                                                  FILRUN    599
           ENDIF                                                        FILRUN    600
           IOS = 0                                                      FILRUN    601
           CALL CLOSEF (IU61)                                           FILRUN    602
C                                                                       FILRUN    603
         ELSE IF (KWORD(1:3) .EQ. 'ESV' .OR.                            FILRUN    604
     +            KWORD(1:3) .EQ. 'BSV') THEN                           FILRUN    605
C                                      Modified dynamic data file name  FILRUN    606
           CALL FSTLST (STRING, 80, IFCHR, ILCHR)                       FILRUN    607
           IF (IFCHR .NE. 0) THEN                                       FILRUN    608
             IF ((ILCHR-IFCHR+1) .GT. 50) GOTO 2100                     FILRUN    609
             SVDYFN = STRING(IFCHR:ILCHR)                               FILRUN    610
           ELSE                                                         FILRUN    611
             SVDYFN = BLNK50                                            FILRUN    612
           ENDIF                                                        FILRUN    613
C                                                                       FILRUN    614
           IF(KWORD(1:3) .EQ. 'BSV') THEN                               FILRUN    615
C                                              Write out in BPA format  FILRUN    616
             IBPAFL = 1                                                 FILRUN    617
           ELSE                                                         FILRUN    618
C                                             Write out in EPRI format  FILRUN    619
             IBPAFL = 2                                                 FILRUN    620
           ENDIF                                                        FILRUN    621
         ELSE                                                           FILRUN    622
C                                  Write the dynamic data card to IU50  FILRUN    623
           IF (CARD(1:5) .NE. '  END') THEN                             FILRUN    624
             WRITE (IU50, '(A80)') CARD                                 FILRUN    625
             DYDFLG = .TRUE.                                            FILRUN    626
           ENDIF                                                        FILRUN    627
         ENDIF                                                          FILRUN    628
C---------------------------------------------------------------------  FILRUN    629
C                               Read dynamic data modifications in BPA  FILRUN    630
C                                        and store in the scratch file  FILRUN    631
C                                                                       FILRUN    632
       ELSE IF (KEY1 .EQ. 4) THEN                                       FILRUN    633
C                                                                       FILRUN    634
         IPTR = IBPADY                                                  FILRUN    635
         GOTO 4800                                                      FILRUN    636
C---------------------------------------------------------------------  FILRUN    637
C                                              Read in Relay data file  FILRUN    638
C                                                                       FILRUN    639
       ELSE IF (KEY1 .EQ. 5) THEN                                       FILRUN    640
C                                                                       FILRUN    641
         I1 = IFNBLK (CARD, 79)                                         FILRUN    642
         IF (I1 .EQ. 0 .OR. I1 .GT. 77) THEN                            FILRUN    643
           KWORD = 'DAT'                                                FILRUN    644
         ELSE                                                           FILRUN    645
           KWORD = CARD(I1:I1+2)                                        FILRUN    646
         ENDIF                                                          FILRUN    647
C                                                                       FILRUN    648
         IK = INDEX (CARD, '=')                                         FILRUN    649
         IF (KWORD(1:3) .EQ. 'INP') THEN                                FILRUN    650
           IF (IK .EQ. 0) GOTO 2100                                     FILRUN    651
           STRING = CARD(IK+1:80)                                       FILRUN    652
         ELSE                                                           FILRUN    653
           KWORD = 'DAT'                                                FILRUN    654
         ENDIF                                                          FILRUN    655
C                                                                       FILRUN    656
         IF(KWORD(1:3) .EQ. 'INP') THEN                                 FILRUN    657
C                                           Input relay data file name  FILRUN    658
           CALL FSTLST (STRING, 80, IFCHR, ILCHR)                       FILRUN    659
           IF (IFCHR .NE. 0) THEN                                       FILRUN    660
             IF ((ILCHR-IFCHR+1) .GT. 50) GOTO 2100                     FILRUN    661
             RLDAFN = STRING(IFCHR:ILCHR)                               FILRUN    662
           ELSE                                                         FILRUN    663
             RLDAFN = BLNK50                                            FILRUN    664
           ENDIF                                                        FILRUN    665
C                                             Open the relay data file  FILRUN    666
C                                             Open the relay data file  FILRUN    667
           STRING = RLDAFN                                              FILRUN    668
           IK = IFNBLK (STRING, 49)                                     FILRUN    669
           RLDAFN = STRING(IK:50)                                       FILRUN    670
           CALL PARSIU (RLDAFN, LEN, IU, LO)                            FILRUN    671
           IF (IU .LT. 0) GOTO 8800                                     FILRUN    672
           IF (IU .GT. 0) THEN                                          FILRUN    673
             STRING = RLDAFN(1:LO)                                      FILRUN    674
             RLDAFN = STRING(1:LO)                                      FILRUN    675
             IU61 = IU                                                  FILRUN    676
             CALL FBOKEP (IU61, IBACK)                                  FILRUN    677
             IF (IBACK .LT. 0) GOTO 8800                                FILRUN    678
           ENDIF                                                        FILRUN    679
           IKEY = 8                                                     FILRUN    680
           LO = INDEX (RLDAFN, ' ')                                     FILRUN    681
           JLENG = 0                                                    FILRUN    682
           CALL OPENRE (IU61, RLDAFN, JLENG, IKEY, ISTAT, LO)           FILRUN    683
           IF (ISTAT .NE. 0) GOTO 8800                                  FILRUN    684
           LUNITS(IU61) = .TRUE.                                        FILRUN    685
C                  Transfer relay data from the specified file to IU54  FILRUN    686
 2700      READ (IU61, '(A80)', IOSTAT = IOS) STRING                    FILRUN    687
           IF (STRING(1:5) .NE. '  END' .AND.                           FILRUN    688
     +         IOS .GE. 0) THEN                                         FILRUN    689
             WRITE (IU54, '(A80)') STRING                               FILRUN    690
             RLDFLG = .TRUE.                                            FILRUN    691
             GOTO 2700                                                  FILRUN    692
           ENDIF                                                        FILRUN    693
           IOS = 0                                                      FILRUN    694
           CALL CLOSEF (IU61)                                           FILRUN    695
C                                                                       FILRUN    696
         ELSE                                                           FILRUN    697
C                                    Write the relay data card to IU54  FILRUN    698
           IF (CARD(1:5) .NE. '  END') THEN                             FILRUN    699
             WRITE (IU54, '(A80)') CARD                                 FILRUN    700
             RLDFLG = .TRUE.                                            FILRUN    701
           ENDIF                                                        FILRUN    702
         ENDIF                                                          FILRUN    703
C---------------------------------------------------------------------  FILRUN    704
C                                    Read in Output specification file  FILRUN    705
C                                                                       FILRUN    706
       ELSE IF (KEY1 .EQ. 6) THEN                                       FILRUN    707
C                                                                       FILRUN    708
         I1 = IFNBLK (CARD, 79)                                         FILRUN    709
         IF (I1 .EQ. 0 .OR. I1 .GT. 77) GOTO 2100                       FILRUN    710
C                                                                       FILRUN    711
         KWORD = CARD(I1:I1+2)                                          FILRUN    712
C                                                                       FILRUN    713
         IF (KWORD(1:3) .EQ. 'INP') THEN                                FILRUN    714
C                                                            File name  FILRUN    715
           IK = INDEX (CARD, '=')                                       FILRUN    716
           IF (IK .EQ. 0) GOTO 2100                                     FILRUN    717
           STRING = CARD(IK+1:80)                                       FILRUN    718
C                                                                       FILRUN    719
           CALL FSTLST (STRING, 80, IFCHR, ILCHR)                       FILRUN    720
           IF (IFCHR .NE. 0) THEN                                       FILRUN    721
             IF ((ILCHR-IFCHR+1) .GT. 50) GOTO 2100                     FILRUN    722
             OUTSFN = STRING(IFCHR:ILCHR)                               FILRUN    723
           ELSE                                                         FILRUN    724
             OUTSFN = BLNK50                                            FILRUN    725
           ENDIF                                                        FILRUN    726
C                                                                       FILRUN    727
         ELSE                                                           FILRUN    728
C                                                                Specs  FILRUN    729
           IPTR = IOUTPT                                                FILRUN    730
           GOTO 4800                                                    FILRUN    731
C                                                                       FILRUN    732
         ENDIF                                                          FILRUN    733
C---------------------------------------------------------------------  FILRUN    734
C                                    Read in Simulation specifications  FILRUN    735
C                                                                       FILRUN    736
       ELSE IF (KEY1 .EQ. 7) THEN                                       FILRUN    737
C                                                                       FILRUN    738
         I1 = IFNBLK (CARD, 79)                                         FILRUN    739
         IF (I1 .EQ. 0 .OR. I1 .GT. 77) GOTO 2100                       FILRUN    740
C                                                                       FILRUN    741
         KWORD = CARD(I1:I1+2)                                          FILRUN    742
C                                                                       FILRUN    743
         IF (KWORD(1:3) .EQ. 'INP') THEN                                FILRUN    744
C                                                       Switching file  FILRUN    745
           IK = INDEX (CARD, '=')                                       FILRUN    746
           IF (IK .EQ. 0) GOTO 2100                                     FILRUN    747
           STRING = CARD(IK+1:80)                                       FILRUN    748
C                                                                       FILRUN    749
           CALL FSTLST (STRING, 80, IFCHR, ILCHR)                       FILRUN    750
           IF (IFCHR .NE. 0) THEN                                       FILRUN    751
             IF ((ILCHR-IFCHR+1) .GT. 50) GOTO 2100                     FILRUN    752
             SWFLNM = STRING(IFCHR:ILCHR)                               FILRUN    753
           ELSE                                                         FILRUN    754
             SWFLNM = BLNK50                                            FILRUN    755
           ENDIF                                                        FILRUN    756
C                                                                       FILRUN    757
         ELSE IF (KWORD(1:3) .EQ. 'PRI' .AND.                           FILRUN    758
     +            INDEX (CARD, 'SUM') .NE. 0) THEN                      FILRUN    759
C                            Print summary of simulation specification  FILRUN    760
           ISWSM = 1                                                    FILRUN    761
           IK = INDEX (CARD, '=')                                       FILRUN    762
           IF (IK .EQ. 0) GOTO 2150                                     FILRUN    763
           STRING = CARD(IK+1:80)                                       FILRUN    764
           IF (TASWFN .EQ. BLNK50) THEN                                 FILRUN    765
C                                                                       FILRUN    766
             CALL FSTLST (STRING, 80, IFCHR, ILCHR)                     FILRUN    767
             IF (IFCHR .NE. 0) THEN                                     FILRUN    768
               IF ((ILCHR-IFCHR+1) .GT. 50) GOTO 2100                   FILRUN    769
               TASWFN = STRING(IFCHR:ILCHR)                             FILRUN    770
             ELSE                                                       FILRUN    771
               TASWFN = BLNK50                                          FILRUN    772
             ENDIF                                                      FILRUN    773
C                                                                       FILRUN    774
           ENDIF                                                        FILRUN    775
C                                                                       FILRUN    776
         ELSE                                                           FILRUN    777
           IPTR = ISWITC                                                FILRUN    778
           GOTO 4800                                                    FILRUN    779
         ENDIF                                                          FILRUN    780
C                                                    Error during read  FILRUN    781
         IF (IOS .NE. 0) GOTO 2100                                      FILRUN    782
C---------------------------------------------------------------------  FILRUN    783
C                           Read Tabulation specs for the dynamic data  FILRUN    784
C                                                                       FILRUN    785
       ELSE IF (KEY1 .EQ. 8 .OR. KEY1 .EQ. 9) THEN                      FILRUN    786
C                                                                       FILRUN    787
         I1 = IFNBLK (CARD, 79)                                         FILRUN    788
         IF (I1 .EQ. 0 .OR. I1 .GT. 77) GOTO 2100                       FILRUN    789
C                                                                       FILRUN    790
         KWORD = CARD(I1:I1+2)                                          FILRUN    791
C                                                                       FILRUN    792
         IF (KWORD(1:3) .EQ. 'OUT') THEN                                FILRUN    793
C                                                            File name  FILRUN    794
           IK = INDEX (CARD, '=')                                       FILRUN    795
           IF (IK .EQ. 0) GOTO 2100                                     FILRUN    796
           STRING = CARD(IK+1:80)                                       FILRUN    797
           IF (TASWFN .EQ. BLNK50) THEN                                 FILRUN    798
C                                                                       FILRUN    799
             CALL FSTLST (STRING, 80, IFCHR, ILCHR)                     FILRUN    800
             IF (IFCHR .NE. 0) THEN                                     FILRUN    801
               IF ((ILCHR-IFCHR+1) .GT. 50) GOTO 2100                   FILRUN    802
               TASWFN = STRING(IFCHR:ILCHR)                             FILRUN    803
             ELSE                                                       FILRUN    804
               TASWFN = BLNK50                                          FILRUN    805
             ENDIF                                                      FILRUN    806
C                                                                       FILRUN    807
           ENDIF                                                        FILRUN    808
C                                                                       FILRUN    809
         ELSE                                                           FILRUN    810
C                                                                Specs  FILRUN    811
           IK = IFNBLK (CARD, 79)                                       FILRUN    812
           STRING = CARD(IK:80)                                         FILRUN    813
           CARD = STRING                                                FILRUN    814
           IF (KEY1 .EQ. 8) THEN                                        FILRUN    815
             IPTR = ITABDA                                              FILRUN    816
           ELSE                                                         FILRUN    817
             IPTR = ITABIC                                              FILRUN    818
           ENDIF                                                        FILRUN    819
           GOTO 4800                                                    FILRUN    820
C                                                                       FILRUN    821
         ENDIF                                                          FILRUN    822
C---------------------------------------------------------------------  FILRUN    823
C                                                             Analysis  FILRUN    824
C                                                                       FILRUN    825
       ELSE IF (KEY1 .EQ. 10) THEN                                      FILRUN    826
C                                                                       FILRUN    827
         GOTO 2150                                                      FILRUN    828
C                                                                       FILRUN    829
C---------------------------------------------------------------------  FILRUN    830
C                                                       Initialization  FILRUN    831
C                                                                       FILRUN    832
       ELSE IF (KEY1 .EQ. 11) THEN                                      FILRUN    833
C                                                                       FILRUN    834
         I1 = IFNBLK (CARD, 79)                                         FILRUN    835
         IF (I1 .EQ. 0 .OR. I1 .GT. 77) GOTO 2100                       FILRUN    836
C                                                                       FILRUN    837
         KWORD = CARD(I1:I1+2)                                          FILRUN    838
C                                                                       FILRUN    839
         IF  (KWORD(1:3) .EQ. 'OUT') THEN                               FILRUN    840
C                                                          Result file  FILRUN    841
           IK = INDEX (CARD, '=')                                       FILRUN    842
           IF (IK .EQ. 0) GOTO 2100                                     FILRUN    843
           STRING = CARD(IK+1:80)                                       FILRUN    844
C                                                                       FILRUN    845
             CALL FSTLST (STRING, 80, IFCHR, ILCHR)                     FILRUN    846
             IF (IFCHR .NE. 0) THEN                                     FILRUN    847
               IF ((ILCHR-IFCHR+1) .GT. 50) GOTO 2100                   FILRUN    848
               RESLFN = STRING(IFCHR:ILCHR)                             FILRUN    849
             ELSE                                                       FILRUN    850
               RESLFN = BLNK50                                          FILRUN    851
             ENDIF                                                      FILRUN    852
C                                                                       FILRUN    853
         ELSE                                                           FILRUN    854
C                                                                       FILRUN    855
           GOTO 2100                                                    FILRUN    856
C                                                                       FILRUN    857
         ENDIF                                                          FILRUN    858
C                                                    Error during read  FILRUN    859
         IF (IOS .NE. 0) GOTO 2100                                      FILRUN    860
C---------------------------------------------------------------------  FILRUN    861
C                                               Write out dynamic data  FILRUN    862
C                                                                       FILRUN    863
       ELSE IF (KEY1 .EQ. 12) THEN                                      FILRUN    864
C                                                                       FILRUN    865
         I1 = IFNBLK (CARD, 79)                                         FILRUN    866
         IF (I1 .EQ. 0 .OR. I1 .GT. 77) GOTO 2100                       FILRUN    867
C                                                                       FILRUN    868
         KWORD = CARD(I1:I1+2)                                          FILRUN    869
C                                                                       FILRUN    870
         IF  (KWORD(1:3) .EQ. 'OUT') THEN                               FILRUN    871
C                                             Dynamic data output file  FILRUN    872
           IK = INDEX (CARD, '=')                                       FILRUN    873
           IF (IK .EQ. 0) GOTO 2100                                     FILRUN    874
           STRING = CARD(IK+1:80)                                       FILRUN    875
C                                                                       FILRUN    876
           CALL FSTLST (STRING, 80, IFCHR, ILCHR)                       FILRUN    877
           IF (IFCHR .NE. 0) THEN                                       FILRUN    878
             IF ((ILCHR-IFCHR+1) .GT. 50) GOTO 2100                     FILRUN    879
             DYDAFN = STRING(IFCHR:ILCHR)                               FILRUN    880
           ELSE                                                         FILRUN    881
             DYDAFN = BLNK50                                            FILRUN    882
           ENDIF                                                        FILRUN    883
C                                                                       FILRUN    884
         ELSE                                                           FILRUN    885
C                                                                       FILRUN    886
           GOTO 2100                                                    FILRUN    887
C                                                                       FILRUN    888
         ENDIF                                                          FILRUN    889
C                                                    Error during read  FILRUN    890
         IF (IOS .NE. 0) GOTO 2100                                      FILRUN    891
C                                                                       FILRUN    892
       ENDIF                                                            FILRUN    893
C---------------------------------------------------------------------  FILRUN    894
C                                                            Next line  FILRUN    895
C                                                                       FILRUN    896
       GOTO 2150                                                        FILRUN    897
C---------------------------------------------------------------------  FILRUN    898
C                      Store control file data in the scratch file and  FILRUN    899
C                                   update the first and next pointers  FILRUN    900
C                                                                       FILRUN    901
4800   JREC = JREC + 1                                                  FILRUN    902
       WRITE (IU56, REC = JREC) CARD                                    FILRUN    903
       IF (IFSPTR(IPTR) .EQ. 0) THEN                                    FILRUN    904
         IFSPTR(IPTR) = JREC                                            FILRUN    905
       ELSE                                                             FILRUN    906
         INXT = IFSPTR(IPTR)                                            FILRUN    907
 4900    IF (INXPTR(INXT) .NE. 0) THEN                                  FILRUN    908
           INXT = INXPTR(INXT)                                          FILRUN    909
           GOTO 4900                                                    FILRUN    910
         ELSE                                                           FILRUN    911
           INXPTR(INXT) = JREC                                          FILRUN    912
         ENDIF                                                          FILRUN    913
       ENDIF                                                            FILRUN    914
C                                                            Next line  FILRUN    915
       GOTO 2150                                                        FILRUN    916
C---------------------------------------------------------------------  FILRUN    917
C                                      End of reading the control file  FILRUN    918
C                                                                       FILRUN    919
 5000  IF (IEBK .NE. 0) GOTO 8900                                       FILRUN    920
C---------------------------------------------------------------------  FILRUN    921
C                                                  Read Load Flow data  FILRUN    922
C                                                                       FILRUN    923
       STRING = LFDAFN                                                  FILRUN    924
       IK = IFNBLK (STRING, 49)                                         FILRUN    925
       IF (IK .EQ. 0) THEN                                              FILRUN    926
         IEBK = 1                                                       FILRUN    927
         MSG(1) = ' *** ERROR - LOAD FLOW FILE NOT SPECIFIED.'          FILRUN    928
         CALL PRTMSG(1)                                                 FILRUN    929
         GOTO 8900                                                      FILRUN    930
       ELSE                                                             FILRUN    931
         LFDAFN = STRING(IK:50)                                         FILRUN    932
       ENDIF                                                            FILRUN    933
C                                                                       FILRUN    934
       IF (INDEX (LFFRMT, 'PTI') .NE. 0) THEN                           FILRUN    935
         LDUMP = 0                                                      FILRUN    936
         IF (INDEX (LFFRMT, 'V16') .NE. 0) LDUMP = 19                   FILRUN    937
       ELSE IF (INDEX (LFFRMT, 'ETM') .NE. 0) THEN                      FILRUN    938
         LDUMP = 2                                                      FILRUN    939
       ELSE IF (INDEX (LFFRMT, 'IEE') .NE. 0) THEN                      FILRUN    940
         LDUMP = 3                                                      FILRUN    941
         IF (INDEX (LFFRMT, 'NAM') .NE. 0) LDUMP = 4                    FILRUN    942
       ELSE IF (INDEX (LFFRMT, 'EPR') .NE. 0) THEN                      FILRUN    943
         LDUMP = 5                                                      FILRUN    944
       ELSE IF (INDEX (LFFRMT, 'WSC') .NE. 0) THEN                      FILRUN    945
         LDUMP = 7                                                      FILRUN    946
       ELSE IF (INDEX (LFFRMT, 'BPA') .NE. 0) THEN                      FILRUN    947
         LDUMP = 8                                                      FILRUN    948
       ELSE IF (INDEX (LFFRMT, 'PSF') .NE. 0) THEN                      FILRUN    949
         LDUMP = 9                                                      FILRUN    950
         IF (INDEX (LFFRMT, 'NAM') .NE. 0) LDUMP = 10                   FILRUN    951
       ELSE IF (INDEX (LFFRMT, 'PEC') .NE. 0) THEN                      FILRUN    952
         IF (INDEX (LFFRMT, 'V5') .NE. 0) THEN                          FILRUN    953
           IF (INDEX (LFFRMT, 'DA') .NE. 0) THEN                        FILRUN    954
             LDUMP = 15                                                 FILRUN    955
             IF (INDEX (LFFRMT, 'NAM') .NE. 0) LDUMP = 16               FILRUN    956
           ELSE                                                         FILRUN    957
             LDUMP = 17                                                 FILRUN    958
             IF (INDEX (LFFRMT, 'NAM') .NE. 0) LDUMP = 18               FILRUN    959
           ENDIF                                                        FILRUN    960
         ELSE                                                           FILRUN    961
           IF (INDEX (LFFRMT, 'DA') .NE. 0) THEN                        FILRUN    962
             LDUMP = 11                                                 FILRUN    963
             IF (INDEX (LFFRMT, 'NAM') .NE. 0) LDUMP = 12               FILRUN    964
           ELSE                                                         FILRUN    965
             LDUMP = 13                                                 FILRUN    966
             IF (INDEX (LFFRMT, 'NAM') .NE. 0) LDUMP = 14               FILRUN    967
           ENDIF                                                        FILRUN    968
         ENDIF                                                          FILRUN    969
       ENDIF                                                            FILRUN    970
C                                                                       FILRUN    971
       LENPAR = 0                                                       FILRUN    972
       NCAS = 0                                                         FILRUN    973
       KDEB = 0                                                         FILRUN    974
       LFEPRI = 0                                                       FILRUN    975
       KLAYER = 0                                                       FILRUN    976
       CALL LOADFL (LFDAFN, LENPAR, LDUMP, NCAS, KDEB, LFEPRI, KLAYER,  FILRUN    977
     +              IEBK)                                               FILRUN    978
       IF (IEBK .NE. 0) GOTO 8900                                       FILRUN    979
C---------------------------------------------------------------------  FILRUN    980
C                                                    Read dynamic data  FILRUN    981
C                                                                       FILRUN    982
       IF (DYDFLG) THEN                                                 FILRUN    983
         WRITE (IU50, '(A5)') '  END'                                   FILRUN    984
         REWIND (IU50)                                                  FILRUN    985
         INDYFN = BLNK50                                                FILRUN    986
       ELSE                                                             FILRUN    987
         IEBK = 1                                                       FILRUN    988
         MSG(1) = ' *** ERROR - DYNAMIC DATA NOT SPECIFIED.'            FILRUN    989
         CALL PRTMSG(1)                                                 FILRUN    990
         GOTO 8900                                                      FILRUN    991
       ENDIF                                                            FILRUN    992
C                                                          Open SAVFIL  FILRUN    993
       IF (IBPAFL .GT. 0 .AND. SVDYFN .NE. BLNK50) THEN                 FILRUN    994
C                        Open a sequential, formatted, new or old file  FILRUN    995
         STRING = SVDYFN                                                FILRUN    996
         IK = IFNBLK (STRING, 49)                                       FILRUN    997
         SVDYFN = STRING(IK:50)                                         FILRUN    998
         CALL PARSIU (SVDYFN, LEN, IU, LO)                              FILRUN    999
         IF (IU .LT. 0) GOTO 5800                                       FILRUN   1000
         IF (IU .GT. 0) THEN                                            FILRUN   1001
           STRING = SVDYFN(1:LO)                                        FILRUN   1002
           SVDYFN = STRING(1:LO)                                        FILRUN   1003
           IU58 = IU                                                    FILRUN   1004
           CALL FBOKEP (IU58, IBACK)                                    FILRUN   1005
           IF (IBACK .LT. 0) GOTO 5800                                  FILRUN   1006
         ENDIF                                                          FILRUN   1007
         IKEY = 10                                                      FILRUN   1008
         LO = INDEX (SVDYFN, ' ')                                       FILRUN   1009
         JLENG = 0                                                      FILRUN   1010
         CALL OPENRE (IU58, SVDYFN, JLENG, IKEY, ISTAT, LO)             FILRUN   1011
         IF (ISTAT .NE. 0) GOTO 5800                                    FILRUN   1012
         LUNITS(IU58) = .TRUE.                                          FILRUN   1013
       ENDIF                                                            FILRUN   1014
C                                                                       FILRUN   1015
       LENPAR = 0                                                       FILRUN   1016
       IUY = 0                                                          FILRUN   1017
       JTLN = 0                                                         FILRUN   1018
       CALL DYNDAT (INDYFN, LENPAR, IUY, KLAYER)                        FILRUN   1019
C                                                  Write dynamic data   FILRUN   1020
       IF (DYDAFN .NE. BLNK50) THEN                                     FILRUN   1021
         STRING = DYDAFN                                                FILRUN   1022
         IK = IFNBLK (STRING, 59)                                       FILRUN   1023
         DYDAFN = STRING(IK:50)                                         FILRUN   1024
         LENPAR = 0                                                     FILRUN   1025
         IUY = 0                                                        FILRUN   1026
         CALL WDYNDA (DYDAFN, LENPAR, IUY, KLAYER)                      FILRUN   1027
       ENDIF                                                            FILRUN   1028
C                                                   Load dynamic data   FILRUN   1029
       CALL LDYNDA (IUY, IEBK)                                          FILRUN   1030
       IF (IEBK .NE. 0) GOTO 8900                                       FILRUN   1031
       GOTO 5900                                                        FILRUN   1032
C                                                                       FILRUN   1033
 5800  MSG(1) = ' *** ERROR OPENING BPA/EPRI DYNAMIC DATA '//           FILRUN   1034
     +          'OUTPUT FILE'                                           FILRUN   1035
       CALL PRTMSG(1)                                                   FILRUN   1036
       IEBK = 1                                                         FILRUN   1037
       GOTO 8900                                                        FILRUN   1038
C---------------------------------------------------------------------  FILRUN   1039
C                                                      Read Relay data  FILRUN   1040
C                                                                       FILRUN   1041
 5900  IF (RLDFLG) THEN                                                 FILRUN   1042
         WRITE (IU54, '(A5)') '  END'                                   FILRUN   1043
         REWIND (IU54)                                                  FILRUN   1044
         RLDAFN = BLNK50                                                FILRUN   1045
         LENPAR = 0                                                     FILRUN   1046
         IUX = 0                                                        FILRUN   1047
         IUY = 0                                                        FILRUN   1048
         CALL RELADA (RLDAFN, LENPAR, IUX, IUY)                         FILRUN   1049
       ENDIF                                                            FILRUN   1050
C---------------------------------------------------------------------  FILRUN   1051
C                                       Read Output Specification data  FILRUN   1052
C                                                                       FILRUN   1053
       STRING = OUTSFN                                                  FILRUN   1054
       IK = IFNBLK (STRING, 49)                                         FILRUN   1055
       IF (IK .NE. 0) THEN                                              FILRUN   1056
         OUTSFN = STRING(IK:50)                                         FILRUN   1057
         LENPAR = 0                                                     FILRUN   1058
         IUX = 0                                                        FILRUN   1059
         IUY = 0                                                        FILRUN   1060
       ENDIF                                                            FILRUN   1061
C                                                                       FILRUN   1062
       CALL RRESDA (OUTSFN, LENPAR, IUX, IUY)                           FILRUN   1063
C---------------------------------------------------------------------  FILRUN   1064
C                Renumber buses and calculate network self admittances  FILRUN   1065
C                                                                       FILRUN   1066
       CALL REBUS                                                       FILRUN   1067
       CALL HEAD                                                        FILRUN   1068
       CALL YSELF                                                       FILRUN   1069
       CALL RENET                                                       FILRUN   1070
       IF (NAUT .NE. 0) CALL ASWINT                                     FILRUN   1071
       IF (KCDC .NE. 0) CALL DCCONT                                     FILRUN   1072
C---------------------------------------------------------------------  FILRUN   1073
C                                                  Read Switching data  FILRUN   1074
C                                                                       FILRUN   1075
       STRING = SWFLNM                                                  FILRUN   1076
       IK = IFNBLK (STRING, 49)                                         FILRUN   1077
C                                                                       FILRUN   1078
       IF (IK .EQ. 0) THEN                                              FILRUN   1079
C        No file specified - open a sequential, formatted scratch file  FILRUN   1080
         IKEY = 9                                                       FILRUN   1081
         LO = 0                                                         FILRUN   1082
C                                                                       FILRUN   1083
       ELSE                                                             FILRUN   1084
C                        A sequential, formatted old file is specified  FILRUN   1085
         SWFLNM = STRING(IK:50)                                         FILRUN   1086
         CALL PARSIU (SWFLNM, LEN, IU, LO)                              FILRUN   1087
         IF (IU .LT. 0) GOTO 6100                                       FILRUN   1088
C                                                                       FILRUN   1089
         IF (IU .GT. 0) THEN                                            FILRUN   1090
           STRING = SWFLNM(1:LO)                                        FILRUN   1091
           SWFLNM = STRING(1:LO)                                        FILRUN   1092
           IU52 = IU                                                    FILRUN   1093
           CALL FBOKEP (IU52, IBACK)                                    FILRUN   1094
           IF (IBACK .LT. 0) GOTO 6100                                  FILRUN   1095
         ENDIF                                                          FILRUN   1096
C                                                                       FILRUN   1097
         IKEY = 8                                                       FILRUN   1098
         LO = INDEX (SWFLNM, ' ')                                       FILRUN   1099
         IF(IFSPTR(ISWITC) .NE. 0) THEN                                 FILRUN   1100
           MSG(1) = ' *** WARNING - SIMULATION SPECIFICATION'//         FILRUN   1101
     +              ' CARDS IN THE CONTROL FILE'                        FILRUN   1102
           MSG(2) = '               WILL BE IGNORED AND THE '//         FILRUN   1103
     +              'DATA WILL BE READ FROM THE'                        FILRUN   1104
           MSG(3) = '               SPECIFIED SWITCHING FILE.'          FILRUN   1105
           CALL PRTMSG(3)                                               FILRUN   1106
           IFSPTR(ISWITC) = 0                                           FILRUN   1107
         ENDIF                                                          FILRUN   1108
       ENDIF                                                            FILRUN   1109
C                                                                       FILRUN   1110
       JLENG = 0                                                        FILRUN   1111
       CALL OPENRE (IU52, SWFLNM, JLENG, IKEY, ISTAT, LO)               FILRUN   1112
       IF (ISTAT .NE. 0) GOTO 6100                                      FILRUN   1113
       LUNITS(IU52) = .TRUE.                                            FILRUN   1114
                                                                        FILRUN   1115
C                                              Transfer switching data  FILRUN   1116
C                          from the scratch file to the switching file  FILRUN   1117
       JREC = IFSPTR(ISWITC)                                            FILRUN   1118
 6000  IF (JREC .NE. 0) THEN                                            FILRUN   1119
         READ (IU56, REC = JREC) CARD                                   FILRUN   1120
         WRITE (IU52, '(A)') CARD                                       FILRUN   1121
         JREC = INXPTR(JREC)                                            FILRUN   1122
         GOTO 6000                                                      FILRUN   1123
       ENDIF                                                            FILRUN   1124
       IF (IFSPTR(ISWITC) .NE. 0) REWIND IU52                           FILRUN   1125
C                                                  Load switching data  FILRUN   1126
       IPSWIT = 0                                                       FILRUN   1127
       CALL LSWITD (IEBK, IPSWIT, IUY)                                  FILRUN   1128
       IF (IEBK .NE. 0) GOTO 8900                                       FILRUN   1129
C                                        Compute the admittance matrix  FILRUN   1130
       CALL YBRAN                                                       FILRUN   1131
C                                              Print switching summary  FILRUN   1132
       IF (ISWSM .EQ. 1) THEN                                           FILRUN   1133
         STRING = TASWFN                                                FILRUN   1134
         IK = IFNBLK (STRING, 49)                                       FILRUN   1135
         IF (IK .EQ. 0) THEN                                            FILRUN   1136
           MSG(1) = ' *** ERROR - INPUT DATA AND INITIAL CONDITION ' // FILRUN   1137
     +              'REPORT FILE NOT SPECIFIED.'                        FILRUN   1138
           GOTO 6700                                                    FILRUN   1139
         ENDIF                                                          FILRUN   1140
         TASWFN = STRING(IK:50)                                         FILRUN   1141
         CALL PARSIU (TASWFN, LEN, IU, LO)                              FILRUN   1142
         IF (IU .LT. 0) GOTO 6200                                       FILRUN   1143
         IF (IU .GT. 0) THEN                                            FILRUN   1144
           STRING = TASWFN(1:LO)                                        FILRUN   1145
           TASWFN = STRING(1:LO)                                        FILRUN   1146
           IU18 = IU                                                    FILRUN   1147
           CALL FBOKEP (IU18, IBACK)                                    FILRUN   1148
           IF (IBACK .LT. 0) GOTO 6200                                  FILRUN   1149
         ENDIF                                                          FILRUN   1150
         IKEY = 6                                                       FILRUN   1151
         JLENG = 0                                                      FILRUN   1152
         LO = INDEX (TASWFN, ' ')                                       FILRUN   1153
         CALL OPENRE (IU18, TASWFN, JLENG, IKEY, ISTAT, LO)             FILRUN   1154
         IF (ISTAT .NE. 0) GOTO 6200                                    FILRUN   1155
         LUNITS(IU18) = .TRUE.                                          FILRUN   1156
         EMSG = 'INPUT DATA AND INITIAL CONDITION REPORT'               FILRUN   1157
         LMSG = 39                                                      FILRUN   1158
         CALL PHEAD (IU18, LMSG, EMSG)                                  FILRUN   1159
         IUY = IU18                                                     FILRUN   1160
         CALL PSWITS (IUY)                                              FILRUN   1161
       ENDIF                                                            FILRUN   1162
C                                         Process output analysis data  FILRUN   1163
       CALL ACHAN                                                       FILRUN   1164
C                                                                       FILRUN   1165
       GOTO 6400                                                        FILRUN   1166
C                                      Error in opening switching file  FILRUN   1167
 6100  MSG(1) = ' *** ERROR OPENING SIMULATION SPECIFICATION FILE.'     FILRUN   1168
       CALL PRTMSG(1)                                                   FILRUN   1169
       IEBK = 1                                                         FILRUN   1170
       GOTO 8900                                                        FILRUN   1171
C                              Error in opening switching summary file  FILRUN   1172
 6200  MSG(1) = ' *** ERROR OPENING SWITCHING SUMMARY FILE.'            FILRUN   1173
       CALL PRTMSG(1)                                                   FILRUN   1174
       IEBK = 1                                                         FILRUN   1175
       GOTO 8900                                                        FILRUN   1176
C---------------------------------------------------------------------  FILRUN   1177
C                                       Dynamic data tabulation set up  FILRUN   1178
C                                                                       FILRUN   1179
 6400  IF (IFSPTR(ITABDA) .EQ. 0) GOTO 7000                             FILRUN   1180
C                                                                       FILRUN   1181
       IF (LUNITS(IU18)) GOTO 6500                                      FILRUN   1182
C                                                                       FILRUN   1183
       STRING = TASWFN                                                  FILRUN   1184
       IK = IFNBLK (STRING, 49)                                         FILRUN   1185
       IF (IK .EQ. 0) THEN                                              FILRUN   1186
         MSG(1) = ' *** ERROR - INPUT DATA AND INITIAL CONDITION ' //   FILRUN   1187
     +            'REPORT FILE NOT SPECIFIED.'                          FILRUN   1188
         GOTO 6700                                                      FILRUN   1189
       ENDIF                                                            FILRUN   1190
C                                                                       FILRUN   1191
       TASWFN = STRING(IK:50)                                           FILRUN   1192
       CALL PARSIU (TASWFN, LEN, IU, LO)                                FILRUN   1193
       IF (IU .LT. 0) GOTO 6600                                         FILRUN   1194
C                                                                       FILRUN   1195
       IF (IU .GT. 0) THEN                                              FILRUN   1196
         STRING = TASWFN(1:LO)                                          FILRUN   1197
         TASWFN = STRING(1:LO)                                          FILRUN   1198
         IU18 = IU                                                      FILRUN   1199
         CALL FBOKEP (IU18, IBACK)                                      FILRUN   1200
         IF (IBACK .LT. 0) GOTO 6600                                    FILRUN   1201
       ENDIF                                                            FILRUN   1202
C                                                                       FILRUN   1203
       IKEY = 6                                                         FILRUN   1204
       LO = INDEX (TASWFN, ' ')                                         FILRUN   1205
       JLENG = 0                                                        FILRUN   1206
       CALL OPENRE (IU18, TASWFN, JLENG, IKEY, ISTAT, LO)               FILRUN   1207
       IF (ISTAT .NE. 0) GOTO 6600                                      FILRUN   1208
       LUNITS(IU18) = .TRUE.                                            FILRUN   1209
       EMSG = 'INPUT DATA AND INITIAL CONDITION REPORT'                 FILRUN   1210
       LMSG = 39                                                        FILRUN   1211
       CALL PHEAD (IU18, LMSG, EMSG)                                    FILRUN   1212
C                                                                       FILRUN   1213
 6500  CALL TABDAT                                                      FILRUN   1214
       GOTO 7000                                                        FILRUN   1215
C                                                                Error  FILRUN   1216
6600   MSG(1) = ' *** ERROR OPENING TABULATION FILE.'                   FILRUN   1217
6700   CALL PRTMSG(1)                                                   FILRUN   1218
       IEBK = 1                                                         FILRUN   1219
       GOTO 8900                                                        FILRUN   1220
C---------------------------------------------------------------------  FILRUN   1221
C                                                       Initialization  FILRUN   1222
C                                                                       FILRUN   1223
7000   IF (.NOT. INITIL) THEN                                           FILRUN   1224
         WRITE (LOUT, 9400)                                             FILRUN   1225
         EMSG = ' ETMSP TERMINATED WITH NO INITIALIZATION.'             FILRUN   1226
         CALL ASTOP (EMSG, 41)                                          FILRUN   1227
       ENDIF                                                            FILRUN   1228
C                                                                       FILRUN   1229
       IF (RESLFN .NE. BLNK50) THEN                                     FILRUN   1230
         STRING = RESLFN                                                FILRUN   1231
         IK = IFNBLK (STRING, 49)                                       FILRUN   1232
         RESLFN = STRING(IK:50)                                         FILRUN   1233
         CALL PARSIU (RESLFN, LEN, IU, LO)                              FILRUN   1234
         IF (IU .LT. 0) GOTO 7300                                       FILRUN   1235
C                                                                       FILRUN   1236
         IF (IU .GT. 0) THEN                                            FILRUN   1237
           STRING = RESLFN(1:LO)                                        FILRUN   1238
           RESLFN = STRING(1:LO)                                        FILRUN   1239
           IU17=IU                                                      FILRUN   1240
           CALL FBOKEP (IU17, IBACK)                                    FILRUN   1241
           IF (IBACK .LT. 0) GOTO 7300                                  FILRUN   1242
         ENDIF                                                          FILRUN   1243
C                                                                       FILRUN   1244
         IKEY = 6                                                       FILRUN   1245
         LO = INDEX (RESLFN, ' ')                                       FILRUN   1246
         JLENG = 0                                                      FILRUN   1247
         CALL OPENRE (IU17, RESLFN, JLENG, IKEY, ISTAT, LO)             FILRUN   1248
         IF (ISTAT .NE. 0) GOTO 7300                                    FILRUN   1249
         LUNITS(IU17) = .TRUE.                                          FILRUN   1250
         EMSG = 'SIMULATION RESULT REPORT'                              FILRUN   1251
         LMSG = 24                                                      FILRUN   1252
         CALL PHEAD (IU17, LMSG, EMSG)                                  FILRUN   1253
       ENDIF                                                            FILRUN   1254
C                                              Set reference generator  FILRUN   1255
       IF (REFGEN .NE. BLNK80) THEN                                     FILRUN   1256
         IK = INDEX (REFGEN, ';')                                       FILRUN   1257
         IF (IK .NE.0) THEN                                             FILRUN   1258
           IF (KLFO .EQ. 0) THEN                                        FILRUN   1259
             READ (REFGEN(IK+1:80), *, IOSTAT = IOS) NLFR               FILRUN   1260
           ELSE                                                         FILRUN   1261
             BSNAMR = REFGEN(IK+1:IK+12)                                FILRUN   1262
           ENDIF                                                        FILRUN   1263
         ENDIF                                                          FILRUN   1264
         IF (IOS .NE. 0 .OR. IK .EQ. 0) THEN                            FILRUN   1265
           NLFR = 0                                                     FILRUN   1266
           BSNAMR = BLNK12                                              FILRUN   1267
           MSG(1) = ' *** ERROR READING REFERENCE GENERATOR BUS NAME'   FILRUN   1268
           MSG(2) = '     REFERENCE GENERATOR WILL BE CHOSEN BY DEFAULT'FILRUN   1269
           CALL PRTMSG(2)                                               FILRUN   1270
         ENDIF                                                          FILRUN   1271
       ENDIF                                                            FILRUN   1272
C                                                                       FILRUN   1273
       CALL INITIA                                                      FILRUN   1274
       GOTO 7500                                                        FILRUN   1275
C                                                                       FILRUN   1276
 7300  MSG(1) = ' *** ERROR OPENING SIMULATION FILE.'                   FILRUN   1277
       CALL PRTMSG(1)                                                   FILRUN   1278
       IEBK = 1                                                         FILRUN   1279
       GOTO 8900                                                        FILRUN   1280
C---------------------------------------------------------------------  FILRUN   1281
C                                  Initial Conditions tabulation setup  FILRUN   1282
C                                                                       FILRUN   1283
 7500  IF (IFSPTR(ITABIC) .EQ. 0) GOTO 8000                             FILRUN   1284
       IF (LUNITS(IU18)) GOTO 7600                                      FILRUN   1285
C                                                                       FILRUN   1286
       STRING = TASWFN                                                  FILRUN   1287
       IK = IFNBLK (STRING, 49)                                         FILRUN   1288
       IF (IK .EQ. 0) THEN                                              FILRUN   1289
         MSG(1) = ' *** ERROR - INPUT DATA AND INITIAL CONDITION ' //   FILRUN   1290
     +            'REPORT FILE NOT SPECIFIED.'                          FILRUN   1291
         GOTO 6700                                                      FILRUN   1292
       ENDIF                                                            FILRUN   1293
C                                                                       FILRUN   1294
       TASWFN = STRING(IK:50)                                           FILRUN   1295
       CALL PARSIU (TASWFN, LEN, IU, LO)                                FILRUN   1296
       IF (IU .LT. 0) GOTO 6600                                         FILRUN   1297
C                                                                       FILRUN   1298
       IF (IU .GT. 0) THEN                                              FILRUN   1299
         STRING = TASWFN(1:LO)                                          FILRUN   1300
         TASWFN = STRING(1:LO)                                          FILRUN   1301
         IU18 = IU                                                      FILRUN   1302
         CALL FBOKEP (IU18, IBACK)                                      FILRUN   1303
         IF (IBACK .LT. 0) GOTO 6600                                    FILRUN   1304
       ENDIF                                                            FILRUN   1305
C                                                                       FILRUN   1306
       IKEY = 6                                                         FILRUN   1307
       LO = INDEX (TASWFN, ' ')                                         FILRUN   1308
       JLENG = 0                                                        FILRUN   1309
       CALL OPENRE (IU18, TASWFN, JLENG, IKEY, ISTAT, LO)               FILRUN   1310
       IF (ISTAT .NE. 0) GOTO 6600                                      FILRUN   1311
       LUNITS(IU18) = .TRUE.                                            FILRUN   1312
       EMSG = 'INPUT DATA AND INITIAL CONDITION REPORT'                 FILRUN   1313
       LMSG = 39                                                        FILRUN   1314
       CALL PHEAD (IU18, LMSG, EMSG)                                    FILRUN   1315
C                                                                       FILRUN   1316
 7600  FILNAM = BLNK50                                                  FILRUN   1317
       LENPAR = 0                                                       FILRUN   1318
       CALL TABINI (FILNAM, LENPAR)                                     FILRUN   1319
C---------------------------------------------------------------------  FILRUN   1320
C                                                           Simulation  FILRUN   1321
C                                                                       FILRUN   1322
8000   IF (.NOT. SIMLAT) THEN                                           FILRUN   1323
         WRITE (LOUT, 9500)                                             FILRUN   1324
         EMSG = ' ETMSP TERMINATED WITH INITIALIZATION ONLY.'           FILRUN   1325
         CALL ASTOP (EMSG, 43)                                          FILRUN   1326
       ENDIF                                                            FILRUN   1327
C                                                                       FILRUN   1328
       CALL SIMULA                                                      FILRUN   1329
       GOTO 8900                                                        FILRUN   1330
C---------------------------------------------------------------------  FILRUN   1331
 8700  MSG(1) = ' *** ERROR OPENING FOLLOWING DYNAMIC DATA FILE'        FILRUN   1332
       MSG(2) = ' ' // CARD(1:79)                                       FILRUN   1333
       CALL PRTMSG(2)                                                   FILRUN   1334
       IEBK = 1                                                         FILRUN   1335
       GOTO 8900                                                        FILRUN   1336
C---------------------------------------------------------------------  FILRUN   1337
 8800  MSG(1) = ' *** ERROR OPENING FOLLOWING RELAY DATA FILE'          FILRUN   1338
       MSG(2) = ' ' // CARD(1:79)                                       FILRUN   1339
       CALL PRTMSG(2)                                                   FILRUN   1340
       IEBK = 1                                                         FILRUN   1341
       GOTO 8900                                                        FILRUN   1342
C---------------------------------------------------------------------  FILRUN   1343
 8900  IF (IEBK .NE. 0) THEN                                            FILRUN   1344
         WRITE (LOUT, 9600)                                             FILRUN   1345
         EMSG = ' ETMSP ABNORMAL TERMINATION.'                          FILRUN   1346
         CALL ASTOP (EMSG, 28)                                          FILRUN   1347
       ENDIF                                                            FILRUN   1348
C---------------------------------------------------------------------  FILRUN   1349
C                                           Formats and error messages  FILRUN   1350
C                                                                       FILRUN   1351
 9000  FORMAT (/, ' OUTPUT FILES OPENED: ', //,                         FILRUN   1352
     +            '   WARNING AND ERROR MESSAGES REPORT: ', A,          FILRUN   1353
     +            '   LUNIT <', I2, '>', /,                             FILRUN   1354
     +            '          SIMULATION PROGRESS REPORT: ', A,          FILRUN   1355
     +            '   LUNIT <', I2, '>', /,                             FILRUN   1356
     +            '       SIMULATION RESULT BINARY FILE: ', A,          FILRUN   1357
     +            '   LUNIT <', I2, '>', /)                             FILRUN   1358
 9100  FORMAT (' *** THE FOLLOWING CARD IN THE CONTROL FILE IS ',       FILRUN   1359
     +         'IGNORED')                                               FILRUN   1360
 9200  FORMAT ('     DUE TO INCORRECT SYNTAX OR DATA ERROR.')           FILRUN   1361
 9300  FORMAT ('     SINCE ITS KEYWORD WAS NOT DEFINED')                FILRUN   1362
C---------------------------------------------------------------------  FILRUN   1363
 9400  FORMAT (//, 10X,                                                 FILRUN   1364
     + '....................................................', /, 10X,  FILRUN   1365
     + ':  -- ETMSP TERMINATION WITH NO INITIALIZATION --  :', /, 10X,  FILRUN   1366
     + ':..................................................:', //)      FILRUN   1367
 9500  FORMAT (//, 10X,                                                 FILRUN   1368
     + '.................................................', /, 10X,     FILRUN   1369
     + ':  -- ETMSP TERMINATION WITH INITIALIZATION --  :', /, 10X,     FILRUN   1370
     + ':...............................................:', //)         FILRUN   1371
 9600  FORMAT (//, 10X,                                                 FILRUN   1372
     + '......................................', /, 10X,                FILRUN   1373
     + ':  -- ETMSP ABNORMAL TERMINATION --  :', /, 10X,                FILRUN   1374
     + ':....................................:', //)                    FILRUN   1375
C---------------------------------------------------------------------  FILRUN   1376
       CALL CLOSEF (IUFRUN)                                             FILRUN   1377
C---------------------------------------------------------------------  FILRUN   1378
       RETURN                                                           FILRUN   1379
       END                                                              FILRUN   1380
C*********************************************************************  FILRUN   1381
       SUBROUTINE FSTLST (STRING, LEN, IFCHR, ILCHR)                    FILRUN   1382
CD                                                                      FILRUN   1383
CD     GIVEN A CHARACTER STRING AND ITS LENGTH, THIS ROUTINE WILL FIND  FILRUN   1384
CD     THE POSITION OF THE FIRST AND THE LAST NON BLANK CHARACTERS IN   FILRUN   1385
CD     THE STRING                                                       FILRUN   1386
CD                                                                      FILRUN   1387
       CHARACTER*(*) STRING                                             FILRUN   1388
C---------------------------------------------------------------------  FILRUN   1389
       DO 1000 IFCHR = 1, LEN                                           FILRUN   1390
         IF (STRING(IFCHR:IFCHR) .NE. ' ') GOTO 1100                    FILRUN   1391
 1000  CONTINUE                                                         FILRUN   1392
C                                                                       FILRUN   1393
       IFCHR = 0                                                        FILRUN   1394
       ILCHR = 0                                                        FILRUN   1395
       GOTO 9999                                                        FILRUN   1396
C                                                                       FILRUN   1397
 1100  DO 1200 ILCHR = LEN, 1, -1                                       FILRUN   1398
         IF(STRING(ILCHR:ILCHR) .NE. ' ') GOTO 9999                     FILRUN   1399
 1200  CONTINUE                                                         FILRUN   1400
C---------------------------------------------------------------------  FILRUN   1401
 9999  RETURN                                                           FILRUN   1402
       END                                                              FILRUN   1403
