CFPRIME SIMULA                                                          SIMULA      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 SIMULA                                                 SIMULA      3
CD                                                                      SIMULA      4
CD    THIS IS THE MAIN DRIVER FOR TIME SIMULATION IN ETMSP              SIMULA      5
CD                                                                      SIMULA      6
      INCLUDE 'PARX.INS'                                                SIMULA      7
      INCLUDE 'CNREC1.INS'                                              SIMULA      8
      INCLUDE 'CNFLAG.INS'                                              SIMULA      9
      INCLUDE 'CNPT.INS'                                                SIMULA     10
      INCLUDE 'CNB0.INS'                                                SIMULA     11
      INCLUDE 'CNB4.INS'                                                SIMULA     12
      INCLUDE 'CNB9.INS'                                                SIMULA     13
      INCLUDE 'CNB19.INS'                                               SIMULA     14
      INCLUDE 'CNMON.INS'                                               SIMULA     15
      INCLUDE 'CNXSTA.INS'                                              SIMULA     16
      INCLUDE 'CNLSTA.INS'                                              SIMULA     17
      INCLUDE 'CNMSTA.INS'                                              SIMULA     18
      INCLUDE 'CNQSTA.INS'                                              SIMULA     19
      INCLUDE 'CNUNIT.INS'                                              SIMULA     20
      INCLUDE 'CNLUN.INS'                                               SIMULA     21
      INCLUDE 'CNPARX.INS'                                              SIMULA     22
      INCLUDE 'UDCA.INS'                                                SIMULA     23
      INCLUDE 'UDCG.INS'                                                SIMULA     24
      INCLUDE 'CNIMPR.INS'                                              SIMULA     25
      INCLUDE 'CNPREV.INS'                                              SIMULA     26
      INCLUDE 'CNGEAR.INS'                                              SIMULA     27
      INCLUDE 'CNULTC.INS'                                              SIMULA     28
      INCLUDE 'CNENG1.INS'                                              SIMULA     29
      INCLUDE 'CNMSG.INS'                                               SIMULA     30
      INCLUDE 'BWRALL.INS'                                              SIMULA     31
C                                                                       SIMULA     32
      LOGICAL KRESUL,IPREF,LASCHM,LRCLSE,IFIRST                         SIMULA     33
      COMMON /CHGDC/ICHGDC                                              SIMULA     34
      INTEGER IH                                                        SIMULA     35
      REAL*4  H                                                         SIMULA     36
      EQUIVALENCE(H,IH)                                                 SIMULA     37
C                                                                       SIMULA     38
      DATA NRSTEP/0/,IRSTEP/0/                                          SIMULA     39
C                                                                       SIMULA     40
      LDEB=(JDEB(1).NE.0)                                               SIMULA     41
      LASCHM=(NAUT.NE.0)                                                SIMULA     42
      LRCLSE=.FALSE.                                                    SIMULA     43
      LOPUTC=0                                                          SIMULA     44
C                                                                       SIMULA     45
C     INITIALIZE IKE WITH ZERO VALUE                                    SIMULA     46
      IKE=0                                                             SIMULA     47
      XKLAST=0.0                                                        SIMULA     48
      TOTALP=0.0                                                        SIMULA     49
C                                                                       SIMULA     50
C                                                                       SIMULA     51
      WRITE(LOUT,1200)                                                  SIMULA     52
C                                                                       SIMULA     53
C  STORE THE TOTAL NUMBER OF STATES AND INITIALIZE 'QSTATE' TO ZERO     SIMULA     54
C                                                                       SIMULA     55
      CALL FMOVE (0,QSTATE,QSTATE,JSTATE)                               SIMULA     56
C                                                                       SIMULA     57
C  READ ISWTEX FROM USER DEFINED SWITCHING FILE ISWF                    SIMULA     58
C                                                                       SIMULA     59
      REWIND ISWF                                                       SIMULA     60
C                                                                       SIMULA     61
      READ(ISWF,1030) (ISWTEX(L),L=1,20)                                SIMULA     62
C                                                                       SIMULA     63
C  READ MAX SPEED DEVIATION, STUDY PERIOD,TIME STEP,PRINT RATIO         SIMULA     64
C  FROM USER DEFINED SWITCHING FILE ISWF                                SIMULA     65
C                                                                       SIMULA     66
      READ(ISWF,1040) XCMM,TL,HN,INDIVX,KNDIVX,IPLTK,IPPK,LOBUS         SIMULA     67
C                                                                       SIMULA     68
C     XMAXSD=MAX SPEED DEVTN(IN P.U.) TO TERMINATE                      SIMULA     69
C                                                                       SIMULA     70
      IF(XMAXSD.LE.0.02) XMAXSD=0.02                                    SIMULA     71
