CFPRIME RKG1                                                            RKG1        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 RKG1(NORDER,IOFFL,IOFFJ,VX,VD,VQ,VQQ,STEP)             RKG1        3
CD                                                                      RKG1        4
CD    THIS IS THE ROUTINE THAT UPDATES THE STATES BASED ON THEIR        RKG1        5
CD    VALUES AND THE ASSOCIATED DERIVATIVES IN EXPLICT INTEGRATION      RKG1        6
CD    METHODS, FOR USER DEFINED MODELS.                                 RKG1        7
CD                                                                      RKG1        8
      INCLUDE 'PARX.INS'                                                RKG1        9
      INCLUDE 'CNFLAG.INS'                                              RKG1       10
      INCLUDE 'CNB9.INS'                                                RKG1       11
      INCLUDE 'CNB91.INS'                                               RKG1       12
      INCLUDE 'CNUNIT.INS'                                              RKG1       13
      DIMENSION VX(*),VD(*),VQ(*),VQQ(*)                                RKG1       14
      EQUIVALENCE (XVD,IDV)                                             RKG1       15
C                                                                       RKG1       16
*IF DEBUG                                                               RKG1       17
      LDEB=(JDEB(61).NE.0)                                              RKG1       18
*ENDIF                                                                  RKG1       19
C                                                                       RKG1       20
      JOFSET=IOFFJ                                                      RKG1       21
      I=0                                                               RKG1       22
      GOTO ( 110, 130, 200, 200, 200, 250), INTMTH                      RKG1       23
  110 CONTINUE                                                          RKG1       24
*IF DEBUG                                                               RKG1       25
      IF(LDEB)WRITE(IUD6,1000)(I,VD(IOFFL+I),VX(IOFFJ+I)                RKG1       26
     &,VQ(IOFFJ+I),I=1,NORDER)                                          RKG1       27
*ENDIF                                                                  RKG1       28
      DO 120 I=1,NORDER                                                 RKG1       29
      JOFSET=JOFSET+1                                                   RKG1       30
      CXX=A11*(VD(IOFFL+I)-B11*VQ(JOFSET))                              RKG1       31
      VX(JOFSET)=VX(JOFSET)+STEP*CXX                                    RKG1       32
      VQ(JOFSET)=VQ(JOFSET)+3.0*CXX-C11*VD(IOFFL+I)                     RKG1       33
  120 CONTINUE                                                          RKG1       34
*IF DEBUG                                                               RKG1       35
      IF(LDEB)WRITE(IUD6,1000)(I,VD(IOFFL+I),VX(IOFFJ+I)                RKG1       36
     &,VQ(IOFFJ+I),I=1,NORDER)                                          RKG1       37
