CFPRIME TPXDOT                                                          TPXDOT      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 TPXDOT                                                 TPXDOT      3
CD                                                                      TPXDOT      4
CD    TO CALCULATE THE DERIVATIVES OF THE STATES OF STP FOR USE IN      TPXDOT      5
CD    THE TRAPEZOIDAL METHOD. THIS SUBROUTINE IS SIMILAR TO SUBROUTINE  TPXDOT      6
CD    DESTP. THE DIFFERENCES ARE                                        TPXDOT      7
CD                                                                      TPXDOT      8
CD    1. THE PARTS RELATED TO THE RUNGE-KUTTA METHOD ARE DELETED        TPXDOT      9
CD                                                                      TPXDOT     10
CD    2. THE JACOBIAN CLACULATION PATH IS ADDED                         TPXDOT     11
CD                                                                      TPXDOT     12
CD    3. THE STATE DERIVATIVE ARRAY, XDOT, IS HERE A GLOBAL ARRAY       TPXDOT     13
CD                                                                      TPXDOT     14
      INCLUDE 'PARX.INS'                                                TPXDOT     15
      INCLUDE 'CNPT.INS'                                                TPXDOT     16
      INCLUDE 'CNIPTR.INS'                                              TPXDOT     17
      INCLUDE 'CNB4.INS'                                                TPXDOT     18
      INCLUDE 'CNB9.INS'                                                TPXDOT     19
      INCLUDE 'CNB91.INS'                                               TPXDOT     20
      INCLUDE 'CNSTP.INS'                                               TPXDOT     21
      INCLUDE 'CNUDM.INS'                                               TPXDOT     22
      INCLUDE 'CNUDMA.INS'                                              TPXDOT     23
      INCLUDE 'CNUDMB.INS'                                              TPXDOT     24
      INCLUDE 'CNUDMK.INS'                                              TPXDOT     25
C                                                                       TPXDOT     26
      INCLUDE 'CNXSTA.INS'                                              TPXDOT     27
      INCLUDE 'CNQSTA.INS'                                              TPXDOT     28
      INCLUDE 'CNZSTA.INS'                                              TPXDOT     29
      INCLUDE 'CNMDAT.INS'                                              TPXDOT     30
      INCLUDE 'CNVOLT.INS'                                              TPXDOT     31
      INCLUDE 'CNMYVA.INS'                                              TPXDOT     32
      INCLUDE 'CNYVAR.INS'                                              TPXDOT     33
      INCLUDE 'CNGEAR.INS'                                              TPXDOT     34
      INCLUDE 'CNABAK.INS'                                              TPXDOT     35
      INCLUDE 'CNXDOT.INS'                                              TPXDOT     36
      INCLUDE 'CNJCOB.INS'                                              TPXDOT     37
      INCLUDE 'CNIMPR.INS'                                              TPXDOT     38
C                                                                       TPXDOT     39
      CHARACTER*80 MSG                                                  TPXDOT     40
      DIMENSION CDEV(4,2),VDEV(4,8),XDEV(8,2),YSEL(4,4)                 TPXDOT     41
C                                                                       TPXDOT     42
      CHARACTER*2 LCKT                                                  TPXDOT     43
      CHARACTER*4 CKID                                                  TPXDOT     44
      INTEGER*4 JCKID                                                   TPXDOT     45
      EQUIVALENCE (JCKID,CKID)                                          TPXDOT     46
C                                                                       TPXDOT     47
      LSTA=0                                                            TPXDOT     48
      X1=0.0                                                            TPXDOT     49
      X2=0.0                                                            TPXDOT     50
      Y1=0.0                                                            TPXDOT     51
      Y2=0.0                                                            TPXDOT     52
      NBUSR1=0                                                          TPXDOT     53
C                                                                       TPXDOT     54
      DO 280 N=1,NTCPS                                                  TPXDOT     55
C                                                                       TPXDOT     56
      JTP=JTPDAT(N)                                                     TPXDOT     57
      JY1=JVSTP(N)                                                      TPXDOT     58
      K1=IDDAT(JTP+1)                                                   TPXDOT     59
      K2=IDDAT(JTP+2)                                                   TPXDOT     60
      NLF1=NOLD(K1)                                                     TPXDOT     61
      K13=K1*3                                                          TPXDOT     62
      JCKID=IDDAT(JTP+3)                                                TPXDOT     63
      LCKT(1:2)=CKID(3:4)                                               TPXDOT     64
      VR1=REAL(VOLT(K1))                                                TPXDOT     65
      VI1=AIMAG(VOLT(K1))                                               TPXDOT     66
      VM1=SQRT(VR1*VR1+VI1*VI1)                                         TPXDOT     67
      VR2=REAL(VOLT(K2))                                                TPXDOT     68
      VI2=AIMAG(VOLT(K2))                                               TPXDOT     69
      VM2=SQRT(VR2*VR2+VI2*VI2)                                         TPXDOT     70
      NTTYPN=IDDAT(JTP+4)                                               TPXDOT     71
      NPTYPN=IDDAT(JTP+5)                                               TPXDOT     72
      JYTC=JVSTC(N)                                                     TPXDOT     73
      JYPS=JVSPS(N)                                                     TPXDOT     74
      ITABT=IDDAT(JTP+6)                                                TPXDOT     75
      ITABP=IDDAT(JTP+7)                                                TPXDOT     76
      ATT=DDAT(JTP+8)                                                   TPXDOT     77
      XTT=DDAT(JTP+9)                                                   TPXDOT     78
      ATP=DDAT(JTP+10)                                                  TPXDOT     79
      XTP=DDAT(JTP+11)                                                  TPXDOT     80
C                                                                       TPXDOT     81
      VALIN(7)=VM1                                                      TPXDOT     82
      VALIN(8)=VM2                                                      TPXDOT     83
      IF (VM1.GT.0.05) THEN                                             TPXDOT     84
         VA1=ATAN2(VI1,VR1)                                             TPXDOT     85
         VAGD=DDAT(JTP+17)-VA1                                          TPXDOT     86
         DDAT(JTP+17)=VA1                                               TPXDOT     87
         IF (VAGD.GT.3.15) THEN                                         TPXDOT     88
            IDDAT(JTP+16)=IDDAT(JTP+16)+1                               TPXDOT     89
         ELSE IF (VAGD.LT.-3.15) THEN                                   TPXDOT     90
            IDDAT(JTP+16)=IDDAT(JTP+16)-1                               TPXDOT     91
         END IF                                                         TPXDOT     92
         VALIN(9)=VA1+6.2831853*IDDAT(JTP+16)                           TPXDOT     93
      ELSE                                                              TPXDOT     94
         VALIN(9)=DDAT(JTP+17)+6.2831853*IDDAT(JTP+16)                  TPXDOT     95
      END IF                                                            TPXDOT     96
      IF (VM2.GT.0.05) THEN                                             TPXDOT     97
         VA2=ATAN2(VI2,VR2)                                             TPXDOT     98
         VAGD=DDAT(JTP+19)-VA2                                          TPXDOT     99
         DDAT(JTP+19)=VA2                                               TPXDOT    100
         IF (VAGD.GT.3.15) THEN                                         TPXDOT    101
            IDDAT(JTP+18)=IDDAT(JTP+18)+1                               TPXDOT    102
         ELSE IF (VAGD.LT.-3.15) THEN                                   TPXDOT    103
            IDDAT(JTP+18)=IDDAT(JTP+18)-1                               TPXDOT    104
         END IF                                                         TPXDOT    105
         VALIN(10)=VA2+6.2831853*IDDAT(JTP+18)                          TPXDOT    106
      ELSE                                                              TPXDOT    107
         VALIN(10)=DDAT(JTP+19)+6.2831853*IDDAT(JTP+18)                 TPXDOT    108
      END IF                                                            TPXDOT    109
      YSTP=DDAT(JTP+12)                                                 TPXDOT    110
      ASTP=DDAT(JTP+13)                                                 TPXDOT    111
      GSTP=YSTP*COS(ASTP)                                               TPXDOT    112
      BSTP=-YSTP*SIN(ASTP)                                              TPXDOT    113
      TSTP=DDAT(JTP+14)                                                 TPXDOT    114
      RSTP=DDAT(JTP+15)                                                 TPXDOT    115
      JTP1=JTP                                                          TPXDOT    116
      JTP=JTP+20                                                        TPXDOT    117