C                                                                       SIMULA     72
C      CALL PAGE6                                                       SIMULA     73
C      CALL PAGE17                                                      SIMULA     74
      WRITE(IU6,1050) (ISWTEX(LL),LL=1,20)                              SIMULA     75
      WRITE(IU6,1060) XMAXSD,TL,HN,INDIVX,KNDIVX                        SIMULA     76
C      WRITE(IU17,1050) (ISWTEX(LL),LL=1,20)                            SIMULA     77
C      WRITE(IU17,1060) XMAXSD,TL,HN,INDIVX,KNDIVX                      SIMULA     78
C                                                                       SIMULA     79
C     CONVERT XMAXSD TO RADS/SEC.                                       SIMULA     80
C                                                                       SIMULA     81
      XMAXSD=XMAXSD*WOBASE                                              SIMULA     82
C                                                                       SIMULA     83
C     SET INTEGRATION METHOD FLAG:                                      SIMULA     84
C                                                                       SIMULA     85
C      LINTEG = .FALSE.  -- EXPLICIT METHOD IS IN USE                   SIMULA     86
C             = .TRUE.  -- IMPLICIT METHOD IS IN USE                    SIMULA     87
C                                                                       SIMULA     88
      LINTEG=.FALSE.                                                    SIMULA     89
      NBFLAG=-1                                                         SIMULA     90
C                                                                       SIMULA     91
C   INITIALIZE XPREV ARRAY FOR USE OF IMPLICIT INTEGRATION METHOD       SIMULA     92
C                                                                       SIMULA     93
      DO 90 I=1,NSTATE                                                  SIMULA     94
       XPREV(1,I)=XSTATE(I)                                             SIMULA     95
       XPREV(2,I)=XSTATE(I)                                             SIMULA     96
  90  CONTINUE                                                          SIMULA     97
C                                                                       SIMULA     98
C   NOTE:                                                               SIMULA     99
C                                                                       SIMULA    100
C   NSTEP = TOTAL NO. OF TIME STEPS IN THE SIMULATION WITH              SIMULA    101
C           IMPLICIT METHOD                                             SIMULA    102
C   NTITER = TOTAL NO. OF ITERATIONS IN THE SIMULATION WITH             SIMULA    103
C            IMPLICIT METHOD                                            SIMULA    104
C                                                                       SIMULA    105
C                                                                       SIMULA    106
      NTSTEP=0                                                          SIMULA    107
      NTITER=0                                                          SIMULA    108
      LONEXT=0                                                          SIMULA    109
      ILSUM=0                                                           SIMULA    110
      ILSUM1=0                                                          SIMULA    111
C                                                                       SIMULA    112
C     LSDAMP = .FALSE.  : NO SYSTEM DAMPING ADDED                       SIMULA    113
C            = .TRUE.   : SYSTEM DAMPING ADDED                          SIMULA    114
C                                                                       SIMULA    115
      LSDAMP=.FALSE.                                                    SIMULA    116
C                                                                       SIMULA    117
      LDISC=.TRUE.                                                      SIMULA    118
      IPREF=.FALSE.                                                     SIMULA    119
      TS=0.0                                                            SIMULA    120
      TBWRO=0.0                                                         SIMULA    121
      IASWX=0                                                           SIMULA    122
      TSOUTC=0.                                                         SIMULA    123
C                                                                       SIMULA    124
C   NOTE:                                                               SIMULA    125
C                                                                       SIMULA    126
C  ITSTRN IS THE TERMINATION FLAG                                       SIMULA    127
C  ITSTRN=1 SET IN RESULT ROUTINE WHEN SPEED OF GENERATOR EXCEEDS LIMIT SIMULA    128
C  ITSTRN=2 SET IN NETSOL WHEN VOLTAGE ITERATION EXCEEDED LIMIT         SIMULA    129
C  ITSTRN=3 SET IN INITIA WHEN PRE-FAULT NETWORK ITERATION              SIMULA    130
C           EXCEEDED LIMIT                                              SIMULA    131
C                                                                       SIMULA    132
C                                                                       SIMULA    133
      IPP=0                                                             SIMULA    134
      ITSTRN=0                                                          SIMULA    135
      KVOLT=1                                                           SIMULA    136
      IPLT=1                                                            SIMULA    137
      IASPRI=0                                                          SIMULA    138
      IRPTK=1                                                           SIMULA    139
C                                                                       SIMULA    140
C   NOTE:                                                               SIMULA    141
C                                                                       SIMULA    142
C  KVOLT=0 NETSOL CALCULATE CURRENT INJECTED BUS VOLTAGES ONLY          SIMULA    143
C  KVOLT=1 NETSOL WILL COMPUTE ALL REQUESTED VOLTAGES                   SIMULA    144
C                                                                       SIMULA    145
C                                                                       SIMULA    146
      IDTS=0                                                            SIMULA    147
      ITCFLG=0                                                          SIMULA    148
  100 CONTINUE                                                          SIMULA    149
