CFPRIME ASTA9                                                           ASTA9       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 ASTA9(ISTATE)                                          ASTA9       3
CD                                                                      ASTA9       4
CD    TO FORMULATE THE JACOBIAN MATRICES OF TYPE 9 STABILIZER.          ASTA9       5
CD                                                                      ASTA9       6
      INCLUDE 'PARX.INS'                                                ASTA9       7
      INCLUDE 'CNB8.INS'                                                ASTA9       8
      INCLUDE 'CNEXC.INS'                                               ASTA9       9
      INCLUDE 'CNSTAB.INS'                                              ASTA9      10
      INCLUDE 'CNPARX.INS'                                              ASTA9      11
      INCLUDE 'CNMDAT.INS'                                              ASTA9      12
      INCLUDE 'CNXSTA.INS'                                              ASTA9      13
      INCLUDE 'CNMSTA.INS'                                              ASTA9      14
      INCLUDE 'CNUDMB.INS'                                              ASTA9      15
      INCLUDE 'CNABAK.INS'                                              ASTA9      16
C                                                                       ASTA9      17
      DIMENSION FS21(10),FS32(3),GS11(6),GS21(6),GS22(10),CS11(6),      ASTA9      18
     *          CS22(3)                                                 ASTA9      19
C                                                                       ASTA9      20
C     ARRAY INITIALIZATION                                              ASTA9      21
C                                                                       ASTA9      22
      DO 5 I=1,10                                                       ASTA9      23
         FS21(I)=0.0                                                    ASTA9      24
         GS22(I)=0.0                                                    ASTA9      25
   5  CONTINUE                                                          ASTA9      26
      DO 10 I=1,6                                                       ASTA9      27
         GS21(I)=0.0                                                    ASTA9      28
         CS11(I)=0.0                                                    ASTA9      29
  10  CONTINUE                                                          ASTA9      30
C                                                                       ASTA9      31
      ISUBB=0                                                           ASTA9      32
      HS21=0.0                                                          ASTA9      33
      HS22=0.0                                                          ASTA9      34
      T2I=0.0                                                           ASTA9      35
      T1=0.0                                                            ASTA9      36
      T3T4=0.0                                                          ASTA9      37
      T1T2=0.0                                                          ASTA9      38
C                                                                       ASTA9      39
C     SUBSCRIPTS                                                        ASTA9      40
C                                                                       ASTA9      41
      ISUB1=IDDAT(JS+30)                                                ASTA9      42
      ISUB2=IDDAT(JS+31)                                                ASTA9      43
      ISUB3=IDDAT(JS+32)                                                ASTA9      44
      ISUB4=IDDAT(JS+33)                                                ASTA9      45
      ISUB5=IDDAT(JS+34)                                                ASTA9      46
      ISUB6=IDDAT(JS+35)                                                ASTA9      47
      ISUB7=IDDAT(JS+36)                                                ASTA9      48
      ISUB8=IDDAT(JS+37)                                                ASTA9      49
      ISUB9=IDDAT(JS+38)                                                ASTA9      50
      ISUB10=IDDAT(JS+39)                                               ASTA9      51
C                                                                       ASTA9      52
      IES1=0                                                            ASTA9      53
      IES2=0                                                            ASTA9      54
      IES3=0                                                            ASTA9      55
C                                                                       ASTA9      56
      INTYP1=IDDAT(JS+2)                                                ASTA9      57
      INTYP2=IDDAT(JS+4)                                                ASTA9      58
C                                                                       ASTA9      59
      CS1=DDAT(JS+15)                                                   ASTA9      60
      CS2=DDAT(JS+19)                                                   ASTA9      61
      CS3=DDAT(JS+23)                                                   ASTA9      62
C                                                                       ASTA9      63
C     DETERMINE G1 AND G2                                               ASTA9      64
C                                                                       ASTA9      65
      IF (ISUB3.EQ.0) THEN                                              ASTA9      66
         G1=1.0                                                         ASTA9      67
      ELSE                                                              ASTA9      68
         G1=0.0                                                         ASTA9      69
      END IF                                                            ASTA9      70
      IF (ISUB6.EQ.0) THEN                                              ASTA9      71
         G2=1.0                                                         ASTA9      72
      ELSE                                                              ASTA9      73
         G2=0.0                                                         ASTA9      74
      END IF                                                            ASTA9      75
