CFPRIME CGENLN                                                          CGENLN      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 CGENLN(IPATH,EPD,EPQ,CPD,CPQ,XPDN,IDMSN)               CGENLN      3
CD                                                                      CGENLN      4
CD    TO FORMULATE JACOBIAN MATRICES OF CLASSICAL MACHINE FOR USE IN    CGENLN      5
CD    IMPLICIT INTEGRATION METHOD.                                      CGENLN      6
CD                                                                      CGENLN      7
      INCLUDE 'PARX.INS'                                                CGENLN      8
      INCLUDE 'CNB3.INS'                                                CGENLN      9
      INCLUDE 'CNB4.INS'                                                CGENLN     10
      INCLUDE 'CNB5.INS'                                                CGENLN     11
      INCLUDE 'CNB8.INS'                                                CGENLN     12
      INCLUDE 'CNB9.INS'                                                CGENLN     13
      INCLUDE 'CNB19.INS'                                               CGENLN     14
      INCLUDE 'CNEXC.INS'                                               CGENLN     15
      INCLUDE 'CNUDM.INS'                                               CGENLN     16
      INCLUDE 'CNMDAT.INS'                                              CGENLN     17
      INCLUDE 'CNYVAR.INS'                                              CGENLN     18
      INCLUDE 'CNMYVA.INS'                                              CGENLN     19
      INCLUDE 'CNVOLT.INS'                                              CGENLN     20
      INCLUDE 'CNXSTA.INS'                                              CGENLN     21
      INCLUDE 'CNMSTA.INS'                                              CGENLN     22
      INCLUDE 'CNPREV.INS'                                              CGENLN     23
      INCLUDE 'CNXDOT.INS'                                              CGENLN     24
      INCLUDE 'CNJCOB.INS'                                              CGENLN     25
      INCLUDE 'CNIMPR.INS'                                              CGENLN     26
      INCLUDE 'CNPRGV.INS'                                              CGENLN     27
      INCLUDE 'CNABAK.INS'                                              CGENLN     28
C                                                                       CGENLN     29
      IF (IGVN .GT. 40 .AND. IGVN.LT.50) GOTO 15                        CGENLN     30
      IF (IGVN.NE.0) THEN                                               CGENLN     31
         DO 10 I=1,IDMSN                                                CGENLN     32
            DO 20 J=1,IDMSN                                             CGENLN     33
               A(I,J)=0.0                                               CGENLN     34
   20       CONTINUE                                                    CGENLN     35
            B(I,1)=0.0                                                  CGENLN     36
            B(I,2)=0.0                                                  CGENLN     37
            AK(1,I)=0.0                                                 CGENLN     38
            AK(2,I)=0.0                                                 CGENLN     39
   10    CONTINUE                                                       CGENLN     40
      END IF                                                            CGENLN     41
C                                                                       CGENLN     42
 15   CONTINUE                                                          CGENLN     43
C                                                                       CGENLN     44
      HM=DDAT(JG+1)                                                     CGENLN     45
      DAMP=DDAT(JG+2)                                                   CGENLN     46
C                                                                       CGENLN     47
      EPDI=EPD-CPQ/XPDN                                                 CGENLN     48
      EPQI=EPQ+CPD/XPDN                                                 CGENLN     49
C                                                                       CGENLN     50
C     FORM A, B, AK MATRICES (YD == 0 SINCE X'D HAS BEEN INCLUDED       CGENLN     51
C     INTO THE NETWORK)                                                 CGENLN     52
C                                                                       CGENLN     53
      EDQ2=(EPDI*EPDI+EPQI*EPQI)*XPDN                                   CGENLN     54
      EDQI=EPQI*CPD-EPDI*CPQ                                            CGENLN     55
C                                                                       CGENLN     56
      A(1,1)=1.0+CEFJM*DAMP*HM                                          CGENLN     57
C                                                                       CGENLN     58
      SDAMP=0.0                                                         CGENLN     59
      IF (LSDAMP) A(1,1)=A(1,1)+CEFJM*SDAMP                             CGENLN     60
C                                                                       CGENLN     61
      A(1,2)=-CEFJM*HM*(EDQI-EDQ2)                                      CGENLN     62
      A(2,1)=-CEFJM                                                     CGENLN     63
      A(2,2)=1.0                                                        CGENLN     64
      AK(1,2)=-EPDI*XPDN                                                CGENLN     65
      AK(2,2)=-EPQI*XPDN                                                CGENLN     66
      B(1,1)=-CEFJM*HM*AK(2,2)                                          CGENLN     67
      B(1,2)=CEFJM*HM*AK(1,2)                                           CGENLN     68
