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