C                                                                       ASTA9      76
C--------------------------                                             ASTA9      77
C                                                                       ASTA9      78
C     FIRST PART -- S1                                                  ASTA9      79
C                                                                       ASTA9      80
C--------------------------                                             ASTA9      81
C                                                                       ASTA9      82
C     T5 BLOCK (OPTIONAL)                                               ASTA9      83
C                                                                       ASTA9      84
      IF (ISUB1.NE.0) THEN                                              ASTA9      85
C                                                                       ASTA9      86
         IES1=IES1+1                                                    ASTA9      87
         T5I=1.0/DDAT(JS+16)                                            ASTA9      88
         A(ISUB1,ISUB1)=-T5I                                            ASTA9      89
C                                                                       ASTA9      90
         INSTA(IES1,1)=ISUB1                                            ASTA9      91
         RINSTA(IES1,1)=CS1*T5I                                         ASTA9      92
         RINSTA(IES1,2)=0.0                                             ASTA9      93
C                                                                       ASTA9      94
         GS11(IES1)=-G1                                                 ASTA9      95
C                                                                       ASTA9      96
      END IF                                                            ASTA9      97
C                                                                       ASTA9      98
C     T6 BLOCK (OPTIONAL)                                               ASTA9      99
C                                                                       ASTA9     100
      IF (ISUB2.NE.0) THEN                                              ASTA9     101
C                                                                       ASTA9     102
         IES1=IES1+1                                                    ASTA9     103
         T6I=1.0/DDAT(JS+17)                                            ASTA9     104
         A(ISUB2,ISUB2)=-T6I                                            ASTA9     105
         IF (ISUB1.NE.0) A(ISUB2,ISUB1)=-T6I                            ASTA9     106
C                                                                       ASTA9     107
         INSTA(IES1,1)=ISUB2                                            ASTA9     108
         RINSTA(IES1,1)=CS1*T6I                                         ASTA9     109
         RINSTA(IES1,2)=0.0                                             ASTA9     110
C                                                                       ASTA9     111
         GS11(IES1)=-G1                                                 ASTA9     112
C                                                                       ASTA9     113
      END IF                                                            ASTA9     114
C                                                                       ASTA9     115
C     T7 BLOCK (OPTIONAL)                                               ASTA9     116
C                                                                       ASTA9     117
      IF (ISUB3.NE.0) THEN                                              ASTA9     118
C                                                                       ASTA9     119
         IES1=IES1+1                                                    ASTA9     120
         T7I=1.0/DDAT(JS+18)                                            ASTA9     121
         A(ISUB3,ISUB3)=-T7I                                            ASTA9     122
         IF (ISUB1.NE.0) A(ISUB3,ISUB1)=-T7I                            ASTA9     123
         IF (ISUB2.NE.0) A(ISUB3,ISUB2)=-T7I                            ASTA9     124
C                                                                       ASTA9     125
         INSTA(IES1,1)=ISUB3                                            ASTA9     126
         RINSTA(IES1,1)=CS1*T7I                                         ASTA9     127
         RINSTA(IES1,2)=0.0                                             ASTA9     128
C                                                                       ASTA9     129
         GS11(IES1)=1.0-G1                                              ASTA9     130
C                                                                       ASTA9     131
      END IF                                                            ASTA9     132
C                                                                       ASTA9     133
C     T8 BLOCK (OPTIONAL)                                               ASTA9     134
C                                                                       ASTA9     135
      IF (ISUB4.NE.0) THEN                                              ASTA9     136
C                                                                       ASTA9     137
         IES1=IES1+1                                                    ASTA9     138
         T8I=1.0/DDAT(JS+20)                                            ASTA9     139
         A(ISUB4,ISUB4)=-T8I                                            ASTA9     140
C                                                                       ASTA9     141
         INSTA(IES1,1)=ISUB4                                            ASTA9     142
         RINSTA(IES1,1)=0.0                                             ASTA9     143
         RINSTA(IES1,2)=T8I                                             ASTA9     144
c                                                                       ASTA9     145
         GS11(IES1)=-G2*CS2*CS3                                         ASTA9     146
C                                                                       ASTA9     147
      END IF                                                            ASTA9     148