C                                                                       TPXDOT    118
      G11=YVAR(JY1+1)                                                   TPXDOT    119
      B11=YVAR(JY1+2)                                                   TPXDOT    120
      G12=YVAR(JY1+3)                                                   TPXDOT    121
      B12=YVAR(JY1+4)                                                   TPXDOT    122
      G21=YVAR(JY1+5)                                                   TPXDOT    123
      B21=YVAR(JY1+6)                                                   TPXDOT    124
      G22=YVAR(JY1+7)                                                   TPXDOT    125
      B22=YVAR(JY1+8)                                                   TPXDOT    126
      CR1=G11*VR1-B11*VI1+G12*VR2-B12*VI2                               TPXDOT    127
      CI1=B11*VR1+G11*VI1+B12*VR2+G12*VI2                               TPXDOT    128
      CR2=G21*VR1-B21*VI1+G22*VR2-B22*VI2                               TPXDOT    129
      CI2=B21*VR1+G21*VI1+B22*VR2+G22*VI2                               TPXDOT    130
      CM1=SQRT(CR1*CR1+CI1*CI1)                                         TPXDOT    131
      CM2=SQRT(CR2*CR2+CI2*CI2)                                         TPXDOT    132
      PM1=VR1*CR1+VI1*CI1                                               TPXDOT    133
      PM2=VR2*CR2+VI2*CI2                                               TPXDOT    134
      QM1=VI1*CR1-VR1*CI1                                               TPXDOT    135
      QM2=VI2*CR2-VR2*CI2                                               TPXDOT    136
      VALIN(1)=CM1                                                      TPXDOT    137
      VALIN(2)=CM2                                                      TPXDOT    138
      VALIN(3)=PM1                                                      TPXDOT    139
      VALIN(4)=PM2                                                      TPXDOT    140
      VALIN(15)=QM1                                                     TPXDOT    141
      VALIN(16)=QM2                                                     TPXDOT    142
C                                                                       TPXDOT    143
C     PREPARATION FOR FORMULATING JACOBIANS                             TPXDOT    144
C                                                                       TPXDOT    145
      IF (NITER.EQ.0) THEN                                              TPXDOT    146
C                                                                       TPXDOT    147
      DO 20 I=1,4                                                       TPXDOT    148
      DO 20 J=1,8                                                       TPXDOT    149
      VDEV(I,J)=0.0                                                     TPXDOT    150
  20  CONTINUE                                                          TPXDOT    151
C         CALL FMOVE(0,VDEV,VDEV,32)                                    TPXDOT    152
         CALL MOVE(0,MBUSR,MBUSR,70)                                    TPXDOT    153
         MBUSR(1)=K1                                                    TPXDOT    154
         MBUSR(2)=K2                                                    TPXDOT    155
         IROWAK=4                                                       TPXDOT    156
         ICOLBV=2                                                       TPXDOT    157
         NBR(1)=K1                                                      TPXDOT    158
         NBR(2)=K2                                                      TPXDOT    159
         LREM=0                                                         TPXDOT    160
         LCYO=1                                                         TPXDOT    161
         LWIF=0                                                         TPXDOT    162
         NBUSS=2                                                        TPXDOT    163
         NBUSR=0                                                        TPXDOT    164
C                                                                       TPXDOT    165
         IF (RSTP.GT.0.0) THEN                                          TPXDOT    166
            A1M=RSTP                                                    TPXDOT    167
            AA1=TSTP                                                    TPXDOT    168
            A2M=1.0                                                     TPXDOT    169
            AA2=0.0                                                     TPXDOT    170
            A1RE=A1M*COS(AA1)                                           TPXDOT    171
            A1IM=A1M*SIN(AA1)                                           TPXDOT    172
            TSTCN=(A1RE-1.0)/ATT                                        TPXDOT    173
            TSPSN=A1IM/ATP                                              TPXDOT    174
         ELSE                                                           TPXDOT    175
            A1M=1.0                                                     TPXDOT    176
            AA1=0.0                                                     TPXDOT    177
            A2M=-RSTP                                                   TPXDOT    178
            AA2=TSTP                                                    TPXDOT    179
            A2RE=A2M*COS(AA2)                                           TPXDOT    180
            A2IM=A2M*SIN(AA2)                                           TPXDOT    181
            TSTCN=-(A2RE-1.0)/ATT                                       TPXDOT    182
            TSPSN=-A2IM/ATP                                             TPXDOT    183
         END IF                                                         TPXDOT    184
         FACT1=A1M**2                                                   TPXDOT    185
         FACT2=A2M**2                                                   TPXDOT    186
         Y12=YSTP/A1M/A2M                                               TPXDOT    187
         AY12=ASTP+AA1-AA2                                              TPXDOT    188
         AY21=ASTP-AA1+AA2                                              TPXDOT    189
         G110=GSTP/FACT1                                                TPXDOT    190
         B110=-BSTP/FACT1                                               TPXDOT    191
         G120=-Y12*COS(AY12)                                            TPXDOT    192
         B120=-Y12*SIN(AY12)                                            TPXDOT    193
         G210=-Y12*COS(AY21)                                            TPXDOT    194
         B210=-Y12*SIN(AY21)                                            TPXDOT    195
         G220=GSTP/FACT2                                                TPXDOT    196
         B220=-BSTP/FACT2                                               TPXDOT    197
         CR1=G110*VR1-B110*VI1+G120*VR2-B120*VI2                        TPXDOT    198
         CI1=B110*VR1+G110*VI1+B120*VR2+G120*VI2                        TPXDOT    199
         CR2=G210*VR1-B210*VI1+G220*VR2-B220*VI2                        TPXDOT    200
         CI2=B210*VR1+G210*VI1+B220*VR2+G220*VI2                        TPXDOT    201
         CM1=SQRT(CR1**2+CI1**2)                                        TPXDOT    202
         CM2=SQRT(CR2**2+CI2**2)                                        TPXDOT    203
         PM1=VR1*CR1+VI1*CI1                                            TPXDOT    204
         PM2=VR2*CR2+VI2*CI2                                            TPXDOT    205
         QM1=VI1*CR1-VR1*CI1                                            TPXDOT    206
         QM2=VI2*CR2-VR2*CI2                                            TPXDOT    207
         VA1=0.0                                                        TPXDOT    208
         VA2=0.0                                                        TPXDOT    209
         IF (VM1.GT.0.05) VA1=ATAN2(VI1,VR1)                            TPXDOT    210
         IF (VM2.GT.0.05) VA2=ATAN2(VI2,VR2)                            TPXDOT    211
C                                                                       TPXDOT    212
         A1RE=1.0+ATT*(1.0-XTT)*TSTCN                                   TPXDOT    213
         A1IM=ATP*(1.0-XTP)*TSPSN                                       TPXDOT    214
         A1M=SQRT(A1RE**2+A1IM**2)                                      TPXDOT    215
         AA1=ATAN2(A1IM,A1RE)                                           TPXDOT    216
         A2RE=1.0-ATT*XTT*TSTCN                                         TPXDOT    217
         A2IM=-ATP*XTP*TSPSN                                            TPXDOT    218
         A2M=SQRT(A2RE**2+A2IM**2)                                      TPXDOT    219
         AA2=ATAN2(A2IM,A2RE)                                           TPXDOT    220
         FACT1=A1M**2                                                   TPXDOT    221
         FACT2=A2M**2                                                   TPXDOT    222
         Y12=YSTP/A1M/A2M                                               TPXDOT    223
         AY12=ASTP+AA1-AA2                                              TPXDOT    224
         AY21=ASTP-AA1+AA2                                              TPXDOT    225
         G11=GSTP/FACT1                                                 TPXDOT    226
         B11=-BSTP/FACT1                                                TPXDOT    227
         G12=-Y12*COS(AY12)                                             TPXDOT    228
         B12=-Y12*SIN(AY12)                                             TPXDOT    229
         G21=-Y12*COS(AY21)                                             TPXDOT    230
         B21=-Y12*SIN(AY21)                                             TPXDOT    231
         G22=GSTP/FACT2                                                 TPXDOT    232
         B22=-BSTP/FACT2                                                TPXDOT    233
