CFPRIME AGOV                                                            AGOV        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 AGOV(ISTATE,HM)                                        AGOV        3
CD                                                                      AGOV        4
CD    TO FORMULATE THE JACOBIAN MATRICES OF USER DEFINED GOVERNOR FOR   AGOV        5
CD    USE IN THE IMPLICIT INTEGRATION METHOD.                           AGOV        6
CD                                                                      AGOV        7
CD    THE INTERCONNECTION OF THE JACOBIANS OF THE USER DEFINED GOVERNOR AGOV        8
CD    WITH THOSE OF THE MACHINE IS DONE IN SUBROUTINE DGENLN.           AGOV        9
CD                                                                      AGOV       10
      INCLUDE 'PARX.INS'                                                AGOV       11
      INCLUDE 'CNPT.INS'                                                AGOV       12
      INCLUDE 'CNB5.INS'                                                AGOV       13
      INCLUDE 'CNB8.INS'                                                AGOV       14
      INCLUDE 'CNB19.INS'                                               AGOV       15
      INCLUDE 'CNEXC.INS'                                               AGOV       16
      INCLUDE 'CNGDAT.INS'                                              AGOV       17
      INCLUDE 'CNFLAG.INS'                                              AGOV       18
      INCLUDE 'CNVOLT.INS'                                              AGOV       19
      INCLUDE 'CNUDM.INS'                                               AGOV       20
      INCLUDE 'CNUDMA.INS'                                              AGOV       21
      INCLUDE 'CNUDMB.INS'                                              AGOV       22
      INCLUDE 'CNUNIT.INS'                                              AGOV       23
      INCLUDE 'CNABAK.INS'                                              AGOV       24
C                                                                       AGOV       25
      LDEB=.FALSE.                                                      AGOV       26
C                                                                       AGOV       27
      VM=VALIN(4)                                                       AGOV       28
      VD=VALIN(6)                                                       AGOV       29
      VQ=VALIN(7)                                                       AGOV       30
      CR=VALIN(8)*BASPRN                                                AGOV       31
      CI=VALIN(9)*BASPRN                                                AGOV       32
C                                                                       AGOV       33
C     FORM: DEL U0=XUI*DEL I+XUV*DEL V+XUY*DEL YB+XUW*DEL W+XUTM*DEL TM AGOV       34
C                                                                       AGOV       35
      DO 50 I=1,20                                                      AGOV       36
      DO 40 J=1,NXUDB                                                   AGOV       37
      XUY(I,J)=0.0                                                      AGOV       38
  40  CONTINUE                                                          AGOV       39
      DO 50 J=1,LOUTP                                                   AGOV       40
      XUI(I,J)=0.0                                                      AGOV       41
      XUV(I,J)=0.0                                                      AGOV       42
  50  CONTINUE                                                          AGOV       43
C      CALL FMOVE(0,XUI,XUI,20*LOUTP)                                   AGOV       44
C      CALL FMOVE(0,XUV,XUV,20*LOUTP)                                   AGOV       45
C      CALL FMOVE(0,XUY,XUY,20*NXUDB)                                   AGOV       46
      CALL FMOVE(0,XUVS,XUVS,20)                                        AGOV       47
      CALL FMOVE(0,XUVU,XUVU,20)                                        AGOV       48
      CALL FMOVE(0,XUW,XUW,20)                                          AGOV       49
      CALL FMOVE(0,XUIF,XUIF,20)                                        AGOV       50
      CALL FMOVE(0,XUTM,XUTM,20)                                        AGOV       51
C                                                                       AGOV       52
      IBEND=IUDAT(JE7+1)                                                AGOV       53
C                                                                       AGOV       54
      XUI(3,1)=-VD-2.0*RK*CR                                            AGOV       55
      XUI(3,2)=-VQ-2.0*RK*CI                                            AGOV       56
      XUI(8,1)=1.0                                                      AGOV       57
      XUI(9,2)=1.0                                                      AGOV       58
      XUI(10,1)=VD                                                      AGOV       59
      XUI(10,2)=VQ                                                      AGOV       60
      XUI(11,1)=VQ                                                      AGOV       61
      XUI(11,2)=-VD                                                     AGOV       62