C                                                                       ASTA9     149
C     T9 BLOCK (OPTIONAL)                                               ASTA9     150
C                                                                       ASTA9     151
      IF (ISUB5.NE.0) THEN                                              ASTA9     152
C                                                                       ASTA9     153
         IES1=IES1+1                                                    ASTA9     154
         T9I=1.0/DDAT(JS+21)                                            ASTA9     155
         A(ISUB5,ISUB5)=-T9I                                            ASTA9     156
         IF (ISUB4.NE.0) A(ISUB5,ISUB4)=-T9I                            ASTA9     157
C                                                                       ASTA9     158
         INSTA(IES1,1)=ISUB5                                            ASTA9     159
         RINSTA(IES1,1)=0.0                                             ASTA9     160
         RINSTA(IES1,2)=T9I                                             ASTA9     161
c                                                                       ASTA9     162
         GS11(IES1)=-G2*CS2*CS3                                         ASTA9     163
C                                                                       ASTA9     164
      END IF                                                            ASTA9     165
C                                                                       ASTA9     166
C     T10 BLOCK (OPTIONAL)                                              ASTA9     167
C                                                                       ASTA9     168
      IF (ISUB6.NE.0) THEN                                              ASTA9     169
C                                                                       ASTA9     170
         IES1=IES1+1                                                    ASTA9     171
         T10I=1.0/DDAT(JS+22)                                           ASTA9     172
         A(ISUB6,ISUB6)=-T10I                                           ASTA9     173
         IF (ISUB5.NE.0) A(ISUB6,ISUB5)=-CS2*T10I                       ASTA9     174
         IF (ISUB4.NE.0) A(ISUB6,ISUB4)=-CS2*T10I                       ASTA9     175
C                                                                       ASTA9     176
         INSTA(IES1,1)=ISUB6                                            ASTA9     177
         RINSTA(IES1,1)=0.0                                             ASTA9     178
         RINSTA(IES1,2)=CS2*T10I                                        ASTA9     179
C                                                                       ASTA9     180
         GS11(IES1)=CS3*(1.0-G2)                                        ASTA9     181
C                                                                       ASTA9     182
      END IF                                                            ASTA9     183
C                                                                       ASTA9     184
      ISTAT2=ISTATE+IES1                                                ASTA9     185
      HS11=G1*CS1                                                       ASTA9     186
      HS12=G2*CS2*CS3                                                   ASTA9     187
C                                                                       ASTA9     188
C--------------------------                                             ASTA9     189
C                                                                       ASTA9     190
C     SECOND PART -- S2 (ALL BLOCKS OPTIONAL)                           ASTA9     191
C                                                                       ASTA9     192
C--------------------------                                             ASTA9     193
C                                                                       ASTA9     194
      NEXP=IDDAT(JS+5)                                                  ASTA9     195
      MEXP=IDDAT(JS+6)                                                  ASTA9     196
C                                                                       ASTA9     197
      IF (ISUB7.EQ.0) GOTO 55                                           ASTA9     198
C                                                                       ASTA9     199
      TFD=DDAT(JS+24)                                                   ASTA9     200
      TFGI=1.0/DDAT(JS+25)                                              ASTA9     201
      TFDTFG=TFD*TFGI                                                   ASTA9     202
C                                                                       ASTA9     203
      IF (NEXP.GT.MEXP) THEN                                            ASTA9     204
C                                                                       ASTA9     205
C     NORMAL CASE                                                       ASTA9     206
C                                                                       ASTA9     207
         NEXPA=NEXP-MEXP                                                ASTA9     208
C                                                                       ASTA9     209
C     BLOCKS IN PART A (PURILY LAG BLOCKS)                              ASTA9     210
C                                                                       ASTA9     211
         ISUBA=ISTAT2                                                   ASTA9     212
         DO 20 I=1,NEXPA                                                ASTA9     213
            IES2=IES2+1                                                 ASTA9     214
            ISUBA=ISUBA+1                                               ASTA9     215
            A(ISUBA,ISUBA)=-TFGI                                        ASTA9     216
            A(ISUBA+1,ISUBA)=TFGI                                       ASTA9     217
  20     CONTINUE                                                       ASTA9     218
         FS21(1)=TFGI                                                   ASTA9     219