C                                                                       TPXDOT    234
         TSLOPE=0.0                                                     TPXDOT    235
         PSLOPE=0.0                                                     TPXDOT    236
         TCOEFF=1.0                                                     TPXDOT    237
         PCOEFF=1.0                                                     TPXDOT    238
C                                                                       TPXDOT    239
         IF (ITABT.GT.0) THEN                                           TPXDOT    240
            TN=TSTCN                                                    TPXDOT    241
            DO 505 I=2,ITABT                                            TPXDOT    242
               NTAB=2*I                                                 TPXDOT    243
               Y2=DDAT(JTP+NTAB)                                        TPXDOT    244
               X2=DDAT(JTP+NTAB-1)                                      TPXDOT    245
               Y1=DDAT(JTP+NTAB-2)                                      TPXDOT    246
               X1=DDAT(JTP+NTAB-3)                                      TPXDOT    247
               IF (TN.LE.X2) GO TO 510                                  TPXDOT    248
  505       CONTINUE                                                    TPXDOT    249
  510       TSLOPE=(Y2-Y1)/(X2-X1)                                      TPXDOT    250
            TCOEFF=(Y1+(TN-X1)*TSLOPE)                                  TPXDOT    251
            JTP=JTP+2*ITABT                                             TPXDOT    252
         END IF                                                         TPXDOT    253
C                                                                       TPXDOT    254
         IF (ITABP.GT.0) THEN                                           TPXDOT    255
            TN=TSPSN                                                    TPXDOT    256
            DO 520 I=2,ITABP                                            TPXDOT    257
               NTAB=2*I                                                 TPXDOT    258
               Y2=DDAT(JTP+NTAB)                                        TPXDOT    259
               X2=DDAT(JTP+NTAB-1)                                      TPXDOT    260
               Y1=DDAT(JTP+NTAB-2)                                      TPXDOT    261
               X1=DDAT(JTP+NTAB-3)                                      TPXDOT    262
               IF (TN.LE.X2) GO TO 530                                  TPXDOT    263
  520       CONTINUE                                                    TPXDOT    264
  530       PSLOPE=(Y2-Y1)/(X2-X1)                                      TPXDOT    265
            PCOEFF=(Y1+(TN-X1)*PSLOPE)                                  TPXDOT    266
         END IF                                                         TPXDOT    267
         YSTP0=YSTP*TCOEFF*PCOEFF                                       TPXDOT    268
C                                                                       TPXDOT    269
         RT0=COS(ASTP)/YSTP0                                            TPXDOT    270
         XT0=-SIN(ASTP)/YSTP0                                           TPXDOT    271
C                                                                       TPXDOT    272
C     FORM  DEL I=CDEV*DEL YC+YDEV*DEL V                                TPXDOT    273
C                 (-YSEL*DELV, AFTER INTERCONNECTION)                   TPXDOT    274
C     WHERE  CDEV=VDEV*XDEV                                             TPXDOT    275
C                                                                       TPXDOT    276
         AT1=ATT*(1.0-XTT)                                              TPXDOT    277
         AT2=-ATT*XTT                                                   TPXDOT    278
         AP1=ATP*(1.0-XTP)                                              TPXDOT    279
         AP2=-ATP*XTP                                                   TPXDOT    280
         TANFI=TAN(ASTP)                                                TPXDOT    281
         C1T=-YSTP0/SQRT(1.0+TANFI**2)/TCOEFF/PCOEFF                    TPXDOT    282
         C1P=C1T*PSLOPE/PCOEFF                                          TPXDOT    283
         C1T=C1T*TSLOPE/TCOEFF                                          TPXDOT    284
         AXRE=A1RE*A2RE+A1IM*A2IM                                       TPXDOT    285
         AXIM=A1RE*A2IM-A1IM*A2RE                                       TPXDOT    286
         FACTX=AXRE**2+AXIM**2                                          TPXDOT    287
         CG12=2.0*(GSTP*AXRE-BSTP*AXIM)/FACTX                           TPXDOT    288
         CB12=2.0*(-GSTP*AXIM-BSTP*AXRE)/FACTX                          TPXDOT    289
         CG21=2.0*(GSTP*AXRE+BSTP*AXIM)/FACTX                           TPXDOT    290
         CB21=2.0*(GSTP*AXIM-BSTP*AXRE)/FACTX                           TPXDOT    291
C                                                                       TPXDOT    292
         VDEV(1,1)=VR1                                                  TPXDOT    293
         VDEV(1,2)=-VI1                                                 TPXDOT    294
         VDEV(1,3)=VR2                                                  TPXDOT    295
         VDEV(1,4)=-VI2                                                 TPXDOT    296
         VDEV(2,1)=VI1                                                  TPXDOT    297
         VDEV(2,2)=VR1                                                  TPXDOT    298
         VDEV(2,3)=VI2                                                  TPXDOT    299
         VDEV(2,4)=VR2                                                  TPXDOT    300
         VDEV(3,5)=VR1                                                  TPXDOT    301
         VDEV(3,6)=-VI1                                                 TPXDOT    302
         VDEV(3,7)=VR2                                                  TPXDOT    303
         VDEV(3,8)=-VI2                                                 TPXDOT    304
         VDEV(4,5)=VI1                                                  TPXDOT    305
         VDEV(4,6)=VR1                                                  TPXDOT    306
         VDEV(4,7)=VI2                                                  TPXDOT    307
         VDEV(4,8)=VR2                                                  TPXDOT    308
C                                                                       TPXDOT    309
         XDEV(1,1)=C1T/FACT1-2.0*GSTP*A1RE*AT1/FACT1/FACT1              TPXDOT    310
         XDEV(1,2)=C1P/FACT1-2.0*GSTP*A1IM*AP1/FACT1/FACT1              TPXDOT    311
         XDEV(2,1)=TANFI*C1T/FACT1+2.0*BSTP*A1RE*AT1/FACT1/FACT1        TPXDOT    312
         XDEV(2,2)=TANFI*C1P/FACT1+2.0*BSTP*A1IM*AP1/FACT1/FACT1        TPXDOT    313
         CX1=(-GSTP+AXRE*CG12)/FACTX                                    TPXDOT    314
         CX2=(BSTP+AXIM*CG12)/FACTX                                     TPXDOT    315
         XDEV(3,1)=-C1T*(AXRE+AXIM*TANFI)/FACTX                         TPXDOT    316
     &             +(CX1*A2RE+CX2*A2IM)*AT1+(CX1*A1RE-CX2*A1IM)*AT2     TPXDOT    317
         XDEV(3,2)=-C1P*(AXRE+AXIM*TANFI)/FACTX                         TPXDOT    318
     &             +(CX1*A2IM-CX2*A2RE)*AP1+(CX1*A1IM+CX2*A1RE)*AP2     TPXDOT    319
         CX1=(BSTP+AXRE*CB12)/FACTX                                     TPXDOT    320
         CX2=(GSTP+AXIM*CB12)/FACTX                                     TPXDOT    321
         XDEV(4,1)=-C1T*(-AXIM+AXRE*TANFI)/FACTX                        TPXDOT    322
     &             +(CX1*A2RE+CX2*A2IM)*AT1+(CX1*A1RE-CX2*A1IM)*AT2     TPXDOT    323
         XDEV(4,2)=-C1P*(-AXIM+AXRE*TANFI)/FACTX                        TPXDOT    324
     &             +(CX1*A2IM-CX2*A2RE)*AP1+(CX1*A1IM+CX2*A1RE)*AP2     TPXDOT    325
         CX1=(-GSTP+AXRE*CG21)/FACTX                                    TPXDOT    326
         CX2=(-BSTP+AXIM*CG21)/FACTX                                    TPXDOT    327
         XDEV(5,1)=-C1T*(AXRE-AXIM*TANFI)/FACTX                         TPXDOT    328
     &             +(CX1*A2RE+CX2*A2IM)*AT1+(CX1*A1RE-CX2*A1IM)*AT2     TPXDOT    329
         XDEV(5,2)=-C1P*(AXRE-AXIM*TANFI)/FACTX                         TPXDOT    330
     &             +(CX1*A2IM-CX2*A2RE)*AP1+(CX1*A1IM+CX2*A1RE)*AP2     TPXDOT    331
         CX1=(BSTP+AXRE*CB21)/FACTX                                     TPXDOT    332
         CX2=(-GSTP+AXIM*CB21)/FACTX                                    TPXDOT    333
         XDEV(6,1)=-C1T*(AXIM+AXRE*TANFI)/FACTX                         TPXDOT    334
     &             +(CX1*A2RE+CX2*A2IM)*AT1+(CX1*A1RE-CX2*A1IM)*AT2     TPXDOT    335
         XDEV(6,2)=-C1P*(AXIM+AXRE*TANFI)/FACTX                         TPXDOT    336
     &             +(CX1*A2IM-CX2*A2RE)*AP1+(CX1*A1IM+CX2*A1RE)*AP2     TPXDOT    337
         XDEV(7,1)=C1T/FACT2-2.0*GSTP*A2RE*AT2/FACT2/FACT2              TPXDOT    338
         XDEV(7,2)=C1P/FACT2-2.0*GSTP*A2IM*AP2/FACT2/FACT2              TPXDOT    339
         XDEV(8,1)=TANFI*C1T/FACT2+2.0*BSTP*A2RE*AT2/FACT2/FACT2        TPXDOT    340
         XDEV(8,2)=TANFI*C1P/FACT2+2.0*BSTP*A2IM*AP2/FACT2/FACT2        TPXDOT    341
