CFPRIME INITIA                                                          INITIA      1
C***********************************************************************RIGHTE      1
C*                                                                     *RIGHTE      2
C*        Extended Transient-Midterm Stability Program (ETMSP)         *RIGHTE      3
C*        ====================================================         *RIGHTE      4
C*                                                                     *RIGHTE      5
C*       Copyright (C) (1993) Electric Power Research Institute        *RIGHTE      6
C*                                                                     *RIGHTE      7
C* EPRI reserves all rights in the software and associated             *RIGHTE      8
C* documentation as delivered. The software and its associated         *RIGHTE      9
C* documention or any portion thereof may not be reproduced in any form*RIGHTE     10
C* whatsoever without the consent of EPRI, except as explicity provided*RIGHTE     11
C* for by license. Licensee shall submit a detailed description to EPRI*RIGHTE     12
C* of any changes or modifications to the software within two (2)      *RIGHTE     13
C* months after such changes or modifications are made. At EPRI's sole *RIGHTE     14
C* discretion, the software, as changed or modified, shall be given a  *RIGHTE     15
C* new designation sufficiently different from its then current        *RIGHTE     16
C* designation as to prevent mistake,confusion, or deception as between*RIGHTE     17
C* the current software as changed or modified.                        *RIGHTE     18
C*                                                                     *RIGHTE     19
C* A license under EPRI's rights in the software can be obtained       *RIGHTE     20
C* directly from EPRI.                                                 *RIGHTE     21
C*                                                                     *RIGHTE     22
C* This program and supporting materials may be independently available*RIGHTE     23
C* from Electric Power Software centre (EPSC) for an appropriate       *RIGHTE     24
C* distribution fee. The EPSC is a service of                          *RIGHTE     25
C*                                                                     *RIGHTE     26
C*                    Power Computing Company                          *RIGHTE     27
C*                    1930 Hi Line                                     *RIGHTE     28
C*                    Dallas, Tx 75207                                 *RIGHTE     29
C*                                                                     *RIGHTE     30
C* NEITHER EPRI, ANY MEMBER OF EPRI, NOR ANY PERSON OR  ORGANIZATION   *RIGHTE     31
C* ACTING ON BEHAVE OF THEM:                                           *RIGHTE     32
C*                                                                     *RIGHTE     33
C* 1. MAKE ANY WARRANTY OR REPRESENTATION WHATSOEVER, EXPRESS OR       *RIGHTE     34
C*    IMPLIED, INCLUDING ANY WARRANTY OF MERCHANTABILITY OR FITNESS OR *RIGHTE     35
C*    ANY PURPOSE WITH RESPECT TO THE SOFTWARE OR ITS ASSOCIATED       *RIGHTE     36
C*    DOCUMENTATION; OR                                                *RIGHTE     37
C*                                                                     *RIGHTE     38
C* 2. ASSUMES ANY LIABILITY WHATSOEVER WITH RESPECT TO ANY USE OF THE  *RIGHTE     39
C*    SOFTWARE OR ITS ASSOCIATED DOCUMENTATION OR ANY PORTION THEREOF  *RIGHTE     40
C*    OR WITH RESPECT TO ANY DAMAGES WHICH MAY RESULT FROM SUCH USE.   *RIGHTE     41
C*                                                                     *RIGHTE     42
C* THIS NOTICE MAY NOT BE REMOVED FROM THE SOFTWARE BY ANY USER        *RIGHTE     43
C* THEREOF.                                                            *RIGHTE     44
C*                                                                     *RIGHTE     45
C***********************************************************************RIGHTE     46
      SUBROUTINE INITIA                                                 INITIA      3