C                                                                       SIMULA    150
      IBFLAG=0                                                          SIMULA    151
      CALL MODIFY (H,IPREF,IBFLAG)                                      SIMULA    152
      IF(NDLR.NE.0)LRCLSE=.TRUE.                                        SIMULA    153
      H=0.0                                                             SIMULA    154
      IR=0                                                              SIMULA    155
      IFIRST=.TRUE.                                                     SIMULA    156
C                                                                       SIMULA    157
C                                                                       SIMULA    158
C     WHEN TS = TNOFA(+) FAULT IS NOW CLEARED                           SIMULA    159
C                                                                       SIMULA    160
      IF(IKE.EQ.1)THEN                                                  SIMULA    161
C                                                                       SIMULA    162
C     CALCULATE THE KINETIC ENERGY                                      SIMULA    163
C                                                                       SIMULA    164
      CALL SYSCEN                                                       SIMULA    165
      CALL KENERG                                                       SIMULA    166
      XKLAST=TOTALK                                                     SIMULA    167
C                                                                       SIMULA    168
C     SET IKE = 2 TO FIND POST FAULT MAXIMUM KINETIC ENERGY             SIMULA    169
C                                                                       SIMULA    170
      IKE=2                                                             SIMULA    171
C                                                                       SIMULA    172
      ENDIF                                                             SIMULA    173
C                                                                       SIMULA    174
C   NOTE:                                                               SIMULA    175
C  IPRTSW IS THE PROGRAM PRINT OUT CONTROL FLAG                         SIMULA    176
C  IPRTSW=1 RESULT ROUTNIE WILL CALCULATE,WRITE AND PRINT               SIMULA    177
C  IPRTSW=2 RESULT ROUTINE WILL CALCULATE AND WRITE                     SIMULA    178
C  IPRTSW=3 RESULT ROUTINE WILL JUST WRITE END OF SIMULATION RECORDS    SIMULA    179
C                                                                       SIMULA    180
C  READ NEXT SWITCHING TIME RECORD FROM ISWF FILE                       SIMULA    181
C                                                                       SIMULA    182
      READ(ISWF,1010) TNEXT,HN,INDIVY,KNDIVY,IPPKN,IPLKN,INTMTH,IRPTKN  SIMULA    183
     *               ,IGMINS,EPSGR,LONEXT                               SIMULA    184
      IF(INTMTH.EQ.0) INTMTH=1                                          SIMULA    185
      INDIV=INDIVX                                                      SIMULA    186
      IF(INDIVY.NE.0) INDIV=INDIVY                                      SIMULA    187
      KNDIV=KNDIVX                                                      SIMULA    188
      IF(KNDIVY.NE.0) KNDIV=KNDIVY                                      SIMULA    189
                                                                        SIMULA    190
      IF(IKE.EQ.0.AND.ABS(TNEXT-TNOFA).LE.0.00001)THEN                  SIMULA    191
C                                                                       SIMULA    192
C     TS = TNOFA" PRIOR TO READ THE NEXT SET OF SWITCHING DATA          SIMULA    193
C                                                                       SIMULA    194
C     SET IKE    = 1 TO CALCULATE THE KINETIC ENERGY WHEN FAULT         SIMULA    195
C                    IS CLEARED (MAXIMUM KINETIC ENERGY)                SIMULA    196
C                                                                       SIMULA    197
      IKE=1                                                             SIMULA    198
C                                                                       SIMULA    199
      ENDIF                                                             SIMULA    200
C                                                                       SIMULA    201
      IF (INTMTH.LE.5) THEN                                             SIMULA    202
         LINTEG=.FALSE.                                                 SIMULA    203
      ELSE IF (INTMTH.GE.11) THEN                                       SIMULA    204
         LINTEG=.TRUE.                                                  SIMULA    205
         IGEARS=.FALSE.                                                 SIMULA    206
         IF (INTMTH.EQ.12) THEN                                         SIMULA    207
            IGEARS=.TRUE.                                               SIMULA    208
            NGMINS=0                                                    SIMULA    209
            IF (IGMINS.EQ.0) IGMINS=5                                   SIMULA    210
            IF (EPSGR.EQ.0.0) EPSGR=0.001                               SIMULA    211
         END IF                                                         SIMULA    212
      END IF                                                            SIMULA    213