C                                                                       ASTA9     220
         IF (MEXP.EQ.0) THEN                                            ASTA9     221
C                                                                       ASTA9     222
            A(ISUBA+1,ISUBA)=0.0                                        ASTA9     223
            GS22(IES2)=1.0                                              ASTA9     224
C                                                                       ASTA9     225
         ELSE                                                           ASTA9     226
C                                                                       ASTA9     227
C     BLOCKS IN PART B (LEAD/LAG BLOCKS)                                ASTA9     228
C                                                                       ASTA9     229
            GAIN1=TFGI                                                  ASTA9     230
            GAIN2=TFGI*(1.0-TFDTFG)                                     ASTA9     231
            ISUBB=ISUBA                                                 ASTA9     232
            DO 30 I=1,MEXP                                              ASTA9     233
               IES2=IES2+1                                              ASTA9     234
               ISUBB=ISUBB+1                                            ASTA9     235
               A(ISUBB,ISUBB)=-TFGI                                     ASTA9     236
               A(ISUBB,ISUBA)=GAIN1                                     ASTA9     237
               GAIN1=GAIN1*TFDTFG                                       ASTA9     238
               GAIN3=GAIN2                                              ASTA9     239
               IWS1=ISUBB                                               ASTA9     240
               DO 40 J=I+1,MEXP                                         ASTA9     241
                  IWS1=IWS1+1                                           ASTA9     242
                  A(IWS1,ISUBB)=GAIN3                                   ASTA9     243
                  GAIN3=GAIN3*TFDTFG                                    ASTA9     244
  40           CONTINUE                                                 ASTA9     245
  30        CONTINUE                                                    ASTA9     246
C                                                                       ASTA9     247
C     GS22 ARRAY                                                        ASTA9     248
C                                                                       ASTA9     249
            GS22(IES2)=1.0-TFDTFG                                       ASTA9     250
            GAIN1=TFDTFG                                                ASTA9     251
            DO 45 I=IES2-1,ISUBA-ISTAT2+1,-1                            ASTA9     252
               GS22(I)=GS22(I+1)*TFDTFG                                 ASTA9     253
               GAIN1=GAIN1*TFDTFG                                       ASTA9     254
  45        CONTINUE                                                    ASTA9     255
            GS22(ISUBA-ISTAT2)=GAIN1                                    ASTA9     256
C                                                                       ASTA9     257
         END IF                                                         ASTA9     258
C                                                                       ASTA9     259
C     HS2 ARRAY                                                         ASTA9     260
C                                                                       ASTA9     261
         HS21=0.0                                                       ASTA9     262
         HS22=0.0                                                       ASTA9     263
C                                                                       ASTA9     264
C     FS21*GS11 TERM IN STATE EQUATION                                  ASTA9     265
C                                                                       ASTA9     266
         DO 50 I=1,IES1                                                 ASTA9     267
            A(ISUB7,ISTATE+I)=FS21(1)*GS11(I)                           ASTA9     268
  50     CONTINUE                                                       ASTA9     269
C                                                                       ASTA9     270
C     FS21*HS1 TERM FOR INPUT SIGNALS                                   ASTA9     271
C                                                                       ASTA9     272
         INSTA(IES1+1,1)=ISUB7                                          ASTA9     273
         RINSTA(IES1+1,1)=FS21(1)*HS11                                  ASTA9     274
         RINSTA(IES1+1,2)=FS21(1)*HS12                                  ASTA9     275
         DO 52 I=2,IES2                                                 ASTA9     276
            INSTA(IES1+I,1)=ISUB7+I-1                                   ASTA9     277
            RINSTA(IES1+I,1)=0.0                                        ASTA9     278
            RINSTA(IES1+I,2)=0.0                                        ASTA9     279
  52     CONTINUE                                                       ASTA9     280
C                                                                       ASTA9     281
      ELSE                                                              ASTA9     282