CD                                                                      INITIA      4
CD    THIS SUBROUTINE IS THE MAIN DRIVER FOR INITIALIZATION OF ALL      INITIA      5
CD    DYNAMIC DEVICES AND FOR ADDITIONAL DATA SANITY CHECK.             INITIA      6
CD                                                                      INITIA      7
CD    THE MAJOR COMPUTATION SEQUENCE IS:                                INITIA      8
CD                                                                      INITIA      9
      INCLUDE 'CNLSTA.INS'                                              INITIA     10
      INCLUDE 'PARX.INS'                                                INITIA     11
      INCLUDE 'CNB0.INS'                                                INITIA     12
      INCLUDE 'CNB9.INS'                                                INITIA     13
      INCLUDE 'CNFLAG.INS'                                              INITIA     14
      INCLUDE 'CNPT.INS'                                                INITIA     15
      INCLUDE 'CNIPTR.INS'                                              INITIA     16
      INCLUDE 'CNB4.INS'                                                INITIA     17
      INCLUDE 'CNSTN.INS'                                               INITIA     18
      INCLUDE 'CNQSTA.INS'                                              INITIA     19
      INCLUDE 'CNXSTA.INS'                                              INITIA     20
      INCLUDE 'CNYVAR.INS'                                              INITIA     21
      INCLUDE 'CNULTC.INS'                                              INITIA     22
      INCLUDE 'CNUNIT.INS'                                              INITIA     23
      INCLUDE 'CNLUN.INS'                                               INITIA     24
      INCLUDE 'CNIMPR.INS'                                              INITIA     25
      INCLUDE 'CNNNEW.INS'                                              INITIA     26
      INCLUDE 'CNUDIC.INS'                                              INITIA     27
      INCLUDE 'CNXDOT.INS'                                              INITIA     28
      INCLUDE 'CNMSG.INS'                                               INITIA     29
      INCLUDE 'CNGEAR.INS'                                              INITIA     30
      INCLUDE 'CNB8.INS'                                                INITIA     31
      INCLUDE 'CNHL20.INS'                                              INITIA     32
      INCLUDE 'CNFRUN.INS'                                              INITIA     33
C                                                                       INITIA     34
      LOGICAL LASCHM,IPREF                                              INITIA     35
      INTEGER IH                                                        INITIA     36
      REAL*4  H                                                         INITIA     37
      EQUIVALENCE(H,IH)                                                 INITIA     38
C                                                                       INITIA     39
      CHARACTER*80 STRING,MSG1,EMSG                                     INITIA     40
      CHARACTER*7 SUBPMT                                                INITIA     41
      CHARACTER*12 BUSNAM                                               INITIA     42
C                                                                       INITIA     43
      LDEB=(JDEB(1).NE.0)                                               INITIA     44
      LASCHM=(NAUT.NE.0)                                                INITIA     45
C                                                                       INITIA     46
      SUBPMT='INITIA '                                                  INITIA     47
      IEBK=0                                                            INITIA     48
      IPRTSW=2                                                          INITIA     49
C                                                                       INITIA     50
      IF (CFLRUN) GOTO 20                                               INITIA     51
CD                                                                      INITIA     52
CD    STEP 1. DETERMINE IF THE SIMULATION RESULT FILE IS WANTED?        INITIA     53
CD                                                                      INITIA     54
   10 CONTINUE                                                          INITIA     55
      MSG1='DO YOU WANT THE SIMULATION RESULT FILE ? (Y/N)'             INITIA     56
      WRITE(LOUT,*)                                                     INITIA     57
      CALL REDLIN(LOUT,LIN,IOERR,46,MSG1,SUBPMT,'IN1',STRING,           INITIA     58
     &RECORD,IREC,KLAYER,KEND,KREAD,PLAYBA)                             INITIA     59
      IF (IOERR.LT.0)THEN                                               INITIA     60
      IF(PLAYBA)CALL PSTOP                                              INITIA     61
      GOTO 10                                                           INITIA     62
      ENDIF                                                             INITIA     63
       IF (STRING(1:1).EQ.'Y'.OR.STRING(1:1).EQ.'y') THEN               INITIA     64
         IKEY=6                                                         INITIA     65
         JLENG=133                                                      INITIA     66
         MSG1='ENTER THE SIMULATION RESULT FILE NAME:'                  INITIA     67
         EMSG='ERROR IN OPENING SIMULATION RESULT FILE'                 INITIA     68
         LMSG=38                                                        INITIA     69
         LEMSG=39                                                       INITIA     70
      ELSE IF (STRING(1:1).EQ.'N'.OR.STRING(1:1).EQ.'n') THEN           INITIA     71
         GOTO 20                                                        INITIA     72
      ELSE                                                              INITIA     73
         KREAD=.TRUE.                                                   INITIA     74
         IF(PLAYBA)CALL PSTOP                                           INITIA     75
         GOTO 10                                                        INITIA     76
      END IF                                                            INITIA     77