C                                                                       SIMULA    214
C  DETERMINE THE ITERATION CONTROL                                      SIMULA    215
C                                                                       SIMULA    216
      IF(IFAUTO.EQ.0)THEN                                               SIMULA    217
       LITTER=0                                                         SIMULA    218
       LITER=0                                                          SIMULA    219
      ELSE                                                              SIMULA    220
       LITTER=1                                                         SIMULA    221
       LITER=1                                                          SIMULA    222
      ENDIF                                                             SIMULA    223
C                                                                       SIMULA    224
C                                                                       SIMULA    225
C  CHANGE HN AND IPPR ONLY IF NEW VALUES ARE READ                       SIMULA    226
C                                                                       SIMULA    227
      IF (HN.GT.1.0E-5) THEN                                            SIMULA    228
         HSTEP=HN                                                       SIMULA    229
      ELSE IF (INTMTH.EQ.12) THEN                                       SIMULA    230
         HSTEP=0.005                                                    SIMULA    231
      END IF                                                            SIMULA    232
      IF(IRPTKN.NE.0)IRPTK=IRPTKN                                       SIMULA    233
      IF(IPPKN.NE.0)IPPK=IPPKN                                          SIMULA    234
      IF(IPLKN.NE.0)IPLTK=IPLKN                                         SIMULA    235
      IF(NMOTL.EQ.0)KNDIV=0                                             SIMULA    236
      IF(KCDC.EQ.0)INDIV=0                                              SIMULA    237
      XNDIV=INDIV                                                       SIMULA    238
      JNDIV=INDIV-1                                                     SIMULA    239
      YNDIV=KNDIV                                                       SIMULA    240
      LNDIV=KNDIV-1                                                     SIMULA    241
C                                                                       SIMULA    242
 110  CONTINUE                                                          SIMULA    243
C                                                                       SIMULA    244
C  CALCULATE THE EVENED STEP SIZE                                       SIMULA    245
C                                                                       SIMULA    246
      IF(TNEXT.GE.TL)THEN                                               SIMULA    247
         TNEXT=TL                                                       SIMULA    248
         ITERMI=1                                                       SIMULA    249
      ELSE                                                              SIMULA    250
         ITERMI=0                                                       SIMULA    251
      ENDIF                                                             SIMULA    252
C                                                                       SIMULA    253
      XSTEP=(TNEXT-TS)/HSTEP                                            SIMULA    254
C                                                                       SIMULA    255
      XSTEP=XSTEP+0.5                                                   SIMULA    256
      NSTEP=INT(XSTEP)                                                  SIMULA    257
      XSTEP=REAL(NSTEP)                                                 SIMULA    258
      HXSTEP=(TNEXT-TS)/XSTEP                                           SIMULA    259
      IF(ABS(HXSTEP-HSTEP).GT.1.E-5)THEN                                SIMULA    260
         NSTEP=NSTEP+1                                                  SIMULA    261
         XSTEP=REAL(NSTEP)                                              SIMULA    262
         HSTEP=(TNEXT-TS)/XSTEP                                         SIMULA    263
      ELSE                                                              SIMULA    264
         HSTEP=HXSTEP                                                   SIMULA    265
      ENDIF                                                             SIMULA    266
      KSTEP=NSTEP-1                                                     SIMULA    267
      IF(IASPRI.EQ.0)THEN                                               SIMULA    268
      WRITE(IU6,1000) TNEXT,HSTEP,NSTEP,IPLTK,IPPK,IRPTK,INDIV,KNDIV    SIMULA    269
     *               ,INTMTH,NSLMTH,LOBUS                               SIMULA    270
C      WRITE(IU17,1000) TNEXT,HSTEP,NSTEP,IPLTK,IPPK,IRPTK,INDIV,KNDIV  SIMULA    271
C     *                ,INTMTH,NSLMTH,LOBUS                             SIMULA    272
      ENDIF                                                             SIMULA    273
C                                                                       SIMULA    274
      IIL=61                                                            SIMULA    275
C                                                                       SIMULA    276
      IF(IFIRST)THEN                                                    SIMULA    277
      CALL NETSOL (H,KVOLT,0,IPREF,IIL,NRSTEP)                          SIMULA    278
      IFIRST=.FALSE.                                                    SIMULA    279
      ENDIF                                                             SIMULA    280
C                                                                       SIMULA    281
C    DETERMINE THE STEP SIZE FOR THE FOSSIL FIRED BOILER MODEL          SIMULA    282
C                                                                       SIMULA    283
      TDIF=TNEXT-TS                                                     SIMULA    284
      IF (TDIF.LE. 0.1 )THEN                                            SIMULA    285
         NBSTEP=NSTEP                                                   SIMULA    286
         BNSTEP=TNEXT-TS                                                SIMULA    287
      ELSE                                                              SIMULA    288
         NBB1=INT( (0.1/HSTEP)+0.5 )                                    SIMULA    289
         NBB2=INT( (0.2/HSTEP)+0.5 )                                    SIMULA    290
         DO 115 JJ=NBB1,NBB2                                            SIMULA    291
           II=MOD(NSTEP,JJ)                                             SIMULA    292
           IF((II.EQ.0) .OR. (JJ-II).LE.5 )GOTO 116                     SIMULA    293
 115     CONTINUE                                                       SIMULA    294
 116     NBSTEP=JJ                                                      SIMULA    295
         BNSTEP=NBSTEP*HSTEP                                            SIMULA    296
      ENDIF                                                             SIMULA    297