C                                                                       ASTA9     283
C     DEFECTIVE CASE 1                                                  ASTA9     284
C                                                                       ASTA9     285
         GAIN1=TFGI                                                     ASTA9     286
         GAIN2=TFGI*(1.0-TFDTFG)                                        ASTA9     287
         ISUBB=ISTAT2                                                   ASTA9     288
         DO 60 I=1,NEXP                                                 ASTA9     289
            IES2=IES2+1                                                 ASTA9     290
            ISUBB=ISUBB+1                                               ASTA9     291
            A(ISUBB,ISUBB)=-TFGI                                        ASTA9     292
            FS21(IES2)=GAIN1                                            ASTA9     293
            GAIN1=GAIN1*TFDTFG                                          ASTA9     294
            GAIN3=GAIN2                                                 ASTA9     295
            IWS1=ISUBB                                                  ASTA9     296
            DO 70 J=I+1,NEXP                                            ASTA9     297
               IWS1=IWS1+1                                              ASTA9     298
               A(IWS1,ISUBB)=GAIN3                                      ASTA9     299
               GAIN3=GAIN3*TFDTFG                                       ASTA9     300
  70        CONTINUE                                                    ASTA9     301
  60     CONTINUE                                                       ASTA9     302
C                                                                       ASTA9     303
C     GS22 ARRAY                                                        ASTA9     304
C                                                                       ASTA9     305
         GS22(IES2)=1.0-TFDTFG                                          ASTA9     306
         GAIN1=TFDTFG                                                   ASTA9     307
         DO 75 I=IES2-1,1,-1                                            ASTA9     308
            GS22(I)=GS22(I+1)*TFDTFG                                    ASTA9     309
            GAIN1=GAIN1*TFDTFG                                          ASTA9     310
  75     CONTINUE                                                       ASTA9     311
C                                                                       ASTA9     312
C     GS21 ARRAY                                                        ASTA9     313
C                                                                       ASTA9     314
         DO 76 I=1,IES1                                                 ASTA9     315
            GS21(I)=GAIN1*GS11(I)                                       ASTA9     316
  76     CONTINUE                                                       ASTA9     317
C                                                                       ASTA9     318
C     HS2 ARRAY                                                         ASTA9     319
C                                                                       ASTA9     320
         HS21=GAIN1*HS11                                                ASTA9     321
         HS22=GAIN1*HS12                                                ASTA9     322
C                                                                       ASTA9     323
C                                                                       ASTA9     324
C     FS21*GS11 TERM IN STATE EQUATION                                  ASTA9     325
C                                                                       ASTA9     326
         DO 80 I=1,IES2                                                 ASTA9     327
            IWS1=ISTAT2+I                                               ASTA9     328
            DO 90 J=1,IES1                                              ASTA9     329
               A(IWS1,ISTATE+J)=FS21(I)*GS11(J)                         ASTA9     330
  90        CONTINUE                                                    ASTA9     331
  80     CONTINUE                                                       ASTA9     332
C                                                                       ASTA9     333
C     FS21*HS1 TERM FOR INPUT SIGNALS                                   ASTA9     334
C                                                                       ASTA9     335
         IWS1=ISTAT2                                                    ASTA9     336
         DO 100 I=1,IES2                                                ASTA9     337
            IWS1=IWS1+1                                                 ASTA9     338
            INSTA(IES1+I,1)=IWS1                                        ASTA9     339
            RINSTA(IES1+I,1)=FS21(I)*HS11                               ASTA9     340
            RINSTA(IES1+I,2)=FS21(I)*HS12                               ASTA9     341
 100     CONTINUE                                                       ASTA9     342
C                                                                       ASTA9     343
      END IF                                                            ASTA9     344
C                                                                       ASTA9     345
  55  CONTINUE                                                          ASTA9     346
C                                                                       ASTA9     347
C--------------------------                                             ASTA9     348
C                                                                       ASTA9     349
C     THIRD PART -- S3                                                  ASTA9     350
C                                                                       ASTA9     351
C--------------------------                                             ASTA9     352
C                                                                       ASTA9     353
C     T11, T12 BLOCK (OPTIONAL)                                         ASTA9     354
C                                                                       ASTA9     355
      IES12=IES1+IES2                                                   ASTA9     356
      GAIN1=G2*CS2                                                      ASTA9     357
      GAIN2=1.0                                                         ASTA9     358
      IF (ISUB8.NE.0) THEN                                              ASTA9     359