C                                                                       INITIA     78
      WRITE(LOUT,*)                                                     INITIA     79
      CALL FILEMG(IU17,LMSG,MSG1,LEMSG,EMSG,SUBPMT,IKEY,JLENG,IEBK)     INITIA     80
C                                                                       INITIA     81
      IF (IEBK.NE.0)THEN                                                INITIA     82
      IF(PLAYBA)CALL PSTOP                                              INITIA     83
      GOTO 10                                                           INITIA     84
      ENDIF                                                             INITIA     85
C                                                                       INITIA     86
      LUNITS(IU17)=.TRUE.                                               INITIA     87
C                                                                       INITIA     88
      MSG(1)='SIMULATION RESULT REPORT'                                 INITIA     89
      CALL PHEAD(IU17,24,MSG(1))                                        INITIA     90
      WRITE(IU17,'(A)') '1'                                             INITIA     91
C                                                                       INITIA     92
 20   IF (LUNITS(IU17)) IPRTSW=1                                        INITIA     93
C                                                                       INITIA     94
      WRITE(LOUT,'(/A/)') ' INITIALIZING GENERATORS. WAIT ...'          INITIA     95
C                                                                       INITIA     96
C  SET THE LOBUS,LBOLD FLAG                                             INITIA     97
C                                                                       INITIA     98
      LOBUS=0                                                           INITIA     99
      LBOLD=0                                                           INITIA    100
      ITTER=0                                                           INITIA    101
      LNSIX=NSI                                                         INITIA    102
C                                                                       INITIA    103
      NVALUS=0                                                          INITIA    104
      NVALUR=0                                                          INITIA    105
      NVALUT=0                                                          INITIA    106
      NVALUB=0                                                          INITIA    107
      NVALIU=0                                                          INITIA    108
      NVALOU=0                                                          INITIA    109
C                                                                       INITIA    110
      DO 100 I=1,LNSIX                                                  INITIA    111
         XDFACT(I)=1.0                                                  INITIA    112
 100  CONTINUE                                                          INITIA    113
CD                                                                      INITIA    114
CD    STEP 2. CALL GENINT TO  SET UP GENERATOR INITIAL CONDITIONS.      INITIA    115
CD                                                                      INITIA    116
      CALL GENINT(NRF,*400,*500)                                        INITIA    117
      IF (CFLRUN) THEN                                                  INITIA    118
         IF (KLFO.EQ.0) THEN                                            INITIA    119
            IF (NLFR.GT.0) THEN                                         INITIA    120
               NRF1=NNEW(NLFR)                                          INITIA    121
               IF (NRF1.EQ.0) THEN                                      INITIA    122
                  WRITE(MSG(1),2010) NLFR                               INITIA    123
                  CALL PRTMSG(1)                                        INITIA    124
                  GOTO 180                                              INITIA    125
               END IF                                                   INITIA    126
            ELSE                                                        INITIA    127
               GOTO 170                                                 INITIA    128
            END IF                                                      INITIA    129
         ELSE                                                           INITIA    130
            IF (BSNAMR.NE.' ') THEN                                     INITIA    131
               CALL CHKBUS (BSNAMR,NLF)                                 INITIA    132
               IF (NLF.EQ.0) THEN                                       INITIA    133
                  WRITE(MSG(1),2020) BSNAMR                             INITIA    134
                  CALL PRTMSG(1)                                        INITIA    135
                  GOTO 180                                              INITIA    136
               END IF                                                   INITIA    137
               NRF1=NNEW(NLF)                                           INITIA    138
            ELSE                                                        INITIA    139
               GOTO 170                                                 INITIA    140
            END IF                                                      INITIA    141
         END IF                                                         INITIA    142
         IF (NRF1.GT.IPNODE) THEN                                       INITIA    143
            IF (KLFO.EQ.0) THEN                                         INITIA    144
               WRITE(MSG(1),2030) NLFR                                  INITIA    145
            ELSE                                                        INITIA    146
               WRITE(MSG(1),2040) BSNAMR                                INITIA    147
            END IF                                                      INITIA    148
            CALL PRTMSG(1)                                              INITIA    149
            GOTO 180                                                    INITIA    150
         ELSE                                                           INITIA    151
            NRF=NRF1                                                    INITIA    152
            GOTO 170                                                    INITIA    153
         END IF                                                         INITIA    154
      END IF                                                            INITIA    155