C                                                                       SIMULA    298
C  NOTE:                                                                SIMULA    299
C  DTIME IS THE INTERVAL SIZE FOR THE DC ROUTINES                       SIMULA    300
C                                                                       SIMULA    301
      DTIME=HSTEP                                                       SIMULA    302
C                                                                       SIMULA    303
C  SANITY CHECK TO SEE WHETHER THE AC TIME STEP IS SMALLER              SIMULA    304
C  THAN THE DC TIME STEP.                                               SIMULA    305
C                                                                       SIMULA    306
      IF(STIME.GT.(HSTEP+0.00001)) THEN                                 SIMULA    307
       WRITE(MSG(1),1100) STIME                                         SIMULA    308
       WRITE(MSG(2),1101) HSTEP                                         SIMULA    309
       CALL PRTMSG(2)                                                   SIMULA    310
       MSG(1)='TERMINATED DUE TO IMPROPER SIZE OF DC TIME STEP'         SIMULA    311
       CALL ASTOP(MSG(1),47)                                            SIMULA    312
      ENDIF                                                             SIMULA    313
C                                                                       SIMULA    314
C  SANITY CHECK TO SEE WHETHER THE DC TIME STEP IS SMALLER              SIMULA    315
C  THAN THE DC CONTROL TIME STEP.                                       SIMULA    316
C                                                                       SIMULA    317
      IF(CTIME.GT.STIME) THEN                                           SIMULA    318
       WRITE(MSG(1),1110) CTIME                                         SIMULA    319
       WRITE(MSG(2),1111) STIME                                         SIMULA    320
       CALL PRTMSG(2)                                                   SIMULA    321
       MSG(1)=                                                          SIMULA    322
     *  'TERMINATED DUE TO IMPROPER SIZE OF DC CONTROL TIME STEP'       SIMULA    323
       CALL ASTOP(MSG(1),55)                                            SIMULA    324
      ENDIF                                                             SIMULA    325
C                                                                       SIMULA    326
      ISTEP=-1                                                          SIMULA    327
C                                                                       SIMULA    328
  200 CONTINUE                                                          SIMULA    329
C                                                                       SIMULA    330
C  NOTE:                                                                SIMULA    331
C      KRESUL=FALSE NO RESULT IS REQUIRED                               SIMULA    332
C      KRESUL=TRUE RESULT IS REQUIRED                                   SIMULA    333
C                                                                       SIMULA    334
      ICHECK=-10                                                        SIMULA    335
      KRESUL=.FALSE.                                                    SIMULA    336
C                                                                       SIMULA    337
      IF(IH.EQ.0.OR.ISTEP.EQ.KSTEP)THEN                                 SIMULA    338
C                                                                       SIMULA    339
C     DISCONTINUNITY POINT                                              SIMULA    340
C                                                                       SIMULA    341
         IPRTSW=1                                                       SIMULA    342
         KRESUL=.TRUE.                                                  SIMULA    343
         LDISC=.TRUE.                                                   SIMULA    344
         IPP=1                                                          SIMULA    345
         IPLT=1                                                         SIMULA    346
C                                                                       SIMULA    347
C     TIME POINT                                                        SIMULA    348
C                                                                       SIMULA    349
      ELSE                                                              SIMULA    350
C                                                                       SIMULA    351
         LDISC=.FALSE.                                                  SIMULA    352
C                                                                       SIMULA    353
         IF(IPLT.LT.IPLTK)THEN                                          SIMULA    354
            IPLT=IPLT+1                                                 SIMULA    355
         ELSE                                                           SIMULA    356
            IPLT=1                                                      SIMULA    357
            IPRTSW=2                                                    SIMULA    358
            KRESUL=.TRUE.                                               SIMULA    359
            IF(IPP.LT.IPPK)THEN                                         SIMULA    360
               IPP=IPP+1                                                SIMULA    361
            ELSE                                                        SIMULA    362
               IPP=1                                                    SIMULA    363
               IPRTSW=1                                                 SIMULA    364
            ENDIF                                                       SIMULA    365
         ENDIF                                                          SIMULA    366
      ENDIF                                                             SIMULA    367
C                                                                       SIMULA    368
      IF(.NOT.LUNITS(IU17))IPRTSW=2                                     SIMULA    369