C                                                                       TPXDOT    342
         DO 130 L=1,2                                                   TPXDOT    343
         DO 130 I=1,4                                                   TPXDOT    344
         CDEV(I,L)=0.0                                                  TPXDOT    345
         DO 130 J=1,8                                                   TPXDOT    346
            CDEV(I,L)=CDEV(I,L)+VDEV(I,J)*XDEV(J,L)                     TPXDOT    347
  130    CONTINUE                                                       TPXDOT    348
C                                                                       TPXDOT    349
         YSEL(1,1)=G110                                                 TPXDOT    350
         YSEL(1,2)=-B110                                                TPXDOT    351
         YSEL(1,3)=G120                                                 TPXDOT    352
         YSEL(1,4)=-B120                                                TPXDOT    353
         YSEL(2,1)=B110                                                 TPXDOT    354
         YSEL(2,2)=G110                                                 TPXDOT    355
         YSEL(2,3)=B120                                                 TPXDOT    356
         YSEL(2,4)=G120                                                 TPXDOT    357
         YSEL(3,1)=G210                                                 TPXDOT    358
         YSEL(3,2)=-B210                                                TPXDOT    359
         YSEL(3,3)=G220                                                 TPXDOT    360
         YSEL(3,4)=-B220                                                TPXDOT    361
         YSEL(4,1)=B210                                                 TPXDOT    362
         YSEL(4,2)=G210                                                 TPXDOT    363
         YSEL(4,3)=B220                                                 TPXDOT    364
         YSEL(4,4)=G220                                                 TPXDOT    365
         YDEVS(1,1)=G11                                                 TPXDOT    366
         YDEVS(1,2)=-B11                                                TPXDOT    367
         YDEVS(1,3)=G12                                                 TPXDOT    368
         YDEVS(1,4)=-B12                                                TPXDOT    369
         YDEVS(2,1)=B11                                                 TPXDOT    370
         YDEVS(2,2)=G11                                                 TPXDOT    371
         YDEVS(2,3)=B12                                                 TPXDOT    372
         YDEVS(2,4)=G12                                                 TPXDOT    373
         YDEVS(3,1)=G21                                                 TPXDOT    374
         YDEVS(3,2)=-B21                                                TPXDOT    375
         YDEVS(3,3)=G22                                                 TPXDOT    376
         YDEVS(3,4)=-B22                                                TPXDOT    377
         YDEVS(4,1)=B21                                                 TPXDOT    378
         YDEVS(4,2)=G21                                                 TPXDOT    379
         YDEVS(4,3)=B22                                                 TPXDOT    380
         YDEVS(4,4)=G22                                                 TPXDOT    381
C                                                                       TPXDOT    382
      DO 50 I=1,LOUTP                                                   TPXDOT    383
      DO 40 J=1,120                                                     TPXDOT    384
      YDEVR(I,J)=0.0                                                    TPXDOT    385
  40  CONTINUE                                                          TPXDOT    386
      DO 50 J=1,LOUTP                                                   TPXDOT    387
      ADEV(I,J)=0.0                                                     TPXDOT    388
      IF(J.LE.(LOUTP/2+1)) CREF(I,J)=0.0                                TPXDOT    389
  50  CONTINUE                                                          TPXDOT    390
C         CALL FMOVE(0,ADEV,ADEV,LOUTP*LOUTP)                           TPXDOT    391
C         CALL FMOVE(0,YDEVR,YDEVR,120*LOUTP)                           TPXDOT    392
C         CALL FMOVE(0,CREF,CREF,LOUTP*(LOUTP/2+1))                     TPXDOT    393
C                                                                       TPXDOT    394
      END IF                                                            TPXDOT    395
C                                                                       TPXDOT    396
      LSTATE=0                                                          TPXDOT    397
      IF (NTTYPN.NE.50) GO TO 160                                       TPXDOT    398
C                                                                       TPXDOT    399
C     GET THE INPUT VALUES                                              TPXDOT    400
C                                                                       TPXDOT    401
      JE0=JTDAT(N)                                                      TPXDOT    402
      JE1=JE0+1                                                         TPXDOT    403
      CALL RINUDM                                                       TPXDOT    404
C                                                                       TPXDOT    405
      VALIN(5)=TSTC(JYTC+2)                                             TPXDOT    406
      VALIN(11)=SSTC(JYTC+3)                                            TPXDOT    407
      VALIN(20)=VREF(JYTC+1)                                            TPXDOT    408
C                                                                       TPXDOT    409
      KORD=0                                                            TPXDOT    410
      JSTATE=JXSTC(N)                                                   TPXDOT    411
      CALL DEUDM(H,KORD,NLF1,K13,LCKT)                                  TPXDOT    412
C                                                                       TPXDOT    413
      DO 100 J=1,KORD                                                   TPXDOT    414
         XDOT(JSTATE+J)=DSTATE(J)                                       TPXDOT    415
  100 CONTINUE                                                          TPXDOT    416
C                                                                       TPXDOT    417
      LSTATE=LSTATE+KORD                                                TPXDOT    418
      IOUT=IDDAT(JE7+1)                                                 TPXDOT    419
      TSTC(JYTC+2)=VALOUT(IOUT)                                         TPXDOT    420
      SSTC(JYTC+3)=VALIN(11)                                            TPXDOT    421
C                                                                       TPXDOT    422
      JYUDM=JYTC+4                                                      TPXDOT    423
      DO 140 J=1,NUDB                                                   TPXDOT    424
         YVAR(JYUDM+J)=VALOUT(J)                                        TPXDOT    425
  140 CONTINUE                                                          TPXDOT    426
C                                                                       TPXDOT    427
C     UPDATE JACOBIAN MATRICES FOR STC                                  TPXDOT    428
C                                                                       TPXDOT    429
      IF (NITER.EQ.0) THEN                                              TPXDOT    430