C                                                                       INITIA    156
      NLF=NOLD(NRF)                                                     INITIA    157
      KK=NRF*3                                                          INITIA    158
      WRITE(LOUT,1000) NLF,INAME(KK-2),INAME(KK-1),INAME(KK)            INITIA    159
      MSG(1)='DO YOU WANT TO CHANGE (Y/N) ?'                            INITIA    160
 110  CALL PMTRED(LOUT,LIN,IOERR,29,MSG(1),'XXX',STRING,KREAD,PLAYBA)   INITIA    161
      IF (IOERR.LT.0)THEN                                               INITIA    162
      IF(PLAYBA)CALL PSTOP                                              INITIA    163
      GOTO 110                                                          INITIA    164
      ENDIF                                                             INITIA    165
      IF (RECORD) WRITE(IREC,'(A)') STRING                              INITIA    166
      IF (STRING(1:1).EQ.'N'.OR.STRING(1:1).EQ.'n') GOTO 170            INITIA    167
      IF (STRING(1:1).NE.'Y'.AND.STRING(1:1).NE.'y') THEN               INITIA    168
         IF (PLAYBA) CALL PSTOP                                         INITIA    169
         GOTO 110                                                       INITIA    170
      END IF                                                            INITIA    171
C                                                                       INITIA    172
      MREFG=0                                                           INITIA    173
 150  CONTINUE                                                          INITIA    174
      MREFG=MREFG+1                                                     INITIA    175
      IF (MREFG.GT.5) GOTO 180                                          INITIA    176
C                                                                       INITIA    177
C     SPECIFY THE REFERENCE GENERATOR BUS                               INITIA    178
C                                                                       INITIA    179
      WRITE(LOUT,*)                                                     INITIA    180
      IF (KLFO.EQ.0) THEN                                               INITIA    181
         MSG(1)='ENTER ;REFERENCE GENERATOR NUMBER :'                   INITIA    182
      ELSE                                                              INITIA    183
         MSG(1)='ENTER ;REFERENCE GENERATOR NAME :  '                   INITIA    184
      END IF                                                            INITIA    185
      CALL PMTRED(LOUT,LIN,IOERR,35,MSG(1),'RR5',STRING,KREAD,PLAYBA)   INITIA    186
      IF (IOERR.LT.0)THEN                                               INITIA    187
      IF(PLAYBA)CALL PSTOP                                              INITIA    188
      GOTO 150                                                          INITIA    189
      ENDIF                                                             INITIA    190
      IF (RECORD) WRITE(IREC,'(A)') STRING                              INITIA    191
      I1=INDEX(STRING,';')+1                                            INITIA    192
      IF (I1.EQ.1) GOTO 150                                             INITIA    193
      IF (KLFO.EQ.0)THEN                                                INITIA    194
         READ(STRING(I1:80),*,IOSTAT=IOS) NLF                           INITIA    195
         IF (IOS.EQ.0) GOTO 160                                         INITIA    196
         KREAD=.TRUE.                                                   INITIA    197
         GOTO 150                                                       INITIA    198
 160     CONTINUE                                                       INITIA    199
         NRF=NNEW(NLF)                                                  INITIA    200
         IF (NRF.EQ.0)  THEN                                            INITIA    201
            WRITE(LOUT,2010) NLF                                        INITIA    202
            GOTO 150                                                    INITIA    203
         END IF                                                         INITIA    204
      ELSE                                                              INITIA    205
         BUSNAM=STRING(I1:I1+11)                                        INITIA    206
         CALL CHKBUS(BUSNAM,NLF)                                        INITIA    207
         IF (NLF.EQ.0) THEN                                             INITIA    208
            KREAD=.TRUE.                                                INITIA    209
            WRITE(LOUT,2020) BUSNAM                                     INITIA    210
            GOTO 150                                                    INITIA    211
         END IF                                                         INITIA    212
         NRF=NNEW(NLF)                                                  INITIA    213
      END IF                                                            INITIA    214
