CFPRIME INTRKG                                                          INTRKG      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 INTRKG(H,KRESUL,IPREF,IIL,NRSTEP)                      INTRKG      3
CD                                                                      INTRKG      4
CD    THIS SUBROUTINE IS THE MAIN DRIVER FOR THE EXPLICIT INTEGRATION   INTRKG      5
CD    METHODS.                                                          INTRKG      6
CD                                                                      INTRKG      7
      INCLUDE 'PARX.INS'                                                INTRKG      8
      INCLUDE 'CNPT.INS'                                                INTRKG      9
      INCLUDE 'CNB4.INS'                                                INTRKG     10
      INCLUDE 'CNB9.INS'                                                INTRKG     11
      INCLUDE 'CNFLAG.INS'                                              INTRKG     12
      INCLUDE 'UDCA.INS'                                                INTRKG     13
      INCLUDE 'UDCJ.INS'                                                INTRKG     14
      INCLUDE 'CNVOLT.INS'                                              INTRKG     15
C                                                                       INTRKG     16
      CHARACTER*80 MSG                                                  INTRKG     17
      LOGICAL KRESUL,IPREF                                              INTRKG     18
C                                                                       INTRKG     19
C      DATA A2/0.2928932/,A3/1.7071068/                                 INTRKG     20
C                                                                       INTRKG     21
      LDEB=.FALSE.                                                      INTRKG     22
      A2=0.2928932                                                      INTRKG     23
      A3=1.7071068                                                      INTRKG     24
C                                                                       INTRKG     25
      KVOLT=0                                                           INTRKG     26
      IF(LDISC)GOTO 280                                                 INTRKG     27
      IF(KCDC.NE.0)THEN                                                 INTRKG     28
        IF(JTHDC.EQ.1)THEN                                              INTRKG     29
          CALL DCNET1                                                   INTRKG     30
        ELSE                                                            INTRKG     31
          CALL DCNETS(TS)                                               INTRKG     32
        ENDIF                                                           INTRKG     33
      ENDIF                                                             INTRKG     34
      IF(KNDIV.LE.1)GOTO 280                                            INTRKG     35
      HD=H/YNDIV                                                        INTRKG     36
      HDD=0.5*HD                                                        INTRKG     37
      I=0                                                               INTRKG     38
      HF=+0.0                                                           INTRKG     39
  200 I=I+1                                                             INTRKG     40
      HF=HF+HD                                                          INTRKG     41
      GOTO ( 210, 220, 230, 230, 230, 250), INTMTH                      INTRKG     42
  210 CONTINUE                                                          INTRKG     43
      IR=0                                                              INTRKG     44
      GOTO 240                                                          INTRKG     45
  220 CONTINUE                                                          INTRKG     46
      IR=1                                                              INTRKG     47
      A1=0.50000000                                                     INTRKG     48
      GOTO 240                                                          INTRKG     49
  230 CONTINUE                                                          INTRKG     50
      IR=2                                                              INTRKG     51
  240 IR=IR+1                                                           INTRKG     52
      CALL ICOEF                                                        INTRKG     53
      IF(JTHDC.NE.2) CALL DEMOTL(HD)                                    INTRKG     54
      IF(IR.LT.4)GOTO 240                                               INTRKG     55
      GOTO 270                                                          INTRKG     56
  250 CONTINUE                                                          INTRKG     57
      IR=1                                                              INTRKG     58
      ICOUNT=0                                                          INTRKG     59
  260 ICOUNT=ICOUNT+1                                                   INTRKG     60
      STOLMX=+0.0                                                       INTRKG     61
      IF(JTHDC.NE.2) CALL DEMOTL(HDD)                                   INTRKG     62
      IR=2                                                              INTRKG     63
      IF(ICOUNT.LT.2)GOTO 260                                           INTRKG     64
      IF(STOLMX.GT.STOL.AND.ICOUNT.LT.50)GOTO 260                       INTRKG     65