C                                                                       SIMULA    370
      IF(IH.NE.0) IRSTEP=IRSTEP+1                                       SIMULA    371
      IF(IRSTEP.EQ.IRPTK)THEN                                           SIMULA    372
         IRSTEP=0                                                       SIMULA    373
         NRSTEP=1                                                       SIMULA    374
      ENDIF                                                             SIMULA    375
C                                                                       SIMULA    376
C                                                                       SIMULA    377
C   DETERMINE THE FLAG FOR DGEN CALLING THE BOILER                      SIMULA    378
C                                                                       SIMULA    379
                                                                        SIMULA    380
      IF(.NOT.LDISC)THEN                                                SIMULA    381
          ICHECK=MOD(ISTEP,NBSTEP)                                      SIMULA    382
      ENDIF                                                             SIMULA    383
C                                                                       SIMULA    384
C   DETERMINE THE FOSSIL FIRED BOILER TIME STEP                         SIMULA    385
C                                                                       SIMULA    386
      IF(NSTEP.NE.NBSTEP)THEN                                           SIMULA    387
       IF(NBFLAG.EQ.-1)THEN                                             SIMULA    388
        IDIF=NSTEP-ISTEP                                                SIMULA    389
        IF(IDIF.LT.NBSTEP)THEN                                          SIMULA    390
           NBSTEP=IDIF                                                  SIMULA    391
           BNSTEP=NBSTEP*HSTEP                                          SIMULA    392
           ICHECK=0                                                     SIMULA    393
           NBFLAG=0                                                     SIMULA    394
        ENDIF                                                           SIMULA    395
       ENDIF                                                            SIMULA    396
      ENDIF                                                             SIMULA    397
C                                                                       SIMULA    398
C                                                                       SIMULA    399
C  NOTE:                                                                SIMULA    400
C      INTMTH <= 5  FOR EXPLICIT METHOD                                 SIMULA    401
C      INTMTH >= 11 FOR IMPLICIT INTEGRATION METHOD                     SIMULA    402
C                                                                       SIMULA    403
      IF(IHOOK.EQ.1)CALL HOOK(IHOOK)                                    SIMULA    404
C                                                                       SIMULA    405
      IF (INTMTH.LE.5.OR.IH.EQ.0) THEN                                  SIMULA    406
         IF (LINTEG) INTMTH=1                                           SIMULA    407
         CALL INTRKG(H,KRESUL,IPREF,IIL,NRSTEP)                         SIMULA    408
      ELSE IF (LINTEG) THEN                                             SIMULA    409
         CALL IMPINT(KRESUL,IIL,NRSTEP)                                 SIMULA    410
      END IF                                                            SIMULA    411
C                                                                       SIMULA    412
C     ITSTRN = 2 WHEN NETWORK ITERATION COUNT EXCEEDES LIMIT            SIMULA    413
C                                                                       SIMULA    414
C                                                                       SIMULA    415
      IF (ITSTRN.EQ.2) GOTO 300                                         SIMULA    416
      ISTEP=ISTEP+1                                                     SIMULA    417
      TS=TS+H                                                           SIMULA    418
C                                                                       SIMULA    419
      IF (KRESUL) THEN                                                  SIMULA    420
         CALL RESULT(H,LOUT)                                            SIMULA    421
            IF(IFAUTO.NE.0)THEN                                         SIMULA    422
            CALL SCHECK(H)                                              SIMULA    423
            CALL CURVHL                                                 SIMULA    424
            ENDIF                                                       SIMULA    425
      END IF                                                            SIMULA    426
C                                                                       SIMULA    427
      CALL GSPCHK                                                       SIMULA    428
C                                                                       SIMULA    429
C     ITSTRN = 1 WHEN GENERATOR SPEED EXCEEDS LIMIT                     SIMULA    430
C                                                                       SIMULA    431
      IF(ITSTRN.EQ.1)GOTO 300                                           SIMULA    432
C                                                                       SIMULA    433
C     CALCULATE KINETIC ENERGY AND TRACK FOR MAXIMUM                    SIMULA    434
C     AND MINIMUM VALUES                                                SIMULA    435
C                                                                       SIMULA    436
      IF(.NOT.LDISC.AND.IKE.GE.2)THEN                                   SIMULA    437
      CALL SYSCEN                                                       SIMULA    438
      CALL KENERG                                                       SIMULA    439
      DKE=TOTALK-XKLAST                                                 SIMULA    440
C                                                                       SIMULA    441
      IF(IKE.EQ.2)THEN                                                  SIMULA    442