C                                                                       INITIA    215
C    REF BUS CHECK                                                      INITIA    216
C                                                                       INITIA    217
      IF (NRF.GT.IPNODE) THEN                                           INITIA    218
         IF (KLFO.EQ.0) THEN                                            INITIA    219
            WRITE(LOUT,2030) NLF                                        INITIA    220
         ELSE                                                           INITIA    221
            WRITE(LOUT,2040) BUSNAM                                     INITIA    222
         END IF                                                         INITIA    223
         KREAD=.TRUE.                                                   INITIA    224
         IF(PLAYBA)CALL PSTOP                                           INITIA    225
         GOTO 150                                                       INITIA    226
      END IF                                                            INITIA    227
C                                                                       INITIA    228
C     SET THE REFERENCE GEN NO.                                         INITIA    229
C     AND DOFFST (USED IN RESULT)                                       INITIA    230
C                                                                       INITIA    231
 170  NRF=NTHG(NRF)                                                     INITIA    232
      IGEN=JCONTA(1,NRF)                                                INITIA    233
      IF (IGEN.EQ.4) THEN                                               INITIA    234
        DOFFST=0.0                                                      INITIA    235
      ELSE                                                              INITIA    236
        DOFFST=90.0                                                     INITIA    237
      END IF                                                            INITIA    238
      GOTO 190                                                          INITIA    239
C                                                                       INITIA    240
 180  CONTINUE                                                          INITIA    241
      NRF=1                                                             INITIA    242
      NLF=NOLD(1)                                                       INITIA    243
      WRITE(LOUT,2050) NLF,INAME(1),INAME(2),INAME(3)                   INITIA    244
C                                                                       INITIA    245
 190  CONTINUE                                                          INITIA    246
C                                                                       INITIA    247
      WRITE(LOUT,'(/A/)') ' INITIALIZING REMAINING DEVICES.  WAIT ...'  INITIA    248
CD                                                                      INITIA    249
CD    STEP 3. CALL MOTINT TO  SET UP MOTOR INITIAL CONDITIONS.          INITIA    250
CD                                                                      INITIA    251
      IF (NMOTL.NE.0) CALL MOTINT(*400,*500)                            INITIA    252
*IF LTSP                                                                INITIA    253
*ENDIF                                                                  INITIA    255
CD                                                                      INITIA    256
CD    STEP 4. CALL TSCINT TO SET UP TSC LOAD CONDITIONS.                INITIA    257
CD                                                                      INITIA    258
      IF (JTHDC.EQ.2) THEN                                              INITIA    259
         WRITE(MSG(1),2090)                                             INITIA    260
         WRITE(MSG(2),3000)                                             INITIA    261
         CALL PRTMSG(2)                                                 INITIA    262
      END IF                                                            INITIA    263
      IF (NTSCL.NE.0) THEN                                              INITIA    264
         IF(JSTATE+2*NTSCL.GT.LNSIX) GOTO 400                           INITIA    265
         CALL TSCINT                                                    INITIA    266
      END IF                                                            INITIA    267
