CFPRIME ASTA4                                                           ASTA4       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 ASTA4(ISTATE)                                          ASTA4       3
CD                                                                      ASTA4       4
CD    TO FORMULATE THE JACOBIAN MATRICES OF TYPES 4, 5 AND 6 STABILIZER.ASTA4       5
CD                                                                      ASTA4       6
      INCLUDE 'PARX.INS'                                                ASTA4       7
      INCLUDE 'CNB8.INS'                                                ASTA4       8
      INCLUDE 'CNEXC.INS'                                               ASTA4       9
      INCLUDE 'CNSTAB.INS'                                              ASTA4      10
      INCLUDE 'CNPARX.INS'                                              ASTA4      11
      INCLUDE 'CNMDAT.INS'                                              ASTA4      12
      INCLUDE 'CNXSTA.INS'                                              ASTA4      13
      INCLUDE 'CNMSTA.INS'                                              ASTA4      14
      INCLUDE 'CNUDMB.INS'                                              ASTA4      15
      INCLUDE 'CNABAK.INS'                                              ASTA4      16
C                                                                       ASTA4      17
      ISUB4=0                                                           ASTA4      18
      SWTCH2=0.0                                                        ASTA4      19
      GAIN2=0.0                                                         ASTA4      20
      GAIN3=0.0                                                         ASTA4      21
      INTYP1=IDDAT(JS+2)                                                ASTA4      22
      IE=1                                                              ASTA4      23
C                                                                       ASTA4      24
C     SUBSCRIPTS                                                        ASTA4      25
C                                                                       ASTA4      26
      ISUB1=ISTATE+1                                                    ASTA4      27
      IF (ISTABN.EQ.4) THEN                                             ASTA4      28
         ISUB2=IDDAT(JS+15)                                             ASTA4      29
         ISUB3=IDDAT(JS+16)                                             ASTA4      30
      ELSE                                                              ASTA4      31
         ISUB2=IDDAT(JS+25)                                             ASTA4      32
         ISUB3=IDDAT(JS+26)                                             ASTA4      33
         ISUB4=IDDAT(JS+27)                                             ASTA4      34
      END IF                                                            ASTA4      35
C                                                                       ASTA4      36
C     T5 BLOCK                                                          ASTA4      37
C                                                                       ASTA4      38
      T5I=1.0/DDAT(JS+4)                                                ASTA4      39
      CS=DDAT(JS+3)                                                     ASTA4      40
      A(ISUB1,ISUB1)=-T5I                                               ASTA4      41
      INSTA(1,1)=ISUB1                                                  ASTA4      42
      RINSTA(1,1)=CS*T5I                                                ASTA4      43
C                                                                       ASTA4      44
C     SECOND ORDER LEAD/LAG BLOCK                                       ASTA4      45
C                                                                       ASTA4      46
      IF (ISUB3.NE.0) THEN                                              ASTA4      47
C                                                                       ASTA4      48
C     SECOND ORDER TERM IS PRESENT                                      ASTA4      49
C                                                                       ASTA4      50
         IE=IE+2                                                        ASTA4      51
         T1=DDAT(JS+5)                                                  ASTA4      52
         T2=DDAT(JS+6)                                                  ASTA4      53
         T3=DDAT(JS+7)                                                  ASTA4      54
         T4I=1.0/DDAT(JS+8)                                             ASTA4      55
         GAIN1=T3*T4I                                                   ASTA4      56
         GAIN2=T4I*(T1-T2*GAIN1)                                        ASTA4      57
         GAIN3=T4I*(1.0-GAIN1)                                          ASTA4      58
         A(ISUB2,ISUB1)=-1.0                                            ASTA4      59
         A(ISUB2,ISUB2)=-T2*T4I                                         ASTA4      60
         A(ISUB2,ISUB3)=-T4I                                            ASTA4      61
         A(ISUB3,ISUB2)=1.0                                             ASTA4      62
         INSTA(IE-1,1)=ISUB2                                            ASTA4      63
         RINSTA(IE-1,1)=CS                                              ASTA4      64
         INSTA(IE,1)=ISUB3                                              ASTA4      65
         RINSTA(IE,1)=0.0                                               ASTA4      66