*ENDIF                                                                  RKG1       38
      RETURN                                                            RKG1       39
  130 CONTINUE                                                          RKG1       40
      GOTO ( 140, 140, 160, 180), IR1                                   RKG1       41
  140 CONTINUE                                                          RKG1       42
      DO 150 I=1,NORDER                                                 RKG1       43
      JOFSET=JOFSET+1                                                   RKG1       44
      CXX=STEP*A11*VD(+IOFFL+I)                                         RKG1       45
      VX(JOFSET)=VX(JOFSET)+CXX                                         RKG1       46
      VQ(JOFSET)=CXX                                                    RKG1       47
  150 CONTINUE                                                          RKG1       48
      RETURN                                                            RKG1       49
  160 CONTINUE                                                          RKG1       50
      DO 170 I=1,NORDER                                                 RKG1       51
      JOFSET=JOFSET+1                                                   RKG1       52
      CXX=STEP*VD(IOFFL+I)                                              RKG1       53
      VX(JOFSET)=VX(JOFSET)-VQ(JOFSET)+CXX                              RKG1       54
      VQQ(JOFSET)=CXX                                                   RKG1       55
  170 CONTINUE                                                          RKG1       56
      RETURN                                                            RKG1       57
  180 CONTINUE                                                          RKG1       58
      DO 190 I=1,NORDER                                                 RKG1       59
      JOFSET=JOFSET+1                                                   RKG1       60
      CXX=STEP*VD(IOFFL+I)                                              RKG1       61
      VX(JOFSET)=VX(JOFSET)-A11*VQQ(JOFSET)+B11*CXX+A11*VQ(JOFSET)      RKG1       62
  190 CONTINUE                                                          RKG1       63
      RETURN                                                            RKG1       64
  200 CONTINUE                                                          RKG1       65
      GOTO ( 210, 210, 210, 230), IR1                                   RKG1       66
  210 CONTINUE                                                          RKG1       67
      DO 220 I=1,NORDER                                                 RKG1       68
      JOFSET=JOFSET+1                                                   RKG1       69
      CXX=VD(IOFFL+I)*STEP                                              RKG1       70
      VQ(JOFSET)=0.5*CXX                                                RKG1       71
      VX(JOFSET)=VX(JOFSET)+CXX                                         RKG1       72
  220 CONTINUE                                                          RKG1       73
      RETURN                                                            RKG1       74
  230 CONTINUE                                                          RKG1       75
      DO 240 I=1,NORDER                                                 RKG1       76
      JOFSET=JOFSET+1                                                   RKG1       77
      CXX=0.5*STEP*VD(IOFFL+I)                                          RKG1       78
      VX(JOFSET)=VX(JOFSET)-VQ(JOFSET)+CXX                              RKG1       79
  240 CONTINUE                                                          RKG1       80
      RETURN                                                            RKG1       81
  250 CONTINUE                                                          RKG1       82
      IF(IR1.EQ.1)THEN                                                  RKG1       83
         DO 260 I=1,NORDER                                              RKG1       84
         JOFSET=JOFSET+1                                                RKG1       85
         VQ(JOFSET)=VX(JOFSET)+STEP*VD(IOFFL+I)                         RKG1       86
         VX(JOFSET)=VQ(JOFSET)+STEP*VD(IOFFL+I)                         RKG1       87
  260    CONTINUE                                                       RKG1       88
         RETURN                                                         RKG1       89
      ENDIF                                                             RKG1       90
      DO 270 I=1,NORDER                                                 RKG1       91
      JOFSET=JOFSET+1                                                   RKG1       92
      XVD=VD(IOFFL+I)                                                   RKG1       93
      IF(IDV.NE.0)THEN                                                  RKG1       94
         VXI=VQ(JOFSET)+STEP*VD(IOFFL+I)                                RKG1       95
         DVXI=ABS((VX(JOFSET)-VXI)/VXI)                                 RKG1       96
         WRITE(IUD6,1010) I,VXI,DVXI,VX(IOFFJ+I)                        RKG1       97
     &   ,VQ(IOFFJ+I),VD(IOFFL+I),STOLMX                                RKG1       98
         IF(ABS(VXI).GT.1.E-3)THEN                                      RKG1       99
            IF(DVXI.GT.STOLMX) STOLMX=DVXI                              RKG1      100
         ENDIF                                                          RKG1      101
         VX(JOFSET)=VXI                                                 RKG1      102
      ENDIF                                                             RKG1      103
  270 CONTINUE                                                          RKG1      104
      RETURN                                                            RKG1      105
C                                                                       RKG1      106
 1000 FORMAT(1X,'RKG:I,DX,X,Q ',/,3(I5,3G12.5))                         RKG1      107
 1010 FORMAT(1X,'RKG',I10,6E12.5)                                       RKG1      108
      END                                                               RKG1      109
      SUBROUTINE ICOEF1                                                 RKG1      110
CD                                                                      RKG1      111
CD    ROUTINE TO SET UP COEFFICIENT FOR DIFFERNT ORDER OF               RKG1      112
CD    EXPLICT INTEGAGTION. USED BY THE USER DEFINED MODELS              RKG1      113
CD                                                                      RKG1      114
      INCLUDE 'CNB9.INS'                                                RKG1      115
      INCLUDE 'CNB91.INS'                                               RKG1      116
      GOTO ( 100, 150, 170, 170, 170), INTMTH                           RKG1      117
  100 CONTINUE                                                          RKG1      118
      GOTO ( 110, 120, 130, 140), IR1                                   RKG1      119
  110 A11=0.5                                                           RKG1      120
      B11=2.0                                                           RKG1      121
      C11=A11                                                           RKG1      122
      RETURN                                                            RKG1      123
  120 A11=A2                                                            RKG1      124
      B11=1.0                                                           RKG1      125
      C11=A11                                                           RKG1      126
      RETURN                                                            RKG1      127
  130 A11=A3                                                            RKG1      128
      B11=1.                                                            RKG1      129
      C11=A11                                                           RKG1      130
      RETURN                                                            RKG1      131
  140 A11=1./6.                                                         RKG1      132
      B11=2.                                                            RKG1      133
      C11=.5                                                            RKG1      134
      RETURN                                                            RKG1      135
  150 CONTINUE                                                          RKG1      136
      A11=0.50000000                                                    RKG1      137
      GOTO ( 170, 170, 170, 160),IR1                                    RKG1      138
  160 CONTINUE                                                          RKG1      139
      A11=1.0/3.0                                                       RKG1      140
      B11=1.0/6.0                                                       RKG1      141
  170 RETURN                                                            RKG1      142
      END                                                               RKG1      143