CD                                                                      INITIA    268
CD    STEP 5. CALL SVCINT TO SET UP INITIAL CONDITIONS OF ALL           INITIA    269
CD            STATIC VAR COMPENSATORS.                                  INITIA    270
CD                                                                      INITIA    271
      IF (NSVC.NE.0) CALL SVCINT(*400,*500)                             INITIA    272
CD                                                                      INITIA    273
CD    STEP 6. CALL ULTCIN TO SET UP INITIAL CONDITIONS OF ALL ULTC.     INITIA    274
CD                                                                      INITIA    275
      IF (NULTC.NE.0) CALL ULTCIN                                       INITIA    276
CD                                                                      INITIA    277
CD    STEP 7. CALL RANINT TO SET UP INITIAL CONDITIONS OF ALL RANIS.    INITIA    278
CD                                                                      INITIA    279
      IF (NRANI.NE.0) CALL RANINT(*500)                                 INITIA    280
CD                                                                      INITIA    281
CD    STEP 8. CALL STPINT TO SET UP INITIAL CONDITIONS OF ALL STP       INITIA    282
CD    DEVICES.                                                          INITIA    283
CD                                                                      INITIA    284
      IF (NTCPS.NE.0) CALL STPINT(*500)                                 INITIA    285
CD                                                                      INITIA    286
CD    STEP 9. CALL SDBINT TO SET UP INITIAL CONDITIONS OF ALL SDB       INITIA    287
CD    DEVICES.                                                          INITIA    288
CD                                                                      INITIA    289
      IF (NSDB.NE.0) CALL SDBINT(*500)                                  INITIA    290
CD                                                                      INITIA    291
CD    NOTE:  NSTATE IS THE LENGTH OF STATE VARIABLES (AC SYSTEM ONLY)   INITIA    292
CD           LYVARB IS THE LENGTH OF Y VARIABLES                        INITIA    293
CD                                                                      INITIA    294
      NSTATE=JSTATE                                                     INITIA    295
      LYVARB=JY                                                         INITIA    296
      WRITE(IU6,2060) NSTATE,LYVARB                                     INITIA    297
CD                                                                      INITIA    298
CD    STEP 10. CALL DCCONI TO SET UP DC CONVERTER INITIAL CONDITIONS.   INITIA    299
CD                                                                      INITIA    300
      IF (KCDC.NE.0) CALL DCCONI                                        INITIA    301
CD                                                                      INITIA    302
CD    STEP 11. CALL PCHAN TO WRITE CHANNEL FILE DIRECTORY RECORDS.      INITIA    303
CD                                                                      INITIA    304
      CALL PCHAN                                                        INITIA    305
CD                                                                      INITIA    306
CD    STEP 12. DO PRE-FAULT NETWORK SOLUTION.                           INITIA    307
CD                                                                      INITIA    308
      WRITE(LOUT,'(/A/)')                                               INITIA    309
     *' PERFORMING PRE-FAULT NETWORK SOLUTION.  WAIT ...'               INITIA    310
C                                                                       INITIA    311
      IPREF=.TRUE.                                                      INITIA    312
      LDISC=.TRUE.                                                      INITIA    313
      TS=0.0                                                            INITIA    314
      IASWX=0                                                           INITIA    315
      ITSOLD=MAXIT                                                      INITIA    316
CD                                                                      INITIA    317
CD    NOTE:                                                             INITIA    318
CD                                                                      INITIA    319
CD    ITSTRN     IS THE TERMINATION FLAG                                INITIA    320
CD    ITSTRN = 1 SET IN RESULT ROUTINE WHEN SPEED OF GENERATOR EXCEEDS  INITIA    321
CD               LIMIT                                                  INITIA    322
CD    ITSTRN = 2 SET IN NETSOL WHEN VOLTAGE ITERATION EXCEEDED LIMIT    INITIA    323
CD    ITSTRN = 3 SET IN INITIA WHEN PRE- FAULT NETWORK ITERATION        INITIA    324
CD               EXCEEDED LIMIT                                         INITIA    325
CD                                                                      INITIA    326
      IPP=0                                                             INITIA    327
      ITSTRN=0                                                          INITIA    328
      KVOLT=1                                                           INITIA    329