C                                                                       SIMULA    443
C        IKE=2 FIND MAXIMUM POST FAULT KINETIC ENERGY                   SIMULA    444
C                                                                       SIMULA    445
           IF(DKE.LE.0.0)THEN                                           SIMULA    446
           IKE=3                                                        SIMULA    447
           TKEMAX=TS                                                    SIMULA    448
           XKEMAX=TOTALK                                                SIMULA    449
           XKLAST=TOTALK                                                SIMULA    450
C                                                                       SIMULA    451
           ELSE                                                         SIMULA    452
           XKLAST=TOTALK                                                SIMULA    453
           ENDIF                                                        SIMULA    454
C                                                                       SIMULA    455
           ELSEIF(IKE.EQ.3)THEN                                         SIMULA    456
C                                                                       SIMULA    457
C       IKE=3 FIND MINIMUM POST FAULT KINETIC ENERGY                    SIMULA    458
C                                                                       SIMULA    459
           IF(DKE.GT.0.0)THEN                                           SIMULA    460
           IKE=4                                                        SIMULA    461
           TKEMIN=TS                                                    SIMULA    462
           XKEMIN=TOTALK                                                SIMULA    463
C                                                                       SIMULA    464
           ELSE                                                         SIMULA    465
           XKLAST=TOTALK                                                SIMULA    466
           ENDIF                                                        SIMULA    467
C                                                                       SIMULA    468
      ENDIF                                                             SIMULA    469
C                                                                       SIMULA    470
      ENDIF                                                             SIMULA    471
C                                                                       SIMULA    472
      IF ((LASCHM).OR.(LRCLSE) .OR. NULTC .GT. 0) THEN                  SIMULA    473
         IF ((LASCHM).OR.(LRCLSE)) THEN                                 SIMULA    474
            CALL ASWCHK(H)                                              SIMULA    475
         END IF                                                         SIMULA    476
         IF (NULTC .GT. 0 .AND. MULTSW.GE.0) THEN                       SIMULA    477
            LOPUTC=LOPUTC+1                                             SIMULA    478
            NAWRUC=0                                                    SIMULA    479
            IF (LOPUTC.GE.MULTSW) THEN                                  SIMULA    480
               CALL ULTCMO(NDELAY,H,IDTS,TSOUTC)                        SIMULA    481
               LOPUTC=0                                                 SIMULA    482
            END IF                                                      SIMULA    483
         END IF                                                         SIMULA    484
         CALL ASWREP                                                    SIMULA    485
C                                                                       SIMULA    486
C                                                                       SIMULA    487
         IF (IASWX.NE.0) THEN                                           SIMULA    488
C                                                                       SIMULA    489
            IASPRI=1                                                    SIMULA    490
C                                                                       SIMULA    491
            IF (ABS(TS-TNEXT).LE. 1.0E-6) IBFLAG=1                      SIMULA    492
            READ(ISWFA,1010)DUMMY                                       SIMULA    493
            CALL MODIFY (H,IPREF,IBFLAG)                                SIMULA    494
            IF (NDLR.NE.0) THEN                                         SIMULA    495
               LRCLSE=.TRUE.                                            SIMULA    496
            ELSE                                                        SIMULA    497
               LRCLSE=.FALSE.                                           SIMULA    498
            END IF                                                      SIMULA    499
            H=0.0                                                       SIMULA    500
            IR=0                                                        SIMULA    501
            CALL NETSOL (H,KVOLT,0,IPREF,IIL,NRSTEP)                    SIMULA    502
            IASWX=0                                                     SIMULA    503
            IF (ABS(TS-TNEXT).LE.1.0E-6) GOTO 100                       SIMULA    504
C                IF(NSMTCL.EQ.0)THEN                                    SIMULA    505
C                 CALL LODSUM(TS,0,ILSUM)                               SIMULA    506
C                 ILSUM=0                                               SIMULA    507
C                ENDIF                                                  SIMULA    508
            GOTO 110                                                    SIMULA    509
         ELSE                                                           SIMULA    510
C                                                                       SIMULA    511
            IASPRI=0                                                    SIMULA    512
C                                                                       SIMULA    513
         END IF                                                         SIMULA    514
C                                                                       SIMULA    515
      END IF                                                            SIMULA    516
C                                                                       SIMULA    517
      H=HSTEP                                                           SIMULA    518
C                                                                       SIMULA    519
      IF (LINTEG.AND.INTMTH.EQ.1) THEN                                  SIMULA    520
         INTMTH=11                                                      SIMULA    521
         IF (IGEARS) INTMTH=12                                          SIMULA    522
         CALL PREINT                                                    SIMULA    523
      END IF                                                            SIMULA    524
C                                                                       SIMULA    525
      IF (ISTEP.LT.NSTEP) GOTO 200                                      SIMULA    526
C                                                                       SIMULA    527
      LOBUS=LONEXT                                                      SIMULA    528