C                                                                       CGENLN     69
      IF (IGVN.EQ.0 .OR. IGVN.EQ.41 .OR. IGVN.EQ.42                     CGENLN     70
     1    .OR. IGVN.EQ.43 .OR. IGVN.EQ.44 .OR.                          CGENLN     71
     2    IGVN.EQ.45 .OR. IGVN.EQ.46) THEN                              CGENLN     72
C                                                                       CGENLN     73
         WS1=A(1,1)-A(1,2)*A(2,1)                                       CGENLN     74
         WS1=1.0/WS1                                                    CGENLN     75
         A(1,2)=-A(1,2)*WS1                                             CGENLN     76
         A(2,1)=-A(2,1)*WS1                                             CGENLN     77
         A(2,2)=A(1,1)*WS1                                              CGENLN     78
         A(1,1)=WS1                                                     CGENLN     79
C                                                                       CGENLN     80
C     STORE A, B, AK MATRICES                                           CGENLN     81
C                                                                       CGENLN     82
         AJCOB(IAIDEX+1)=A(1,1)                                         CGENLN     83
         AJCOB(IAIDEX+2)=A(1,2)                                         CGENLN     84
         AJCOB(IAIDEX+3)=A(2,1)                                         CGENLN     85
         AJCOB(IAIDEX+4)=A(2,2)                                         CGENLN     86
C                                                                       CGENLN     87
         BJCOB(IBIDEX+1)=B(1,1)                                         CGENLN     88
         BJCOB(IBIDEX+2)=B(1,2)                                         CGENLN     89
C                                                                       CGENLN     90
         CJCOB(ICIDEX+1)=AK(1,2)                                        CGENLN     91
         CJCOB(ICIDEX+2)=AK(2,2)                                        CGENLN     92
C                                                                       CGENLN     93
      ELSE                                                              CGENLN     94
C                                                                       CGENLN     95
         ISTATE=2                                                       CGENLN     96
         JSTATE=MSTATE(5,N)                                             CGENLN     97
         JGG=JCONTA(2,N)                                                CGENLN     98
         JYP=MYVAR(5,N)                                                 CGENLN     99
         ICOLBV=1                                                       CGENLN    100
C                                                                       CGENLN    101
         IF (IGVN.EQ.50) THEN                                           CGENLN    102
C                                                                       CGENLN    103
C     USER DEFINED GOVERNORS                                            CGENLN    104
C                                                                       CGENLN    105
            BASPRN=DDAT(JG+3)/BASPC                                     CGENLN    106
            BASERT=BASER(JYP+3)                                         CGENLN    107
            JEU=JE7-JE1+2                                               CGENLN    108
            DO 790 I=1,JEU                                              CGENLN    109
               UDAT(I)=DDAT(I+JE1-1)                                    CGENLN    110
  790       CONTINUE                                                    CGENLN    111
            IWS1=JGG+2                                                  CGENLN    112
            JE1=JE1-IWS1                                                CGENLN    113
            JE2=JE2-IWS1                                                CGENLN    114
            JE3=JE3-IWS1                                                CGENLN    115
            JE4=JE4-IWS1                                                CGENLN    116
            JE5=JE5-IWS1                                                CGENLN    117
            JE6=JE6-IWS1                                                CGENLN    118
            JE7=JE7-IWS1                                                CGENLN    119
C                                                                       CGENLN    120
            CALL AGOV(ISTATE,HM)                                        CGENLN    121
C                                                                       CGENLN    122
            ISTATE=ISTATE+MSUDM(1,4)                                    CGENLN    123
            GOTO 900                                                    CGENLN    124
         END IF                                                         CGENLN    125
C                                                                       CGENLN    126
C                     GOVERNOR TYPES                                    CGENLN    127
C                1   2   3   4   5   6   7   8   9  10                  CGENLN    128
         GOTO (801,801,900,804,900,806,807,808,900,900,                 CGENLN    129
C                                                                       CGENLN    130
C               11  12  13  14  15  16  17  18  19  20                  CGENLN    131
     *         900,900,900,900,900,900,900,900,900,820,                 CGENLN    132
C                                                                       CGENLN    133
C               21  22                                                  CGENLN    134
     *         821,822), IGVN                                           CGENLN    135
C                                                                       CGENLN    136
C     TYPE 1 AND 2                                                      CGENLN    137
C                                                                       CGENLN    138
  801    CALL AGOV1(ISTATE,HM)                                          CGENLN    139
         GOTO 900                                                       CGENLN    140
C                                                                       CGENLN    141
C     TYPE 4                                                            CGENLN    142
C                                                                       CGENLN    143
  804    CALL AGOV4(ISTATE,HM)                                          CGENLN    144
         GOTO 900                                                       CGENLN    145