C                                                                       TPXDOT    431
         CALL FMOVE(0,UDAT,UDAT,NXUDB**2)                               TPXDOT    432
         JEU=JE7-JE1+2                                                  TPXDOT    433
         DO 150 I=1,JEU                                                 TPXDOT    434
            UDAT(I)=DDAT(I+JE1-1)                                       TPXDOT    435
  150    CONTINUE                                                       TPXDOT    436
         IWS1=JTDAT(N)                                                  TPXDOT    437
         JE1=JE1-IWS1                                                   TPXDOT    438
         JE2=JE2-IWS1                                                   TPXDOT    439
         JE3=JE3-IWS1                                                   TPXDOT    440
         JE4=JE4-IWS1                                                   TPXDOT    441
         JE5=JE5-IWS1                                                   TPXDOT    442
         JE6=JE6-IWS1                                                   TPXDOT    443
         JE7=JE7-IWS1                                                   TPXDOT    444
C                                                                       TPXDOT    445
C     FORM: DEL U0=XUI*DEL I+XUV*DEL V+XUY*DEL YB+XUREF*DEL VREF        TPXDOT    446
C                                                                       TPXDOT    447
      DO 70 I=1,20                                                      TPXDOT    448
      DO 60 J=1,NXUDB                                                   TPXDOT    449
      XUY(I,J)=0.0                                                      TPXDOT    450
  60  CONTINUE                                                          TPXDOT    451
      DO 70 J=1,LOUTP                                                   TPXDOT    452
      XUI(I,J)=0.0                                                      TPXDOT    453
      XUV(I,J)=0.0                                                      TPXDOT    454
  70  CONTINUE                                                          TPXDOT    455
C         CALL FMOVE(0,XUI,XUI,20*LOUTP)                                TPXDOT    456
C         CALL FMOVE(0,XUV,XUV,20*LOUTP)                                TPXDOT    457
C         CALL FMOVE(0,XUY,XUY,20*NXUDB)                                TPXDOT    458
C                                                                       TPXDOT    459
         IBEND=IUDAT(JE7+1)                                             TPXDOT    460
         XUI(1,1)=CR1/CM1                                               TPXDOT    461
         XUI(1,2)=CI1/CM1                                               TPXDOT    462
         XUI(2,3)=CR2/CM2                                               TPXDOT    463
         XUI(2,4)=CI2/CM2                                               TPXDOT    464
         XUI(3,1)=VR1                                                   TPXDOT    465
         XUI(3,2)=VI1                                                   TPXDOT    466
         XUI(4,3)=VR2                                                   TPXDOT    467
         XUI(4,4)=VI2                                                   TPXDOT    468
         XUI(15,1)=VI1                                                  TPXDOT    469
         XUI(15,2)=-VR1                                                 TPXDOT    470
         XUI(16,3)=VI2                                                  TPXDOT    471
         XUI(16,4)=-VR2                                                 TPXDOT    472
C                                                                       TPXDOT    473
         XUV(3,1)=CR1                                                   TPXDOT    474
         XUV(3,2)=CI1                                                   TPXDOT    475
         XUV(4,3)=CR2                                                   TPXDOT    476
         XUV(4,4)=CI2                                                   TPXDOT    477
         XUV(7,1)=VR1/VM1                                               TPXDOT    478
         XUV(7,2)=VI1/VM1                                               TPXDOT    479
         XUV(8,3)=VR2/VM2                                               TPXDOT    480
         XUV(8,4)=VI2/VM2                                               TPXDOT    481
         XUV(9,1)=-VI1/VM1/VM1                                          TPXDOT    482
         XUV(9,2)=VR1/VM1/VM1                                           TPXDOT    483
         XUV(10,3)=-VI2/VM2/VM2                                         TPXDOT    484
         XUV(10,4)=VR2/VM2/VM2                                          TPXDOT    485
         XUV(15,1)=-CI1                                                 TPXDOT    486
         XUV(15,2)=CR1                                                  TPXDOT    487
         XUV(16,3)=-CI2                                                 TPXDOT    488
         XUV(16,4)=CR2                                                  TPXDOT    489
C                                                                       TPXDOT    490
         XUY(5,IBEND)=1.0                                               TPXDOT    491
C                                                                       TPXDOT    492
C     FORM THE REMOTE BUS ARRAY AND CONTROL A B C D MATRICES            TPXDOT    493
C                                                                       TPXDOT    494
         BASERT=1.0                                                     TPXDOT    495
         CALL AUDMB(LCYO,LWIF,NBUSR,NBUSS)                              TPXDOT    496
         IF (KERUDM.NE.0) GO TO 900                                     TPXDOT    497
         IF (NBUSR.NE.0) THEN                                           TPXDOT    498
            DO 120 I=1,NBUSR                                            TPXDOT    499
               ICOLBV=ICOLBV+1                                          TPXDOT    500
               NBR(ICOLBV)=MBUSR(NBUSS+I)                               TPXDOT    501
  120       CONTINUE                                                    TPXDOT    502
         END IF                                                         TPXDOT    503
C                                                                       TPXDOT    504
C     SOLVE THE CONTROL EQUATIONS                                       TPXDOT    505
C                                                                       TPXDOT    506
         LREM=2*NBUSR                                                   TPXDOT    507
         CALL AUDMC(IROWAK,LCYO,LWIF,LREM)                              TPXDOT    508
         IF (KERUDM.NE.0) GO TO 900                                     TPXDOT    509
C                                                                       TPXDOT    510
C     FORM: XDOT=AX*X+BXI*DEL I+BXV*DEL V(S&R)+BREF*DEL VREF            TPXDOT    511
C          DEL I=CX*X+ADEV*DEL I+YDEV*DEL V+YDEVR*DEL VR+CREF*DEL VREF  TPXDOT    512
C                                                                       TPXDOT    513
         LSTA=KORD                                                      TPXDOT    514
         DO 165 I=1,KORD                                                TPXDOT    515
         DO 165 J=1,KORD                                                TPXDOT    516
            AX(J,I)=AXB(J,I)                                            TPXDOT    517
  165    CONTINUE                                                       TPXDOT    518
C                                                                       TPXDOT    519
         DO 170 I=1,KORD                                                TPXDOT    520
         DO 170 J=1,4                                                   TPXDOT    521
            BXI(I,J)=BUI(I,J)                                           TPXDOT    522
            BXV(I,J)=BUV(I,J)                                           TPXDOT    523
            CX(J,I)=CDEV(J,1)*CYX(1,I)                                  TPXDOT    524
  170    CONTINUE                                                       TPXDOT    525
C                                                                       TPXDOT    526
         DO 180 I=1,4                                                   TPXDOT    527
         DO 180 J=1,4                                                   TPXDOT    528
            ADEV(J,I)=CDEV(J,1)*CYI(1,I)                                TPXDOT    529
            YDEVS(J,I)=YDEVS(J,I)+CDEV(J,1)*CYV(1,I)                    TPXDOT    530
  180    CONTINUE                                                       TPXDOT    531
C                                                                       TPXDOT    532
         IF (NBUSR.NE.0) THEN                                           TPXDOT    533
            DO 195 I=1,KORD                                             TPXDOT    534
            DO 195 J=1,2*NBUSR                                          TPXDOT    535
               BXV(I,J+4)=BUVR(I,J)                                     TPXDOT    536
  195       CONTINUE                                                    TPXDOT    537
            DO 200 I=1,2*NBUSR                                          TPXDOT    538
            DO 200 J=1,4                                                TPXDOT    539
               YDEVR(J,I)=CDEV(J,1)*CYVR(1,I)                           TPXDOT    540
  200       CONTINUE                                                    TPXDOT    541
         END IF                                                         TPXDOT    542
C                                                                       TPXDOT    543
      END IF                                                            TPXDOT    544
C                                                                       TPXDOT    545
  160 CONTINUE                                                          TPXDOT    546
C                                                                       TPXDOT    547
      IF (NPTYPN.NE.50) GO TO 190                                       TPXDOT    548
C                                                                       TPXDOT    549
C     GET THE INPUT VALUES                                              TPXDOT    550
C                                                                       TPXDOT    551
      JE0=JPDAT(N)                                                      TPXDOT    552
      JE1=JE0+1                                                         TPXDOT    553
      CALL RINUDM                                                       TPXDOT    554
      VALIN(6)=TSPS(JYPS+2)                                             TPXDOT    555
      VALIN(12)=SSPS(JYPS+3)                                            TPXDOT    556
      VALIN(20)=VREF(JYPS+1)                                            TPXDOT    557