C                                                                       SIMULA    529
      IF (ITERMI.EQ.0) GOTO 100                                         SIMULA    530
C                                                                       SIMULA    531
C     STOP SIMULATION COMPLETED                                         SIMULA    532
C                                                                       SIMULA    533
  300 CONTINUE                                                          SIMULA    534
      IPRTSW=3                                                          SIMULA    535
      CALL RESULT(H,LOUT)                                               SIMULA    536
C                                                                       SIMULA    537
      CALL PRULTC                                                       SIMULA    538
C                                                                       SIMULA    539
      CALL RANKVM                                                       SIMULA    540
      CALL LODSUM(TS,1,ILSUM1)                                          SIMULA    541
C                                                                       SIMULA    542
      IF (NTSTEP.NE.0) THEN                                             SIMULA    543
         WRITE(IU6,2000) NTSTEP,NTITER,REAL(NTITER)/REAL(NTSTEP)        SIMULA    544
      END IF                                                            SIMULA    545
C                                                                       SIMULA    546
      RETURN                                                            SIMULA    547
C                                                                       SIMULA    548
 1000 FORMAT('  NEXT SWITCHING TIME =',F10.4,/                          SIMULA    549
     &,'  TIME INTERVAL =',F8.4,/                                       SIMULA    550
     &,'  NUMBER OF STEPS =',I5,/                                       SIMULA    551
     &,'  PRINT & PLOT CONTROL OPTION :',/                              SIMULA    552
     &,'  PLOT STEP =',I5,3X,'PRINT STEP =',I5,'   REPORT STEP =',I5,/  SIMULA    553
     &,'  DC SOLUTION DIVIDER = ',I2,/                                  SIMULA    554
     &,'  INDUCTION MOTOR SOLUTION DIVIDER = ',I2,/                     SIMULA    555
     &,'  INTEGRATION OPTION = ',I2,/                                   SIMULA    556
     &,'  NETWORK SOLUTION OPTION = ',I2,/                              SIMULA    557
     *,'  LOAD BUS SIMPLIFICATION OPTION = ',I2,/)                      SIMULA    558
 1010 FORMAT(2F10.5,6I5,5X,I5,F10.5,I5)                                 SIMULA    559
 1030 FORMAT(20A4)                                                      SIMULA    560
 1040 FORMAT(3F10.5,6I5)                                                SIMULA    561
 1050 FORMAT('  SWITCHING: ',20A4)                                      SIMULA    562
 1060 FORMAT(/,'  MAXIMUM SPEED DEVIATION TO TERMINATE STUDY  =',F8.4   SIMULA    563
     *,' IN PER UNIT',/                                                 SIMULA    564
     *,'  INTENDED LENGTH OF SIMULATION TL',12X,'=',F8.4,' SECONDS',/   SIMULA    565
     *,'  NOMINAL TIME INTERVAL H',21X,'=',F8.4,' SECONDS',/            SIMULA    566
     *,'  NOMINAL DC SOLUTION DIVIDER IDC',13X,'=',I3,/                 SIMULA    567
     *,'  NOMINAL INDUCTION MOTOR SOLUTION DIVIDER IM =',I3,//)         SIMULA    568
 1100 FORMAT(' *** ERROR THE DC TIME STEP = ',F8.4,                     SIMULA    569
     *' SHOULD BE SMALLER THAN')                                        SIMULA    570
 1101 FORMAT('     THE AC TIME STEP = ',F8.4)                           SIMULA    571
 1110 FORMAT(' *** ERROR THE DC CONTROL TIME STEP = ',F8.6,             SIMULA    572
     &' SHOULD BE SMALLER THAN')                                        SIMULA    573
 1111 FORMAT('     THE DC TIME STEP = ',F8.6)                           SIMULA    574
 1200 FORMAT(32X,'SOLUTION REPORT',/,32X,15('='),/                      SIMULA    575
     *,'                                    MAX. ANG.'                  SIMULA    576
     *,'                        MAX. CUR.',/                            SIMULA    577
     *,'     TIME     BUS#  STATION NAME GID   CHANGE'                  SIMULA    578
     *,'     BUS#    BUS NAME    MISMATCH',/                            SIMULA    579
     *,'    -----    -----  ------------ --- --------'                  SIMULA    580
     *,'    -----  ------------ ---------')                             SIMULA    581
 2000 FORMAT(///,'  TOTAL NUMBER OF TIME STEPS (NTSTEP) =',I7,/         SIMULA    582
     *,'  TOTAL NUMBER OF ITERATIONS (NTITER) =',I7,/                   SIMULA    583
     *,'  NTITER/NTSTEP                       =',F7.3,/)                SIMULA    584
C                                                                       SIMULA    585
      END                                                               SIMULA    586