CD                                                                      INITIA    330
CD    KVOLT  = 0 NETSOL CALCULATE CURRENT INJECTED BUS VOLTAGES ONLY    INITIA    331
CD    KVOLT  = 1 NETSOL WILL COMPUTE ALL REQUESTED VOLTAGES             INITIA    332
CD                                                                      INITIA    333
      IBFLAG=0                                                          INITIA    334
      CALL MODIFY (H,IPREF,IBFLAG)                                      INITIA    335
C      IF(NDLR.NE.0)LRCLSE=.TRUE.                                       INITIA    336
      H=0.0                                                             INITIA    337
      IR=0                                                              INITIA    338
C                                                                       INITIA    339
      MAXIT=MPRITE                                                      INITIA    340
      CALL ISCHEC                                                       INITIA    341
C                                                                       INITIA    342
      I1=0                                                              INITIA    343
      IIL=216                                                           INITIA    344
      CALL NETSOL (H,KVOLT,0,IPREF,IIL,I1)                              INITIA    345
       CALL ICURHL                                                      INITIA    346
CD                                                                      INITIA    347
CD    IPRTSW = 1 RESULT ROUTNIE WILL CALCULATE,WRITE AND PRINT          INITIA    348
CD    IPRTSW = 2 RESULT ROUTINE WILL CALCULATE AND WRITE                INITIA    349
CD    IPRTSW = 3 RESULT ROUTINE WILL JUST WRITE END OF SIMULATION       INITIA    350
CD               RECORDS                                                INITIA    351
CD                                                                      INITIA    352
      CALL RESULT (H,0)                                                 INITIA    353
      IF (ITER.GT.MPRITE) THEN                                          INITIA    354
         ITSTRN=3                                                       INITIA    355
         WRITE(MSG(1),2000) ITER,MPRITE                                 INITIA    356
         CALL PRTMSG(1)                                                 INITIA    357
      END IF                                                            INITIA    358
C                                                                       INITIA    359
      MAXIT=ITSOLD                                                      INITIA    360
C                                                                       INITIA    361
      IF (LASCHM) CALL ASWCHK(H)                                        INITIA    362
CD                                                                      INITIA    363
CD    STEP 13. CALL PRXDOT TO CHECK THE DSTATE.                         INITIA    364
CD                                                                      INITIA    365
      WRITE(LOUT,'(/A/)')                                               INITIA    366
     *' CHECKING PRE-FAULT STATE DERIVATIVES.  WAIT ...'                INITIA    367
C                                                                       INITIA    368
      H=0.0                                                             INITIA    369
      CALL PRXDOT(IU16,ZDTOL)                                           INITIA    370
C                                                                       INITIA    371
C                                                                       INITIA    372
      IF(IHOOK.EQ.0)THEN                                                INITIA    373
C                                                                       INITIA    374
      CALL HOOK(IHOOK)                                                  INITIA    375
C                                                                       INITIA    376
        IF(IHOOK.EQ.3.OR.IHOOK.EQ.4)THEN                                INITIA    377
 200    CONTINUE                                                        INITIA    378
        IKEY=10                                                         INITIA    379
        MSG1='ENTER YOUR HOOK OUTPUT FILE NAME:'                        INITIA    380
        EMSG='ERROR IN OPENING HOOK OUTPUT FILE'                        INITIA    381
        LMSG=33                                                         INITIA    382
        LEMSG=33                                                        INITIA    383
C                                                                       INITIA    384
        WRITE(LOUT,*)                                                   INITIA    385
        CALL FILEMG(IUHK,LMSG,MSG1,LEMSG,EMSG,SUBPMT,IKEY,JLENG,IEBK)   INITIA    386
C                                                                       INITIA    387
          IF(IEBK.NE.0)THEN                                             INITIA    388
          IF(PLAYBA)CALL PSTOP                                          INITIA    389
          GOTO 200                                                      INITIA    390
          ENDIF                                                         INITIA    391