C                                                                       ASTA4      67
      ELSE IF (ISUB2.NE.0) THEN                                         ASTA4      68
C                                                                       ASTA4      69
C     FIRST ORDER TERM IS PRESENT                                       ASTA4      70
C                                                                       ASTA4      71
         IE=IE+1                                                        ASTA4      72
         T1=DDAT(JS+5)                                                  ASTA4      73
         T2I=1.0/DDAT(JS+6)                                             ASTA4      74
         GAIN1=T1*T2I                                                   ASTA4      75
         GAIN2=1.0-GAIN1                                                ASTA4      76
         A(ISUB2,ISUB1)=-T2I                                            ASTA4      77
         A(ISUB2,ISUB2)=-T2I                                            ASTA4      78
         INSTA(IE,1)=ISUB2                                              ASTA4      79
         RINSTA(IE,1)=CS*T2I                                            ASTA4      80
C                                                                       ASTA4      81
      ELSE                                                              ASTA4      82
C                                                                       ASTA4      83
C     DEFECTIVE CASE -- NOTHING FOR SECOND ORDER BLOCK                  ASTA4      84
C                                                                       ASTA4      85
         GAIN1=1.0                                                      ASTA4      86
C                                                                       ASTA4      87
      END IF                                                            ASTA4      88
C                                                                       ASTA4      89
      GAINI=GAIN1*CS                                                    ASTA4      90
C                                                                       ASTA4      91
C     TYPE 5 AND 6                                                      ASTA4      92
C                                                                       ASTA4      93
      IF (ISTABN.NE.4) THEN                                             ASTA4      94
C                                                                       ASTA4      95
C     SWITCH S1                                                         ASTA4      96
C                                                                       ASTA4      97
         IF (IDDAT(JS+23).EQ.1) THEN                                    ASTA4      98
            SWTCH1=1.0                                                  ASTA4      99
         ELSE                                                           ASTA4     100
            SWTCH1=0.0                                                  ASTA4     101
         END IF                                                         ASTA4     102
C                                                                       ASTA4     103
C     SWITCH S2                                                         ASTA4     104
C                                                                       ASTA4     105
         SWTCH2=1.0                                                     ASTA4     106
         IF (ISTABN.EQ.6.AND.IDDAT(JS+24).NE.1) SWTCH2=0.0              ASTA4     107
C                                                                       ASTA4     108
C     KANG, TANG BLOCK                                                  ASTA4     109
C                                                                       ASTA4     110
         IF (IDDAT(JS+16).EQ.0) THEN                                    ASTA4     111
            GAINI=GAINI+SWTCH2                                          ASTA4     112
         ELSE                                                           ASTA4     113
            IE=IE+1                                                     ASTA4     114
            TANGI=1.0/DDAT(JS+16)                                       ASTA4     115
            A(ISUB4,ISUB4)=-TANGI                                       ASTA4     116
            WS1=SWTCH1*DDAT(JS+15)*TANGI                                ASTA4     117
            INSTA(IE,1)=ISUB4                                           ASTA4     118
            RINSTA(IE,1)=WS1                                            ASTA4     119
         END IF                                                         ASTA4     120
      END IF                                                            ASTA4     121