C                                                                       ASTA9     360
         IES3=IES3+1                                                    ASTA9     361
         T12I=1.0/DDAT(JS+8)                                            ASTA9     362
         GAIN1=GAIN1*T12I                                               ASTA9     363
         A(ISUB8,ISUB8)=-T12I                                           ASTA9     364
         IF (ISUB4.NE.0) A(ISUB8,ISUB4)=GAIN1                           ASTA9     365
         IF (ISUB5.NE.0) A(ISUB8,ISUB5)=GAIN1                           ASTA9     366
         IF (ISUB6.NE.0) A(ISUB8,ISUB6)=-T12I*(1.0-G2)                  ASTA9     367
C                                                                       ASTA9     368
         FS32(IES3)=T12I                                                ASTA9     369
         INSTA(IES12+IES3,1)=ISUB8                                      ASTA9     370
         IF (NEXP.GT.MEXP) THEN                                         ASTA9     371
            RINSTA(IES12+IES3,1)=0.0                                    ASTA9     372
            RINSTA(IES12+IES3,2)=-GAIN1                                 ASTA9     373
         ELSE                                                           ASTA9     374
            RINSTA(IES12+IES3,1)=T12I*HS21                              ASTA9     375
            RINSTA(IES12+IES3,2)=-GAIN1+T12I*HS22                       ASTA9     376
         END IF                                                         ASTA9     377
C                                                                       ASTA9     378
         GAIN1=GAIN1*DDAT(JS+7)                                         ASTA9     379
         GAIN2=DDAT(JS+7)*T12I                                          ASTA9     380
C                                                                       ASTA9     381
      END IF                                                            ASTA9     382
C                                                                       ASTA9     383
C     T1, T2 BLOCK (OPTIONAL)                                           ASTA9     384
C                                                                       ASTA9     385
      IF (ISUB9.NE.0) THEN                                              ASTA9     386
C                                                                       ASTA9     387
         IES3=IES3+1                                                    ASTA9     388
         T2I=1.0/DDAT(JS+10)                                            ASTA9     389
         T1=DDAT(JS+9)                                                  ASTA9     390
         T1T2=T1*T2I                                                    ASTA9     391
         GAIN1=GAIN1*T2I                                                ASTA9     392
         GAIN2=GAIN2*T2I                                                ASTA9     393
         A(ISUB9,ISUB9)=-T2I                                            ASTA9     394
         IF (ISUB8.NE.0) A(ISUB9,ISUB8)=-GAIN2                          ASTA9     395
         IF (ISUB4.NE.0) A(ISUB9,ISUB4)=GAIN1                           ASTA9     396
         IF (ISUB5.NE.0) A(ISUB9,ISUB5)=GAIN1                           ASTA9     397
         IF (ISUB6.NE.0) A(ISUB9,ISUB6)=-GAIN2*(1.0-G2)                 ASTA9     398
C                                                                       ASTA9     399
         FS32(IES3)=GAIN2                                               ASTA9     400
         INSTA(IES12+IES3,1)=ISUB9                                      ASTA9     401
         IF (NEXP.GT.MEXP) THEN                                         ASTA9     402
            RINSTA(IES12+IES3,1)=0.0                                    ASTA9     403
            RINSTA(IES12+IES3,2)=-GAIN1                                 ASTA9     404
         ELSE                                                           ASTA9     405
            RINSTA(IES12+IES3,1)=GAIN2*HS21                             ASTA9     406
            RINSTA(IES12+IES3,2)=-GAIN1+GAIN2*HS22                      ASTA9     407
         END IF                                                         ASTA9     408
C                                                                       ASTA9     409
         GAIN1=GAIN1*T1                                                 ASTA9     410
         GAIN2=GAIN2*T1                                                 ASTA9     411
C                                                                       ASTA9     412
      END IF                                                            ASTA9     413
C                                                                       ASTA9     414
C     T3, T4 BLOCK (OPTIONAL)                                           ASTA9     415
C                                                                       ASTA9     416
      IF (ISUB10.NE.0) THEN                                             ASTA9     417