C                                                                       TPXDOT    558
      KORD=0                                                            TPXDOT    559
      JSTATE=JXSPS(N)                                                   TPXDOT    560
      CALL DEUDM(H,KORD,NLF1,K13,LCKT)                                  TPXDOT    561
C                                                                       TPXDOT    562
      DO 110 J=1,KORD                                                   TPXDOT    563
         XDOT(JSTATE+J)=DSTATE(J)                                       TPXDOT    564
  110 CONTINUE                                                          TPXDOT    565
C                                                                       TPXDOT    566
      LSTATE=LSTATE+KORD                                                TPXDOT    567
      IOUT=IDDAT(JE7+1)                                                 TPXDOT    568
      TSPS(JYPS+2)=VALOUT(IOUT)                                         TPXDOT    569
      SSPS(JYPS+3)=VALIN(12)                                            TPXDOT    570
C                                                                       TPXDOT    571
      JYUDM=JYPS+4                                                      TPXDOT    572
      DO 175 J=1,NUDB                                                   TPXDOT    573
         YVAR(JYUDM+J)=VALOUT(J)                                        TPXDOT    574
  175 CONTINUE                                                          TPXDOT    575
C                                                                       TPXDOT    576
C     UPDATE JACOBIAN MATRICES FOR SPS                                  TPXDOT    577
C                                                                       TPXDOT    578
      IF (NITER.EQ.0) THEN                                              TPXDOT    579
C                                                                       TPXDOT    580
         CALL FMOVE(0,UDAT,UDAT,NXUDB**2)                               TPXDOT    581
         JEU=JE7-JE1+2                                                  TPXDOT    582
         DO 210 I=1,JEU                                                 TPXDOT    583
            UDAT(I)=DDAT(I+JE1-1)                                       TPXDOT    584
  210    CONTINUE                                                       TPXDOT    585
         IWS1=JPDAT(N)                                                  TPXDOT    586
         JE1=JE1-IWS1                                                   TPXDOT    587
         JE2=JE2-IWS1                                                   TPXDOT    588
         JE3=JE3-IWS1                                                   TPXDOT    589
         JE4=JE4-IWS1                                                   TPXDOT    590
         JE5=JE5-IWS1                                                   TPXDOT    591
         JE6=JE6-IWS1                                                   TPXDOT    592
         JE7=JE7-IWS1                                                   TPXDOT    593
C                                                                       TPXDOT    594
C     FORM: DEL U0=XUI*DEL I+XUV*DEL V+XUY*DEL YB+XUREF*DEL VREF        TPXDOT    595
C                                                                       TPXDOT    596
      DO 90 I=1,20                                                      TPXDOT    597
      DO 80 J=1,NXUDB                                                   TPXDOT    598
      XUY(I,J)=0.0                                                      TPXDOT    599
  80  CONTINUE                                                          TPXDOT    600
      DO 90 J=1,LOUTP                                                   TPXDOT    601
      XUI(I,J)=0.0                                                      TPXDOT    602
      XUV(I,J)=0.0                                                      TPXDOT    603
  90  CONTINUE                                                          TPXDOT    604
C         CALL FMOVE(0,XUI,XUI,20*LOUTP)                                TPXDOT    605
C         CALL FMOVE(0,XUV,XUV,20*LOUTP)                                TPXDOT    606
C         CALL FMOVE(0,XUY,XUY,20*NXUDB)                                TPXDOT    607
C                                                                       TPXDOT    608
         IBEND=IUDAT(JE7+1)                                             TPXDOT    609
         XUI(1,1)=CR1/CM1                                               TPXDOT    610
         XUI(1,2)=CI1/CM1                                               TPXDOT    611
         XUI(2,3)=CR2/CM2                                               TPXDOT    612
         XUI(2,4)=CI2/CM2                                               TPXDOT    613
         XUI(3,1)=VR1                                                   TPXDOT    614
         XUI(3,2)=VI1                                                   TPXDOT    615
         XUI(4,3)=VR2                                                   TPXDOT    616
         XUI(4,4)=VI2                                                   TPXDOT    617
         XUI(15,1)=VI1                                                  TPXDOT    618
         XUI(15,2)=-VR1                                                 TPXDOT    619
         XUI(16,3)=VI2                                                  TPXDOT    620
         XUI(16,4)=-VR2                                                 TPXDOT    621
C                                                                       TPXDOT    622
         XUV(3,1)=CR1                                                   TPXDOT    623
         XUV(3,2)=CI1                                                   TPXDOT    624
         XUV(4,3)=CR2                                                   TPXDOT    625
         XUV(4,4)=CI2                                                   TPXDOT    626
         XUV(7,1)=VR1/VM1                                               TPXDOT    627
         XUV(7,2)=VI1/VM1                                               TPXDOT    628
         XUV(8,3)=VR2/VM2                                               TPXDOT    629
         XUV(8,4)=VI2/VM2                                               TPXDOT    630
         XUV(9,1)=-VI1/VM1/VM1                                          TPXDOT    631
         XUV(9,2)=VR1/VM1/VM1                                           TPXDOT    632
         XUV(10,3)=-VI2/VM2/VM2                                         TPXDOT    633
         XUV(10,4)=VR2/VM2/VM2                                          TPXDOT    634
         XUV(15,1)=-CI1                                                 TPXDOT    635
         XUV(15,2)=CR1                                                  TPXDOT    636
         XUV(16,3)=-CI2                                                 TPXDOT    637
         XUV(16,4)=CR2                                                  TPXDOT    638
C                                                                       TPXDOT    639
         XUY(6,IBEND)=1.0                                               TPXDOT    640
C                                                                       TPXDOT    641
C     FORM THE REMOTE BUS ARRAY AND CONTROL A B C D MATRICES            TPXDOT    642
C                                                                       TPXDOT    643
         NBUSR=NBUSR1                                                   TPXDOT    644
         BASERT=1.0                                                     TPXDOT    645
         CALL AUDMB(LCYO,LWIF,NBUSR,NBUSS)                              TPXDOT    646
         IF (KERUDM.NE.0) GO TO 900                                     TPXDOT    647
         IF (NBUSR.NE.0) THEN                                           TPXDOT    648
            DO 125 I=1,NBUSR                                            TPXDOT    649
               ICOLBV=ICOLBV+1                                          TPXDOT    650
               NBR(ICOLBV)=MBUSR(NBUSS+I)                               TPXDOT    651
  125       CONTINUE                                                    TPXDOT    652
         END IF                                                         TPXDOT    653
C                                                                       TPXDOT    654
C     SOLVE THE CONTROL EQUATIONS                                       TPXDOT    655
C                                                                       TPXDOT    656
         LREM=2*NBUSR                                                   TPXDOT    657
         CALL AUDMC(IROWAK,LCYO,LWIF,LREM)                              TPXDOT    658
         IF (KERUDM.NE.0) GO TO 900                                     TPXDOT    659
C                                                                       TPXDOT    660
C     FORM: XDOT=AX*X+BXI*DEL I+BXV*DEL V(S&R)+BREF*DEL VREF            TPXDOT    661
C          DEL I=CX*X+ADEV*DEL I+YDEV*DEL V+YDEVR*DEL VR+CREF*DEL VREF  TPXDOT    662
C                                                                       TPXDOT    663
         DO 220 I=1,KORD                                                TPXDOT    664
         DO 220 J=1,KORD                                                TPXDOT    665
            AX(J+LSTA,I+LSTA)=AXB(J,I)                                  TPXDOT    666
  220    CONTINUE                                                       TPXDOT    667
         DO 225 I=1,LSTA                                                TPXDOT    668
         DO 225 J=1,KORD                                                TPXDOT    669
         AX(J+LSTA,I)=0.0                                               TPXDOT    670
         AX(I,J+LSTA)=0.0                                               TPXDOT    671
  225    CONTINUE                                                       TPXDOT    672