C                                                                       ASTA4     122
C     OUTPUT EQUATION                                                   ASTA4     123
C                                                                       ASTA4     124
      IE1=1                                                             ASTA4     125
      IOUTS(1)=ISUB1                                                    ASTA4     126
      ROUTS(1)=-GAIN1                                                   ASTA4     127
      IF (ISUB2.NE.0) THEN                                              ASTA4     128
         IE1=IE1+1                                                      ASTA4     129
         IOUTS(IE1)=ISUB2                                               ASTA4     130
         ROUTS(IE1)=GAIN2                                               ASTA4     131
      END IF                                                            ASTA4     132
      IF (ISUB3.NE.0) THEN                                              ASTA4     133
         IE1=IE1+1                                                      ASTA4     134
         IOUTS(IE1)=ISUB3                                               ASTA4     135
         ROUTS(IE1)=GAIN3                                               ASTA4     136
      END IF                                                            ASTA4     137
      IF (ISTABN.NE.4.AND.IDDAT(JS+16).NE.0) THEN                       ASTA4     138
         IE1=IE1+1                                                      ASTA4     139
         IOUTS(IE1)=ISUB4                                               ASTA4     140
         ROUTS(IE1)=SWTCH2                                              ASTA4     141
      END IF                                                            ASTA4     142
      DSTB1=GAINI                                                       ASTA4     143
      DSTB2=0.0                                                         ASTA4     144
C                                                                       ASTA4     145
C     TORSIONAL FILTER                                                  ASTA4     146
C                                                                       ASTA4     147
      IF (IFLTRN.NE.0) CALL ASTF1(ISTATE)                               ASTA4     148
C                                                                       ASTA4     149
C     INTERCONNECTION WITH EXCITER                                      ASTA4     150
C                                                                       ASTA4     151
      IE1=IE                                                            ASTA4     152
      IF (IEXN.NE.50) THEN                                              ASTA4     153
C                                                                       ASTA4     154
      DO 10 I=1,4                                                       ASTA4     155
         IF (IUST(I).EQ.0) GOTO 100                                     ASTA4     156
         IWS1=IUST(I)                                                   ASTA4     157
         WS1=GUST(I)                                                    ASTA4     158
         DO 20 J=1,IE                                                   ASTA4     159
            IWS2=IOUTS(J)                                               ASTA4     160
            A(IWS1,IWS2)=ROUTS(J)*WS1                                   ASTA4     161
  20     CONTINUE                                                       ASTA4     162
         IE1=IE1+1                                                      ASTA4     163
         INSTA(IE1,1)=IWS1                                              ASTA4     164
         RINSTA(IE1,1)=DSTB1*WS1                                        ASTA4     165
  10  CONTINUE                                                          ASTA4     166
C                                                                       ASTA4     167
      ELSE                                                              ASTA4     168
C                                                                       ASTA4     169
C     CONNECTION WITH A USER DEFIEND EXCITER                            ASTA4     170
C                                                                       ASTA4     171
      MSEXC=MSUDM(1,1)                                                  ASTA4     172
      IWS1=ISTATE-MSEXC                                                 ASTA4     173
      DO 30 I=1,MSEXC+1                                                 ASTA4     174
         IWS2=IWS1+I                                                    ASTA4     175
         IF (I.GT.MSEXC) IWS2=3                                         ASTA4     176
         DO 40 J=1,IE                                                   ASTA4     177
            IWS3=IOUTS(J)                                               ASTA4     178
            A(IWS2,IWS3)=ROUTS(J)*BXVS(I)                               ASTA4     179
  40     CONTINUE                                                       ASTA4     180
         IE1=IE1+1                                                      ASTA4     181
         INSTA(IE1,1)=IWS2                                              ASTA4     182
         RINSTA(IE1,1)=DSTB1*BXVS(I)                                    ASTA4     183
  30  CONTINUE                                                          ASTA4     184
C                                                                       ASTA4     185
      END IF                                                            ASTA4     186
C                                                                       ASTA4     187
 100  CONTINUE                                                          ASTA4     188
      INSTA(IE1+1,1)=0                                                  ASTA4     189
C                                                                       ASTA4     190
C     INCOPORATE WITH INPUT SIGNALS                                     ASTA4     191
C                                                                       ASTA4     192
      CALL ASGNAL(ISTATE,INTYP1,0)                                      ASTA4     193
C                                                                       ASTA4     194
      ISTATE=ISTATE+IE                                                  ASTA4     195
C                                                                       ASTA4     196
      RETURN                                                            ASTA4     197
      END                                                               ASTA4     198