C                                                                       ASTA9     418
         IES3=IES3+1                                                    ASTA9     419
         T4I=1.0/DDAT(JS+12)                                            ASTA9     420
         T3=DDAT(JS+11)                                                 ASTA9     421
         T3T4=T3*T4I                                                    ASTA9     422
         GAIN1=GAIN1*T4I                                                ASTA9     423
         GAIN2=GAIN2*T4I                                                ASTA9     424
         A(ISUB10,ISUB10)=-T4I                                          ASTA9     425
         IF (ISUB9.NE.0) A(ISUB10,ISUB9)=T4I*(1.0-T1*T2I)               ASTA9     426
         IF (ISUB8.NE.0) A(ISUB10,ISUB8)=-GAIN2                         ASTA9     427
         IF (ISUB4.NE.0) A(ISUB10,ISUB4)=GAIN1                          ASTA9     428
         IF (ISUB5.NE.0) A(ISUB10,ISUB5)=GAIN1                          ASTA9     429
         IF (ISUB6.NE.0) A(ISUB10,ISUB6)=-GAIN2*(1.0-G2)                ASTA9     430
C                                                                       ASTA9     431
         FS32(IES3)=GAIN2                                               ASTA9     432
         INSTA(IES12+IES3,1)=ISUB10                                     ASTA9     433
         IF (NEXP.GT.MEXP) THEN                                         ASTA9     434
            RINSTA(IES12+IES3,1)=0.0                                    ASTA9     435
            RINSTA(IES12+IES3,2)=-GAIN1                                 ASTA9     436
        ELSE                                                            ASTA9     437
            RINSTA(IES12+IES3,1)=GAIN2*HS21                             ASTA9     438
            RINSTA(IES12+IES3,2)=-GAIN1+GAIN2*HS22                      ASTA9     439
         END IF                                                         ASTA9     440
C                                                                       ASTA9     441
         GAIN1=GAIN1*T3                                                 ASTA9     442
         GAIN2=GAIN2*T3                                                 ASTA9     443
C                                                                       ASTA9     444
      END IF                                                            ASTA9     445
C                                                                       ASTA9     446
C     FS32*GS21 TERM IN STATE EQUATION                                  ASTA9     447
C                                                                       ASTA9     448
      IF (NEXP.GT.MEXP) GOTO 110                                        ASTA9     449
C                                                                       ASTA9     450
      IWS1=ISUBB                                                        ASTA9     451
      DO 120 I=1,IES3                                                   ASTA9     452
         IWS1=IWS1+1                                                    ASTA9     453
         DO 130 J=1,IES1                                                ASTA9     454
            A(IWS1,ISTATE+J)=A(IWS1,ISTATE+J)+FS32(I)*GS21(J)           ASTA9     455
 130     CONTINUE                                                       ASTA9     456
 120  CONTINUE                                                          ASTA9     457
C                                                                       ASTA9     458
 110  CONTINUE                                                          ASTA9     459
C                                                                       ASTA9     460
C     FS32*GS22 TERM IN STATE EQUATION                                  ASTA9     461
C                                                                       ASTA9     462
      IWS1=ISUBB                                                        ASTA9     463
      DO 140 I=1,IES3                                                   ASTA9     464
         IWS1=IWS1+1                                                    ASTA9     465
         DO 150 J=1,IES2                                                ASTA9     466
            A(IWS1,ISTAT2+J)=FS32(I)*GS22(J)                            ASTA9     467
 150     CONTINUE                                                       ASTA9     468
 140  CONTINUE                                                          ASTA9     469
C                                                                       ASTA9     470
C     OUTPUT EQUATION                                                   ASTA9     471
C                                                                       ASTA9     472
      IF (ISUB4.NE.0) CS11(ISUB4-ISTATE)=GAIN1                          ASTA9     473
      IF (ISUB5.NE.0) CS11(ISUB5-ISTATE)=GAIN1                          ASTA9     474
      IF (ISUB6.NE.0) CS11(ISUB6-ISTATE)=-GAIN2*(1.0-G2)                ASTA9     475
      IF (ISUB8.NE.0) CS22(ISUB8-ISUBB)=-GAIN2                          ASTA9     476
      IF (ISUB9.NE.0) CS22(ISUB9-ISUBB)=T3T4*(1.0-T1T2)                 ASTA9     477
      IF (ISUB10.NE.0) CS22(ISUB10-ISUBB)=1.0-T3T4                      ASTA9     478