C                                                                       INITIA    392
C      CALL HOOK TO PRINT INITIAL CONDITIONS IF REQUIRED                INITIA    393
C                                                                       INITIA    394
        IF(IHOOK.EQ.4)CALL HOOK(IHOOK)                                  INITIA    395
C                                                                       INITIA    396
        ENDIF                                                           INITIA    397
C                                                                       INITIA    398
C     TO ACTIVATE THE CALLS OF HOOK IN ROUTINE SIMULA SET IHOOK TO 1    INITIA    399
C                                                                       INITIA    400
      IHOOK=1                                                           INITIA    401
C                                                                       INITIA    402
      ENDIF                                                             INITIA    403
                                                                        INITIA    404
C                                                                       INITIA    405
      RETURN                                                            INITIA    406
C                                                                       INITIA    407
  400 CONTINUE                                                          INITIA    408
      WRITE(MSG(1),2070) LNSIX                                          INITIA    409
      CALL PRTMSG(1)                                                    INITIA    410
      CALL ASTOP(MSG(1),1)                                              INITIA    411
C                                                                       INITIA    412
  500 CONTINUE                                                          INITIA    413
      WRITE(MSG(1),2080) LNSIX                                          INITIA    414
      CALL PRTMSG(1)                                                    INITIA    415
      CALL ASTOP(MSG(1),1)                                              INITIA    416
C                                                                       INITIA    417
 1000 FORMAT(' GENERATOR AT BUS',I6,1X,3A4                              INITIA    418
     *,' IS SELECTED AS THE REFERENCE GENERATOR')                       INITIA    419
 2000 FORMAT(' *** ERROR PRE-FAULT ITERATION=',I3                       INITIA    420
     &,' EXCEEDS THE LIMIT OF',I4,' ITERATIONS')                        INITIA    421
 2010 FORMAT(1X,'*** ERROR REFERENCE GENERATOR BUS# ',I5                INITIA    422
     &,' IS NOT IN THE LOADFLOW')                                       INITIA    423
 2020 FORMAT(1X,'*** ERROR REFERENCE GENERATOR BUS',A12                 INITIA    424
     &,' IS NOT IN THE LOADFLOW')                                       INITIA    425
 2030 FORMAT(' *** ERROR:  REF. GENERATOR BUS# ',I5                     INITIA    426
     &,' IS NOT A GENERATOR BUS')                                       INITIA    427
 2040 FORMAT(' *** ERROR: REF. GENERATOR BUS ',A12                      INITIA    428
     &,' IS NOT A GENERATOR BUS')                                       INITIA    429
 2050 FORMAT(1X,'*** WARNING TOO MANY REFERENCE GENERATOR BUS ERRORS'   INITIA    430
     &,/,1X,'PROGRAM HAS CHOSEN GENERATOR AT BUS: '                     INITIA    431
     &,/,1X,I5,1X,3A4,' TO BE THE REFERENCE GENERATOR')                 INITIA    432
 2060 FORMAT(/5X,'TOTAL NUMBER OF STATES IN THE SYSTEM = ',I5/          INITIA    433
     &5X,'TOTAL NUMBER OF Y VARIABLES IN THE SYSTEM = ',I5/)            INITIA    434
 2070 FORMAT(' *** ERROR TOTAL NUMBER OF STATES IN THE SYSTEM EXCEEDS'  INITIA    435
     *,' THE LIMIT OF',I6)                                              INITIA    436
 2080 FORMAT(' *** ERROR TOTAL NUMBER OF Y VARIABLES IN THE SYSTEM'     INITIA    437
     *,' EXCEEDS THE LIMIT OF',I6)                                      INITIA    438
 2090 FORMAT(' *** WARNING EVERY MACHINE WILL BE REPRESENTED BY ')      INITIA    439
 3000 FORMAT('     ITS EQUIVALENT INFINITE BUS BEHIND IMPEDANCE.')      INITIA    440
C                                                                       INITIA    441
      END                                                               INITIA    442