C                                                                       AGOV       63
      XUV(3,1)=-CR                                                      AGOV       64
      XUV(3,2)=-CI                                                      AGOV       65
      XUV(4,1)=VD/VM                                                    AGOV       66
      XUV(4,2)=VQ/VM                                                    AGOV       67
      XUV(5,1)=-VQ/VM/VM                                                AGOV       68
      XUV(5,2)=VD/VM/VM                                                 AGOV       69
      XUV(6,1)=1.0                                                      AGOV       70
      XUV(7,2)=1.0                                                      AGOV       71
      XUV(10,1)=CR                                                      AGOV       72
      XUV(10,2)=CI                                                      AGOV       73
      XUV(11,1)=-CI                                                     AGOV       74
      XUV(11,2)=CR                                                      AGOV       75
C                                                                       AGOV       76
      XUTM(3)=1.0                                                       AGOV       77
      XUW(3)=-DAMPK                                                     AGOV       78
      XUW(12)=1.0                                                       AGOV       79
C                                                                       AGOV       80
C     FORM THE REMOTE BUS ARRAY AND CONTROL A B C D MATRICES            AGOV       81
C                                                                       AGOV       82
      LCYO=1                                                            AGOV       83
      LWIF=1                                                            AGOV       84
      NBUSS=1                                                           AGOV       85
      NBUSR=0                                                           AGOV       86
      NBUSR1=NBUSR                                                      AGOV       87
      CALL AUDMB(LCYO,LWIF,NBUSR,NBUSS)                                 AGOV       88
      IF (KERUDM.NE.0) GO TO 900                                        AGOV       89
      MSUDM(2,4)=NBUSR                                                  AGOV       90
      IF (NBUSR.NE.0) THEN                                              AGOV       91
         DO 100 I=1,NBUSR                                               AGOV       92
            MSUDM(I+2,4)=MBUSR(NBUSS+I)                                 AGOV       93
  100    CONTINUE                                                       AGOV       94
      END IF                                                            AGOV       95
C                                                                       AGOV       96
C     SOLVE THE CONTROL EQUATIONS                                       AGOV       97
C                                                                       AGOV       98
      LOUT=2                                                            AGOV       99
      LREM=2*NBUSR                                                      AGOV      100
      CALL AUDMC(LOUT,LCYO,LWIF,LREM)                                   AGOV      101
      IF (KERUDM.NE.0) GO TO 900                                        AGOV      102
C                                                                       AGOV      103
C     FORM: DEL XDOT = AXB*DEL X+BUI*DEL I+BUV*DEL VS+BUVR*DEL VR+      AGOV      104
C                      BUW*DEL W+BUTM*DEL TM                            AGOV      105
C                                                                       AGOV      106
C             DEL TM = CYX*DEL X+CYI*DEL I+CYV*DEL VS+CYVR*DEL VR+      AGOV      107
C                      CYW*DEL W                                        AGOV      108
C                                                                       AGOV      109
C      IF(JHPLP.NE.0) THEN                                              AGOV      110
C         IHPLP(1)=IHPLP(1)+LSTA1                                       AGOV      111
C         IHPLP(2)=IHPLP(2)+LSTA1                                       AGOV      112
C         IHPLP(3)=IHPLP(3)+LSTA1                                       AGOV      113
C      ENDIF                                                            AGOV      114
C                                                                       AGOV      115
      MSUDM(1,4)=KORD                                                   AGOV      116
      DO 110 I=1,KORD                                                   AGOV      117
      DO 110 J=1,KORD                                                   AGOV      118
         A(ISTATE+I,ISTATE+J)=AXB(I,J)                                  AGOV      119
  110 CONTINUE                                                          AGOV      120
C                                                                       AGOV      121
      MSEXC=MSUDM(1,1)                                                  AGOV      122
      MSSTA=MSUDM(1,2)                                                  AGOV      123
      MSUEL=MSUDM(1,3)                                                  AGOV      124
      IMSUDM=MSEXC+MSSTA+MSUEL                                          AGOV      125
      ICOLTM=ICOLBV                                                     AGOV      126
      DO 120 I=1,KORD                                                   AGOV      127
         A(ISTATE+I,1)=BUW(I)                                           AGOV      128
         BXTM(IMSUDM+I)=BUTM(I)                                         AGOV      129
         BC(ISTATE+I,1)=BUI(I,1)                                        AGOV      130
         BC(ISTATE+I,2)=BUI(I,2)                                        AGOV      131
         BC(ISTATE+I,1)=BUI(I,1)                                        AGOV      132
         B(ISTATE+I,2)=BUV(I,2)                                         AGOV      133
  120 CONTINUE                                                          AGOV      134