C                                                                       TPXDOT    673
         DO 230 I=1,KORD                                                TPXDOT    674
         DO 230 J=1,4                                                   TPXDOT    675
            BXI(I+LSTA,J)=BUI(I,J)                                      TPXDOT    676
            BXV(I+LSTA,J)=BUV(I,J)                                      TPXDOT    677
            CX(J,I+LSTA)=CDEV(J,2)*CYX(1,I)                             TPXDOT    678
  230    CONTINUE                                                       TPXDOT    679
C                                                                       TPXDOT    680
         DO 245 I=1,4                                                   TPXDOT    681
         DO 245 J=1,4                                                   TPXDOT    682
            ADEV(J,I)=ADEV(J,I)+CDEV(J,2)*CYI(1,I)                      TPXDOT    683
            YDEVS(J,I)=YDEVS(J,I)+CDEV(J,2)*CYV(1,I)                    TPXDOT    684
  245    CONTINUE                                                       TPXDOT    685
C                                                                       TPXDOT    686
         IF (NBUSR.NE.0) THEN                                           TPXDOT    687
            DO 255 I=1,KORD                                             TPXDOT    688
            DO 255 J=1,2*NBUSR                                          TPXDOT    689
               BXV(I+LSTA,J+4)=BUVR(I,J)                                TPXDOT    690
  255       CONTINUE                                                    TPXDOT    691
            DO 265 I=1,2*NBUSR                                          TPXDOT    692
            DO 265 J=1,4                                                TPXDOT    693
               YDEVR(J,I)=YDEVR(J,I)+CDEV(J,2)*CYVR(1,I)                TPXDOT    694
  265       CONTINUE                                                    TPXDOT    695
            NBUSD=NBUSR-NBUSR1                                          TPXDOT    696
            IF (NBUSD.NE.0) THEN                                        TPXDOT    697
               DO 275 I=1,LSTA                                          TPXDOT    698
               DO 275 J=1,2*NBUSD                                       TPXDOT    699
                  BXV(I,J+2*NBUSR1+4)=0.0                               TPXDOT    700
  275          CONTINUE                                                 TPXDOT    701
            ENDIF                                                       TPXDOT    702
         ENDIF                                                          TPXDOT    703
C                                                                       TPXDOT    704
         LSTA=LSTA+KORD                                                 TPXDOT    705
C                                                                       TPXDOT    706
      END IF                                                            TPXDOT    707
C                                                                       TPXDOT    708
  190 CONTINUE                                                          TPXDOT    709
C                                                                       TPXDOT    710
      TSTCN=TSTC(JYTC+2)+TSTC(JYTC+4)                                   TPXDOT    711
      TSPSN=TSPS(JYPS+2)+TSPS(JYPS+4)                                   TPXDOT    712
      YFACTT=1.0                                                        TPXDOT    713
      YFACTP=1.0                                                        TPXDOT    714
      JTP=JTP1+20                                                       TPXDOT    715
      IF (ITABT.GT.0) THEN                                              TPXDOT    716
         TN=TSTCN                                                       TPXDOT    717
         DO 440 I=2,ITABT                                               TPXDOT    718
         NTAB=2*I                                                       TPXDOT    719
         Y2=DDAT(JTP+NTAB)                                              TPXDOT    720
         X2=DDAT(JTP+NTAB-1)                                            TPXDOT    721
         Y1=DDAT(JTP+NTAB-2)                                            TPXDOT    722
         X1=DDAT(JTP+NTAB-3)                                            TPXDOT    723
         IF (TN.LE.X2) GO TO 450                                        TPXDOT    724
  440    CONTINUE                                                       TPXDOT    725
  450    YFACTT=1.0/(Y1+(TN-X1)*(Y2-Y1)/(X2-X1))                        TPXDOT    726
      ENDIF                                                             TPXDOT    727
      JTP1=JTP+2*ITABT                                                  TPXDOT    728
      IF (ITABP.GT.0) THEN                                              TPXDOT    729
         TN=TSPSN                                                       TPXDOT    730
         DO 460 I=2,ITABP                                               TPXDOT    731
         NTAB=2*I                                                       TPXDOT    732
         Y2=DDAT(JTP1+NTAB)                                             TPXDOT    733
         X2=DDAT(JTP1+NTAB-1)                                           TPXDOT    734
         Y1=DDAT(JTP1+NTAB-2)                                           TPXDOT    735
         X1=DDAT(JTP1+NTAB-3)                                           TPXDOT    736
         IF (TN.LE.X2) GO TO 470                                        TPXDOT    737
  460    CONTINUE                                                       TPXDOT    738
  470    YFACTP=1.0/(Y1+(TN-X1)*(Y2-Y1)/(X2-X1))                        TPXDOT    739
      ENDIF                                                             TPXDOT    740
      YSTPM=YSTP*YFACTT*YFACTP                                          TPXDOT    741
      GSTP=YSTPM*COS(ASTP)                                              TPXDOT    742
      BSTP=YSTPM*SIN(ASTP)                                              TPXDOT    743
C                                                                       TPXDOT    744
      A1RE=1.0+ATT*(1.0-XTT)*TSTCN                                      TPXDOT    745
      A1IM=ATP*(1.0-XTP)*TSPSN                                          TPXDOT    746
      A1M=SQRT(A1RE*A1RE+A1IM*A1IM)                                     TPXDOT    747
      AA1=ATAN2(A1IM,A1RE)                                              TPXDOT    748
      A2RE=1.0-ATT*XTT*TSTCN                                            TPXDOT    749
      A2IM=-ATP*XTP*TSPSN                                               TPXDOT    750
      A2M=SQRT(A2RE*A2RE+A2IM*A2IM)                                     TPXDOT    751
      AA2=ATAN2(A2IM,A2RE)                                              TPXDOT    752
      FACT1=A1M*A1M                                                     TPXDOT    753
      FACT2=A2M*A2M                                                     TPXDOT    754
      Y12=YSTPM/A1M/A2M                                                 TPXDOT    755
      AY12=ASTP+AA1-AA2                                                 TPXDOT    756
      AY21=ASTP-AA1+AA2                                                 TPXDOT    757
      YVAR(JY1+1)=GSTP/FACT1                                            TPXDOT    758
      YVAR(JY1+2)=BSTP/FACT1                                            TPXDOT    759
      YVAR(JY1+3)=-Y12*COS(AY12)                                        TPXDOT    760
      YVAR(JY1+4)=-Y12*SIN(AY12)                                        TPXDOT    761
      YVAR(JY1+5)=-Y12*COS(AY21)                                        TPXDOT    762
      YVAR(JY1+6)=-Y12*SIN(AY21)                                        TPXDOT    763
      YVAR(JY1+7)=GSTP/FACT2                                            TPXDOT    764
      YVAR(JY1+8)=BSTP/FACT2                                            TPXDOT    765
C                                                                       TPXDOT    766
C     OBTAIN THE COMPLETE JACOBIAN MATRICES                             TPXDOT    767
C                                                                       TPXDOT    768
      IF (NITER.EQ.0) THEN                                              TPXDOT    769
C                                                                       TPXDOT    770
         LREF=2                                                         TPXDOT    771
         CALL AUDMD(LSTA,IROWAK,LREM,LREF)                              TPXDOT    772
         IF (KERUDM.NE.0) GO TO 900                                     TPXDOT    773