C      WRITE(IUD6,1000) ICOUNT,TS,STOLMX,STOL                           INTRKG     66
      IF(ICOUNT.GE.50) THEN                                             INTRKG     67
      MSG='INTRKG: STOP 79'                                             INTRKG     68
      CALL ASTOP(MSG,15)                                                INTRKG     69
      ENDIF                                                             INTRKG     70
  270 CONTINUE                                                          INTRKG     71
      IF(I.LT.LNDIV)GOTO 200                                            INTRKG     72
      IF(I.GE.KNDIV)GOTO 280                                            INTRKG     73
      HD=H-HF                                                           INTRKG     74
      HDD=0.5*HD                                                        INTRKG     75
      GOTO 200                                                          INTRKG     76
  280 CONTINUE                                                          INTRKG     77
      GOTO ( 290, 300, 310, 310, 310, 330), INTMTH                      INTRKG     78
  290 CONTINUE                                                          INTRKG     79
      LIR1=.TRUE.                                                       INTRKG     80
      IR=0                                                              INTRKG     81
      KSBINT=4                                                          INTRKG     82
      GOTO 320                                                          INTRKG     83
  300 CONTINUE                                                          INTRKG     84
      LIR1=.TRUE.                                                       INTRKG     85
      IR=1                                                              INTRKG     86
      KSBINT=3                                                          INTRKG     87
      A1=0.50000000                                                     INTRKG     88
      GOTO 320                                                          INTRKG     89
  310 CONTINUE                                                          INTRKG     90
      LIR1=.TRUE.                                                       INTRKG     91
      IR=2                                                              INTRKG     92
      KSBINT=2                                                          INTRKG     93
  320 IR=IR+1                                                           INTRKG     94
      LIR4=(IR.EQ.4)                                                    INTRKG     95
      CALL ICOEF                                                        INTRKG     96
      IF(JTHDC.NE.2) CALL DGEN(H)                                       INTRKG     97
C                                                                       INTRKG     98
C   DETERMINE THE ITERATION CONTROL                                     INTRKG     99
C                                                                       INTRKG    100
      IF(LDISC)THEN                                                     INTRKG    101
       IF(IFAUTO.EQ.0)THEN                                              INTRKG    102
        LITER=0                                                         INTRKG    103
        LITTER=0                                                        INTRKG    104
       ELSE                                                             INTRKG    105
        LITER=1                                                         INTRKG    106
        LITTER=1                                                        INTRKG    107
       ENDIF                                                            INTRKG    108
      ENDIF                                                             INTRKG    109
C                                                                       INTRKG    110
      IF(NMOTL.NE.0.AND.JTHDC.NE.2) CALL DEMOTL(H)                      INTRKG    111
      IF(NTSCL.NE.0) CALL DETSCL(H)                                     INTRKG    112
      IF(NSVC.NE.0)CALL DESVC(H)                                        INTRKG    113
      IF(NRANI.NE.0)CALL DERAN(H)                                       INTRKG    114
      IF(NTCPS.NE.0)CALL DESTP(H)                                       INTRKG    115
      IF(NSDB.NE.0) CALL DESDB(H)                                       INTRKG    116
      IF(LIR4)THEN                                                      INTRKG    117
         IF(KRESUL) KVOLT=1                                             INTRKG    118
         CALL NETSOL(H,KVOLT,IR,IPREF,IIL,NRSTEP)                       INTRKG    119
      ELSE                                                              INTRKG    120
         I1=0                                                           INTRKG    121
         CALL NETSOL(H,KVOLT,IR,IPREF,IIL,I1)                           INTRKG    122
      ENDIF                                                             INTRKG    123
      LIR1=.FALSE.                                                      INTRKG    124
      IF(IR.LT.4)GOTO 320                                               INTRKG    125
      RETURN                                                            INTRKG    126
  330 CONTINUE                                                          INTRKG    127
      ICOUNT=0                                                          INTRKG    128
      HDD=0.5*H                                                         INTRKG    129
      IR=1                                                              INTRKG    130
  340 ICOUNT=ICOUNT+1                                                   INTRKG    131
      STOLMX=+0.0                                                       INTRKG    132
      IF(JTHDC.NE.2) CALL DGEN(HDD)                                     INTRKG    133
      IF(NMOTL.NE.0.AND.JTHDC.NE.2) CALL DEMOTL(H)                      INTRKG    134
      IF(NTSCL.NE.0) CALL DETSCL(HDD)                                   INTRKG    135
  350 CONTINUE                                                          INTRKG    136
      IF(NSVC.NE.0)CALL DESVC(HDD)                                      INTRKG    137
      IF(NRANI.NE.0)CALL DERAN(HDD)                                     INTRKG    138
      IF(NTCPS.NE.0)CALL DESTP(HDD)                                     INTRKG    139
      IF(NSDB.NE.0) CALL DESDB(HDD)                                     INTRKG    140
      IF(IR.EQ.5)THEN                                                   INTRKG    141
         IF(KRESUL) KVOLT=1                                             INTRKG    142
         CALL NETSOL(H,KVOLT,1,IPREF,IIL,NRSTEP)                        INTRKG    143
         RETURN                                                         INTRKG    144
      ELSE                                                              INTRKG    145
         I1=0                                                           INTRKG    146
         CALL NETSOL(H,KVOLT,1,IPREF,IIL,I1)                            INTRKG    147
      ENDIF                                                             INTRKG    148
      IR=2                                                              INTRKG    149
      IF(ICOUNT.LT.2)GOTO 340                                           INTRKG    150