C                                                                       CGENLN    146
C     TYPE 6                                                            CGENLN    147
C                                                                       CGENLN    148
  806    CALL AGOV6(ISTATE,HM)                                          CGENLN    149
         GOTO 900                                                       CGENLN    150
C                                                                       CGENLN    151
C     TYPE 7                                                            CGENLN    152
C                                                                       CGENLN    153
  807    CALL AGOV7(ISTATE,HM)                                          CGENLN    154
         GOTO 900                                                       CGENLN    155
C                                                                       CGENLN    156
C     TYPE 8                                                            CGENLN    157
C                                                                       CGENLN    158
  808    CALL AGOV8(ISTATE,HM)                                          CGENLN    159
         GOTO 900                                                       CGENLN    160
C                                                                       CGENLN    161
C     TYPE 20                                                           CGENLN    162
C                                                                       CGENLN    163
  820    CALL AGOV20(ISTATE,HM)                                         CGENLN    164
         GOTO 900                                                       CGENLN    165
C                                                                       CGENLN    166
C     TYPE 21                                                           CGENLN    167
C                                                                       CGENLN    168
  821    CALL AGOV21(ISTATE,HM)                                         CGENLN    169
         GOTO 900                                                       CGENLN    170
C                                                                       CGENLN    171
C     TYPE 22                                                           CGENLN    172
C                                                                       CGENLN    173
  822    CALL AGOV22(ISTATE,HM)                                         CGENLN    174
C                                                                       CGENLN    175
  900    CONTINUE                                                       CGENLN    176
C                                                                       CGENLN    177
C     STORE A, B, AK MATRICES                                           CGENLN    178
C                                                                       CGENLN    179
         NAIDEX=IAIDEX                                                  CGENLN    180
         NBIDEX=IBIDEX                                                  CGENLN    181
         NCIDEX=ICIDEX                                                  CGENLN    182
         DO 990 I=1,ISTATE                                              CGENLN    183
            DO 1000 J=1,ISTATE                                          CGENLN    184
               IF (IA(I,J).EQ.0) GOTO 1000                              CGENLN    185
               IF (I.LE.2.AND.J.LE.2) GOTO 1000                         CGENLN    186
               A(I,J)=-CEFJM*A(I,J)                                     CGENLN    187
 1000       CONTINUE                                                    CGENLN    188
            IF (I.LE.2) GOTO 990                                        CGENLN    189
            A(I,I)=A(I,I)+1.0                                           CGENLN    190
            B(I,1)=-CEFJM*B(I,1)                                        CGENLN    191
            B(I,2)=-CEFJM*B(I,2)                                        CGENLN    192
  990    CONTINUE                                                       CGENLN    193
C                                                                       CGENLN    194
C     PERFORM LU FACTORIZATION FOR A                                    CGENLN    195
C                                                                       CGENLN    196
         CALL LUDCM(ISTATE)                                             CGENLN    197
C                                                                       CGENLN    198
C     COMPUTE INVERSE(A)*B                                              CGENLN    199
C                                                                       CGENLN    200
         CALL FBSUBA(ISTATE)                                            CGENLN    201
C                                                                       CGENLN    202
C     STORE AK IN CJCOB ARRAY                                           CGENLN    203
C                                                                       CGENLN    204
         DO 840 J=1,ISTATE                                              CGENLN    205
            NCIDEX=NCIDEX+1                                             CGENLN    206
            CJCOB(NCIDEX)=-AK(1,J)                                      CGENLN    207
            CJCOB(NCIDEX+ISTATE)=-AK(2,J)                               CGENLN    208
 840     CONTINUE                                                       CGENLN    209
         NCIDEX=NCIDEX+ISTATE                                           CGENLN    210
C                                                                       CGENLN    211
C     STORE A AND B IN AJCOB AND BJCOB ARRAYS                           CGENLN    212
C                                                                       CGENLN    213
         DO 850 I=1,ISTATE                                              CGENLN    214
            DO 860 J=1,ISTATE                                           CGENLN    215
               NAIDEX=NAIDEX+1                                          CGENLN    216
               AJCOB(NAIDEX)=A(I,J)                                     CGENLN    217
  860       CONTINUE                                                    CGENLN    218
  850    CONTINUE                                                       CGENLN    219
C                                                                       CGENLN    220
         DO 866 I=1,ISTATE                                              CGENLN    221
            NBIDEX=NBIDEX+2                                             CGENLN    222
            BJCOB(NBIDEX-1)=B(I,1)                                      CGENLN    223
            BJCOB(NBIDEX)=B(I,2)                                        CGENLN    224
  866    CONTINUE                                                       CGENLN    225
C                                                                       CGENLN    226
      END IF                                                            CGENLN    227
C                                                                       CGENLN    228
      RETURN                                                            CGENLN    229
      END                                                               CGENLN    230