C                                                                       TPXDOT    774
C     STORE THE REMOTE BUS ADMITANCE                                    TPXDOT    775
C                                                                       TPXDOT    776
C         MUDBUS(IUDBUS+1)=KYUDM                                        TPXDOT    777
C         IUDBUS=IUDBUS+1                                               TPXDOT    778
C         IF(NBUSR.NE.0) THEN                                           TPXDOT    779
C            DO 280 K=1,NBUSR                                           TPXDOT    780
C            DO 280 L=1,2                                               TPXDOT    781
C            DO 280 J=1,2                                               TPXDOT    782
C            DO 280 I=1,2                                               TPXDOT    783
C            KYUDM=KYUDM+1                                              TPXDOT    784
C            YKUDM(KYUDM)=YDEVR(I+2*L-2,J+2*K-2)                        TPXDOT    785
C  280       CONTINUE                                                   TPXDOT    786
C         ENDIF                                                         TPXDOT    787
C                                                                       TPXDOT    788
C     LOAD A, B, C, D MATRICES TO WORKING ARRAYS                        TPXDOT    789
C                                                                       TPXDOT    790
         DO 240 I=1,LSTA                                                TPXDOT    791
            DO 250 J=1,LSTA                                             TPXDOT    792
               A(I,J)=AX(I,J)                                           TPXDOT    793
  250       CONTINUE                                                    TPXDOT    794
            DO 260 J=1,2*ICOLBV                                         TPXDOT    795
               B(I,J)=BXV(I,J)                                          TPXDOT    796
  260       CONTINUE                                                    TPXDOT    797
            AK(1,I)=CX(1,I)                                             TPXDOT    798
            AK(2,I)=CX(2,I)                                             TPXDOT    799
            AK(3,I)=CX(3,I)                                             TPXDOT    800
            AK(4,I)=CX(4,I)                                             TPXDOT    801
  240    CONTINUE                                                       TPXDOT    802
         DO 290 I=1,4                                                   TPXDOT    803
         DO 290 J=1,4                                                   TPXDOT    804
            YD(I,J)=YDEVS(I,J)-YSEL(I,J)                                TPXDOT    805
  290    CONTINUE                                                       TPXDOT    806
C                                                                       TPXDOT    807
         GOTO 270                                                       TPXDOT    808
C                                                                       TPXDOT    809
  270    CONTINUE                                                       TPXDOT    810
C                                                                       TPXDOT    811
C     FINALLY FORM AG, BG, CG MATRICES (JACOBIAN MATRICES)              TPXDOT    812
C                                                                       TPXDOT    813
      NAIDEX=IAIDEX                                                     TPXDOT    814
      NBIDEX=IBIDEX                                                     TPXDOT    815
      NCIDEX=ICIDEX                                                     TPXDOT    816
C                                                                       TPXDOT    817
      IPATH=1                                                           TPXDOT    818
      IF (IPATH.EQ.1) THEN                                              TPXDOT    819
C                                                                       TPXDOT    820
C     FOR USE IN THE NORMAL TRAPEZOIDAL INTEGRATION METHOD              TPXDOT    821
C                                                                       TPXDOT    822
      DO 480 I=1,LSTA                                                   TPXDOT    823
         DO 490 J=1,LSTA                                                TPXDOT    824
            IF (IA(I,J).EQ.0) GOTO 490                                  TPXDOT    825
            A(I,J)=-CEFJM*A(I,J)                                        TPXDOT    826
 490     CONTINUE                                                       TPXDOT    827
         A(I,I)=A(I,I)+1.0                                              TPXDOT    828
         DO 500 J=1,2*ICOLBV                                            TPXDOT    829
            IF (IB(I,J).EQ.0) GOTO 500                                  TPXDOT    830
            B(I,J)=-CEFJM*B(I,J)                                        TPXDOT    831
 500     CONTINUE                                                       TPXDOT    832
 480  CONTINUE                                                          TPXDOT    833
C                                                                       TPXDOT    834
C     PERFORM LU FACTORIZATION FOR A                                    TPXDOT    835
C                                                                       TPXDOT    836
      CALL LUDCM(LSTA)                                                  TPXDOT    837
C                                                                       TPXDOT    838
C     COMPUTE INVERSE(A)*B                                              TPXDOT    839
C                                                                       TPXDOT    840
      CALL FBSUBA(LSTA)                                                 TPXDOT    841
C                                                                       TPXDOT    842
C     STORE AK IN CJCOB ARRAY                                           TPXDOT    843
C                                                                       TPXDOT    844
      DO 310 I=1,4                                                      TPXDOT    845
         DO 320 J=1,LSTA                                                TPXDOT    846
            NCIDEX=NCIDEX+1                                             TPXDOT    847
            CJCOB(NCIDEX)=-AK(I,J)                                      TPXDOT    848
 320     CONTINUE                                                       TPXDOT    849
 310  CONTINUE                                                          TPXDOT    850
C                                                                       TPXDOT    851
C     STORE A AND B IN AJCOB AND BJCOB ARRAY                            TPXDOT    852
C                                                                       TPXDOT    853
      DO 330 I=1,LSTA                                                   TPXDOT    854
         DO 340 J=1,LSTA                                                TPXDOT    855
            NAIDEX=NAIDEX+1                                             TPXDOT    856
            AJCOB(NAIDEX)=A(I,J)                                        TPXDOT    857
  340    CONTINUE                                                       TPXDOT    858
  330 CONTINUE                                                          TPXDOT    859
C                                                                       TPXDOT    860
      DO 350 I=1,ICOLBV                                                 TPXDOT    861
         NBIDEX=NBIDEX+1                                                TPXDOT    862
         IBJCOB(NBIDEX)=NBR(I)                                          TPXDOT    863
         IWS1=2*I                                                       TPXDOT    864
         DO 360 J=1,LSTA                                                TPXDOT    865
            NBIDEX=NBIDEX+2                                             TPXDOT    866
            BJCOB(NBIDEX-1)=B(J,IWS1-1)                                 TPXDOT    867
            BJCOB(NBIDEX)=B(J,IWS1)                                     TPXDOT    868
  360    CONTINUE                                                       TPXDOT    869
  350 CONTINUE                                                          TPXDOT    870
      NBIDEX=NBIDEX+1                                                   TPXDOT    871
      IBJCOB(NBIDEX)=0                                                  TPXDOT    872
C                                                                       TPXDOT    873
      ELSE                                                              TPXDOT    874
C                                                                       TPXDOT    875
C     FOR USE IN GEAR'S METHOD TO CALCULATE THE SECOND ORDER DERIVATIVESTPXDOT    876
C                                                                       TPXDOT    877
C      DO 370 ILR=1,ISTATE                                              TPXDOT    878
C         DO 380 ILC=1,ISTATE                                           TPXDOT    879
C            ADGEN(ILR,ILC,N)=A(ILR,ILC)                                TPXDOT    880
C 380     CONTINUE                                                      TPXDOT    881
C         DO 390 ILC=1,ICOLBV                                           TPXDOT    882
C            BDGEN(ILR,ILC,N)=B(ILR,ILC)                                TPXDOT    883
C 390     CONTINUE                                                      TPXDOT    884
C         DO 400 ILC=1,IROWAK                                           TPXDOT    885
C            AKDGEN(ILC,ILR,N)=-AK(ILC,ILR)                             TPXDOT    886
C 400     CONTINUE                                                      TPXDOT    887
C 370  CONTINUE                                                         TPXDOT    888
C                                                                       TPXDOT    889
      END IF                                                            TPXDOT    890
C                                                                       TPXDOT    891
      END IF                                                            TPXDOT    892
C                                                                       TPXDOT    893
C     UPDATE COUNTERS                                                   TPXDOT    894
C                                                                       TPXDOT    895
      IAIDEX=IAIDEX+KORD*KORD                                           TPXDOT    896
      ICIDEX=ICIDEX+4*KORD                                              TPXDOT    897
C                                                                       TPXDOT    898
  420 IBIDEX=IBIDEX+1                                                   TPXDOT    899
      KS=IBJCOB(IBIDEX)                                                 TPXDOT    900
      IF (KS.EQ.0) GOTO 280                                             TPXDOT    901
      IBIDEX=IBIDEX+2*KORD                                              TPXDOT    902
      GOTO 420                                                          TPXDOT    903
C                                                                       TPXDOT    904
  280 CONTINUE                                                          TPXDOT    905
      RETURN                                                            TPXDOT    906
C                                                                       TPXDOT    907
  900 CONTINUE                                                          TPXDOT    908
      MSG='TPXDOT: ERROR IN JACOBIAN CALCULATION OF USER DEFINED STP'   TPXDOT    909
      CALL ASTOP(MSG,57)                                                TPXDOT    910
C                                                                       TPXDOT    911
      END                                                               TPXDOT    912