C                                                                       INTRKG    151
C     CHECK STOL                                                        INTRKG    152
C                                                                       INTRKG    153
      IF(STOLMX.GT.STOL.AND.ICOUNT.LT.50)GOTO 340                       INTRKG    154
C      WRITE(IUD6,1000) ICOUNT,TS,STOLMX,STOL                           INTRKG    155
      IF(ICOUNT.GE.50)THEN                                              INTRKG    156
      MSG='INTRKG: STOP BLANK'                                          INTRKG    157
      CALL ASTOP(MSG,18)                                                INTRKG    158
      ENDIF                                                             INTRKG    159
      IR=5                                                              INTRKG    160
      GOTO 350                                                          INTRKG    161
C                                                                       INTRKG    162
 1000 FORMAT (1X,I10,3E10.5)                                            INTRKG    163
C                                                                       INTRKG    164
      END                                                               INTRKG    165
C                                                                       INTRKG    166
      SUBROUTINE ICOEF                                                  INTRKG    167
CD                                                                      INTRKG    168
CD    THIS ROUTINE SETS UP THE INTERGRATION COEFFICIENTS ACCORDING      INTRKG    169
CD    TO THE INTERGRATION METHOD USED BY THE EXPLICT INTEGRATION        INTRKG    170
CD    METHODS.                                                          INTRKG    171
CD                                                                      INTRKG    172
      INCLUDE 'CNB9.INS'                                                INTRKG    173
      GOTO ( 100, 150, 170, 170, 170), INTMTH                           INTRKG    174
  100 CONTINUE                                                          INTRKG    175
      GOTO ( 110, 120, 130, 140), IR                                    INTRKG    176
  110 A1=0.5                                                            INTRKG    177
      B1=2.0                                                            INTRKG    178
      C1=A1                                                             INTRKG    179
      RETURN                                                            INTRKG    180
  120 A1=A2                                                             INTRKG    181
      B1=1.0                                                            INTRKG    182
      C1=A1                                                             INTRKG    183
      RETURN                                                            INTRKG    184
  130 A1=A3                                                             INTRKG    185
      B1=1.                                                             INTRKG    186
      C1=A1                                                             INTRKG    187
      RETURN                                                            INTRKG    188
  140 A1=1./6.                                                          INTRKG    189
      B1=2.                                                             INTRKG    190
      C1=.5                                                             INTRKG    191
      RETURN                                                            INTRKG    192
  150 CONTINUE                                                          INTRKG    193
      A1=0.50000000                                                     INTRKG    194
      GOTO ( 170, 170, 170, 160),IR                                     INTRKG    195
  160 CONTINUE                                                          INTRKG    196
      A1=1.0/3.0                                                        INTRKG    197
      B1=1.0/6.0                                                        INTRKG    198
  170 RETURN                                                            INTRKG    199
      END                                                               INTRKG    200