C                                                                       ASTA9     479
      DO 170 J=1,IES1                                                   ASTA9     480
         IOUTS(J)=ISTATE+J                                              ASTA9     481
         ROUTS(J)=CS11(J)+GAIN2*GS21(J)                                 ASTA9     482
 170  CONTINUE                                                          ASTA9     483
      DO 180 J=1,IES2                                                   ASTA9     484
         IOUTS(IES1+J)=ISTAT2+J                                         ASTA9     485
         ROUTS(IES1+J)=GAIN2*GS22(J)                                    ASTA9     486
 180  CONTINUE                                                          ASTA9     487
      DO 190 J=1,IES3                                                   ASTA9     488
         IOUTS(IES12+J)=ISUBB+J                                         ASTA9     489
         ROUTS(IES12+J)=CS22(J)                                         ASTA9     490
 190  CONTINUE                                                          ASTA9     491
      DSTB1=GAIN2*HS21                                                  ASTA9     492
      DSTB2=GAIN1+GAIN2*HS22                                            ASTA9     493
      IE=IES12+IES3                                                     ASTA9     494
C                                                                       ASTA9     495
C     TORSIONAL FILTER                                                  ASTA9     496
C                                                                       ASTA9     497
      IF (IFLTRN.NE.0) CALL ASTF1(ISTATE)                               ASTA9     498
C                                                                       ASTA9     499
C     INTERCONNECTION WITH EXCITER                                      ASTA9     500
C                                                                       ASTA9     501
      IE1=IE                                                            ASTA9     502
      IF (IEXN.NE.50) THEN                                              ASTA9     503
C                                                                       ASTA9     504
      DO 200 I=1,4                                                      ASTA9     505
         IF (IUST(I).EQ.0) GOTO 250                                     ASTA9     506
         IWS1=IUST(I)                                                   ASTA9     507
         WS1=GUST(I)                                                    ASTA9     508
         DO 210 J=1,IE                                                  ASTA9     509
            IWS2=IOUTS(J)                                               ASTA9     510
            A(IWS1,IWS2)=ROUTS(J)*WS1                                   ASTA9     511
 210     CONTINUE                                                       ASTA9     512
         IE1=IE1+1                                                      ASTA9     513
         INSTA(IE1,1)=IWS1                                              ASTA9     514
         RINSTA(IE1,1)=DSTB1*WS1                                        ASTA9     515
         RINSTA(IE1,2)=DSTB2*WS1                                        ASTA9     516
 200  CONTINUE                                                          ASTA9     517
C                                                                       ASTA9     518
      ELSE                                                              ASTA9     519
C                                                                       ASTA9     520
C     CONNECTION WITH A USER DEFIEND EXCITER                            ASTA9     521
C                                                                       ASTA9     522
      MSEXC=MSUDM(1,1)                                                  ASTA9     523
      IWS1=ISTATE-MSEXC                                                 ASTA9     524
      DO 220 I=1,MSEXC+1                                                ASTA9     525
         IWS2=IWS1+I                                                    ASTA9     526
         IF (I.GT.MSEXC) IWS2=3                                         ASTA9     527
         DO 230 J=1,IE                                                  ASTA9     528
            IWS3=IOUTS(J)                                               ASTA9     529
            A(IWS2,IWS3)=ROUTS(J)*BXVS(I)                               ASTA9     530
 230     CONTINUE                                                       ASTA9     531
         IE1=IE1+1                                                      ASTA9     532
         INSTA(IE1,1)=IWS2                                              ASTA9     533
         RINSTA(IE1,1)=DSTB1*BXVS(I)                                    ASTA9     534
         RINSTA(IE1,2)=DSTB2*BXVS(I)                                    ASTA9     535
 220  CONTINUE                                                          ASTA9     536
C                                                                       ASTA9     537
      END IF                                                            ASTA9     538
C                                                                       ASTA9     539
 250  CONTINUE                                                          ASTA9     540
      INSTA(IE1+1,1)=0                                                  ASTA9     541
C                                                                       ASTA9     542
C     INCOPORATE WITH INPUT SIGNALS                                     ASTA9     543
C                                                                       ASTA9     544
      CALL ASGNAL(ISTATE,INTYP1,INTYP2)                                 ASTA9     545
C                                                                       ASTA9     546
      ISTATE=ISTATE+IE                                                  ASTA9     547
C                                                                       ASTA9     548
      RETURN                                                            ASTA9     549
      END                                                               ASTA9     550