C                                                                       AGOV      135
      IF (NBUSR.NE.0) THEN                                              AGOV      136
         DO 140 I=1,NBUSR                                               AGOV      137
            ICOLBV=ICOLBV+1                                             AGOV      138
            NBR(ICOLBV)=MSUDM(J+2,4)                                    AGOV      139
            IWS1=2*ICOLBV                                               AGOV      140
            DO 150 J=1,KORD                                             AGOV      141
               B(ISTATE+J,IWS1-1)=BUVR(J,2*I-1)                         AGOV      142
               B(ISTATE+J,IWS1)=BUVR(J,2*I-1)                           AGOV      143
  150       CONTINUE                                                    AGOV      144
  140    CONTINUE                                                       AGOV      145
      END IF                                                            AGOV      146
C                                                                       AGOV      147
C     ELIMINATE DEL TM                                                  AGOV      148
C                                                                       AGOV      149
      DO 155 I=1,KORD                                                   AGOV      150
         CYX(1,I)=CYX(1,I)+CYX(2,I)+CYX(3,I)+CYX(4,I)                   AGOV      151
  155 CONTINUE                                                          AGOV      152
      DO 160 I=1,IMSUDM+KORD                                            AGOV      153
         DO 170 J=1,KORD                                                AGOV      154
            A(MT+I,ISTATE+J)=A(MT+I,ISTATE+J)+BXTM(I)*CYX(1,J)          AGOV      155
  170    CONTINUE                                                       AGOV      156
         A(I,1)=A(I,1)+BXTM(I)*CYW(1)                                   AGOV      157
         BC(I,1)=BC(I,1)+BXTM(I)*CYI(1,1)                               AGOV      158
         BC(I,2)=BC(I,2)+BXTM(I)*CYI(1,2)                               AGOV      159
         B(I,1)=B(I,1)+BXTM(I)*CYV(1,1)                                 AGOV      160
         B(I,2)=B(I,2)+BXTM(I)*CYV(1,2)                                 AGOV      161
  160 CONTINUE                                                          AGOV      162
C                                                                       AGOV      163
      DO 175 I=1,KORD                                                   AGOV      164
         A(1,ISTATE+I)=HM*CYX(1,I)                                      AGOV      165
         A(3,ISTATE+I)=A(3,ISTATE+I)+CXTM*CYX(1,I)                      AGOV      166
  175 CONTINUE                                                          AGOV      167
C                                                                       AGOV      168
      A(1,1)=A(1,1)+HM*CYW(1)                                           AGOV      169
      BC(1,1)=BC(1,1)+HM*CYI(1,1)                                       AGOV      170
      BC(1,2)=BC(1,2)+HM*CYI(1,2)                                       AGOV      171
      B(1,1)=B(1,1)+HM*CYV(1,1)                                         AGOV      172
      B(1,2)=B(1,2)+HM*CYV(1,2)                                         AGOV      173
C                                                                       AGOV      174
      A(3,1)=A(3,1)+CXTM*CYW(1)                                         AGOV      175
      BC(3,1)=BC(3,1)+CXTM*CYI(1,1)                                     AGOV      176
      BC(3,2)=BC(3,2)+CXTM*CYI(1,2)                                     AGOV      177
      B(3,1)=B(3,1)+CXTM*CYV(1,1)                                       AGOV      178
      B(3,2)=B(3,2)+CXTM*CYV(1,2)                                       AGOV      179
C                                                                       AGOV      180
      IF (NBUSR.NE.0) THEN                                              AGOV      181
         DO 180 I=1,NBUSR                                               AGOV      182
            IWS1=2*(ICOLTM+I)                                           AGOV      183
            DO 190 J=1,KORD                                             AGOV      184
               B(ISTATE+J,IWS1-1)=BUVR(J,2*I-1)                         AGOV      185
               B(ISTATE+J,IWS1)=BUVR(J,2*I-1)                           AGOV      186
  190       CONTINUE                                                    AGOV      187
  180    CONTINUE                                                       AGOV      188
      END IF                                                            AGOV      189
                                                                        AGOV      190
  900 RETURN                                                            AGOV      191
      END                                                               AGOV      192