C                                                                       INTRKG    201
      SUBROUTINE RKG (NORDER,IOFSET,VX,VD,VQ,VQQ,STEP)                  INTRKG    202
CD                                                                      INTRKG    203
CD    THIS IS THE ROUTINE THAT UPDATES THE STATES BASED ON THEIR        INTRKG    204
CD    VALUES AND THE ASSOCIATED DERIVATIVES IN EXPLICT INTEGRATION      INTRKG    205
CD    METHODS.                                                          INTRKG    206
CD                                                                      INTRKG    207
      INCLUDE 'PARX.INS'                                                INTRKG    208
      INCLUDE 'CNFLAG.INS'                                              INTRKG    209
      INCLUDE 'CNB9.INS'                                                INTRKG    210
      INCLUDE 'CNUNIT.INS'                                              INTRKG    211
      DIMENSION VX(*),VD(*),VQ(*),VQQ(*)                                INTRKG    212
      EQUIVALENCE (XVD,IDV)                                             INTRKG    213
C                                                                       INTRKG    214
*IF DEBUG                                                               INTRKG    215
      LDEB=(JDEB(61).NE.0)                                              INTRKG    216
*ENDIF                                                                  INTRKG    217
C                                                                       INTRKG    218
      JOFSET=IOFSET                                                     INTRKG    219
C                                                                       INTRKG    220
      GOTO ( 110, 130, 200, 200, 200, 250), INTMTH                      INTRKG    221
C                                                                       INTRKG    222
  110 CONTINUE                                                          INTRKG    223
*IF DEBUG                                                               INTRKG    224
      IF(LDEB)WRITE(IUD6,1000)(I,VD(I),VX(IOFSET+I)                     INTRKG    225
     &,VQ(IOFSET+I),I=1,NORDER)                                         INTRKG    226
*ENDIF                                                                  INTRKG    227
      DO 120 I=1,NORDER                                                 INTRKG    228
      JOFSET=JOFSET+1                                                   INTRKG    229
      CXX=A1*(VD(I)-B1*VQ(JOFSET))                                      INTRKG    230
      VX(JOFSET)=VX(JOFSET)+STEP*CXX                                    INTRKG    231
      VQ(JOFSET)=VQ(JOFSET)+3.0*CXX-C1*VD(I)                            INTRKG    232
  120 CONTINUE                                                          INTRKG    233
*IF DEBUG                                                               INTRKG    234
      IF(LDEB)WRITE(IUD6,1000)(I,VD(I),VX(IOFSET+I)                     INTRKG    235
     &,VQ(IOFSET+I),I=1,NORDER)                                         INTRKG    236
*ENDIF                                                                  INTRKG    237
      RETURN                                                            INTRKG    238
  130 CONTINUE                                                          INTRKG    239
      GOTO ( 140, 140, 160, 180), IR                                    INTRKG    240
  140 CONTINUE                                                          INTRKG    241
      DO 150 I=1,NORDER                                                 INTRKG    242
      JOFSET=JOFSET+1                                                   INTRKG    243
      CXX=STEP*A1*VD(I)                                                 INTRKG    244
      VX(JOFSET)=VX(JOFSET)+CXX                                         INTRKG    245
      VQ(JOFSET)=CXX                                                    INTRKG    246
  150 CONTINUE                                                          INTRKG    247
      RETURN                                                            INTRKG    248
  160 CONTINUE                                                          INTRKG    249
      DO 170 I=1,NORDER                                                 INTRKG    250
      JOFSET=JOFSET+1                                                   INTRKG    251
      CXX=STEP*VD(I)                                                    INTRKG    252
      VX(JOFSET)=VX(JOFSET)-VQ(JOFSET)+CXX                              INTRKG    253
      VQQ(JOFSET)=CXX                                                   INTRKG    254
C      WRITE(6,27) I,II,STEP,CXX,VX(IOFSET+I),VQQ(IOFSET+I),VQ(IOFSET+I)INTRKG    255
C 27    FORMAT(1X,'STEP2',I5,I10,6E12.5)                                INTRKG    256
  170 CONTINUE                                                          INTRKG    257
      RETURN                                                            INTRKG    258
  180 CONTINUE                                                          INTRKG    259
      DO 190 I=1,NORDER                                                 INTRKG    260
      JOFSET=JOFSET+1                                                   INTRKG    261
      CXX=STEP*VD(I)                                                    INTRKG    262
      VX(JOFSET)=VX(JOFSET)-A1*VQQ(JOFSET)+B1*CXX+A1*VQ(JOFSET)         INTRKG    263
C      WRITE(6,34) I,II,STEP,CXX,VX(IOFSET+I),VQQ(IOFSET+I),VQ(IOFSET+I)INTRKG    264
C 34    FORMAT(1X,'STEP3',I5,I10,6E12.5)                                INTRKG    265
  190 CONTINUE                                                          INTRKG    266
      RETURN                                                            INTRKG    267
  200 CONTINUE                                                          INTRKG    268
      GOTO ( 210, 210, 210, 230), IR                                    INTRKG    269
  210 CONTINUE                                                          INTRKG    270
      DO 220 I=1,NORDER                                                 INTRKG    271
      JOFSET=JOFSET+1                                                   INTRKG    272
      CXX=VD(I)*STEP                                                    INTRKG    273
      VQ(JOFSET)=0.5*CXX                                                INTRKG    274
      VX(JOFSET)=VX(JOFSET)+CXX                                         INTRKG    275
  220 CONTINUE                                                          INTRKG    276
      RETURN                                                            INTRKG    277
  230 CONTINUE                                                          INTRKG    278
      DO 240 I=1,NORDER                                                 INTRKG    279
      JOFSET=JOFSET+1                                                   INTRKG    280
      CXX=0.5*STEP*VD(I)                                                INTRKG    281
      VX(JOFSET)=VX(JOFSET)-VQ(JOFSET)+CXX                              INTRKG    282
  240 CONTINUE                                                          INTRKG    283
      RETURN                                                            INTRKG    284
  250 CONTINUE                                                          INTRKG    285
      IF(IR.EQ.1)THEN                                                   INTRKG    286
         DO 260 I=1,NORDER                                              INTRKG    287
         JOFSET=JOFSET+1                                                INTRKG    288
         VQ(JOFSET)=VX(JOFSET)+STEP*VD(I)                               INTRKG    289
         VX(JOFSET)=VQ(JOFSET)+STEP*VD(I)                               INTRKG    290
  260    CONTINUE                                                       INTRKG    291
         RETURN                                                         INTRKG    292
      ENDIF                                                             INTRKG    293
      DO 270 I=1,NORDER                                                 INTRKG    294
      JOFSET=JOFSET+1                                                   INTRKG    295
      XVD=VD(I)                                                         INTRKG    296
      IF(IDV.NE.0)THEN                                                  INTRKG    297
         VXI=VQ(JOFSET)+STEP*VD(I)                                      INTRKG    298
         DVXI=ABS((VX(JOFSET)-VXI)/VXI)                                 INTRKG    299
C         WRITE(IUD6,1010) I,VXI,DVXI,VX(IOFSET+I)                      INTRKG    300
C     &   ,VQ(IOFSET+I),VD(I),STOLMX                                    INTRKG    301
         IF(ABS(VXI).GT.1.E-3)THEN                                      INTRKG    302
            IF(DVXI.GT.STOLMX) STOLMX=DVXI                              INTRKG    303
         ENDIF                                                          INTRKG    304
         VX(JOFSET)=VXI                                                 INTRKG    305
      ENDIF                                                             INTRKG    306
  270 CONTINUE                                                          INTRKG    307
      RETURN                                                            INTRKG    308
C                                                                       INTRKG    309
 1000 FORMAT(1X,'RKG:I,DX,X,Q ',/,3(I5,3G12.5))                         INTRKG    310
 1010 FORMAT(1X,'RKG',I10,6E12.5)                                       INTRKG    311
      END                                                               INTRKG    312
