CFPRIME SXDOT                                                           SXDOT       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 SXDOT                                                  SXDOT       3
CD                                                                      SXDOT       4
CD    TO CALCULATE THE DERIVATIVES OF THE STATES OF SVC FOR USE IN THE  SXDOT       5
CD    TRAPEZOIDAL METHOD. THIS SUBROUTINE IS SIMILAR TO SUBROUTINE      SXDOT       6
CD    DESVC. THE DIFFERENCES ARE                                        SXDOT       7
CD                                                                      SXDOT       8
CD    1. THE PARTS RELATED TO THE RUNGE-KUTTA METHOD ARE DELETED        SXDOT       9
CD                                                                      SXDOT      10
CD    2. THE JACOBIAN CLACULATION PATH IS ADDED                         SXDOT      11
CD                                                                      SXDOT      12
CD    3. THE STATE DERIVATIVE ARRAY, XDOT, IS HERE A GLOBAL ARRAY       SXDOT      13
CD                                                                      SXDOT      14
      INCLUDE 'PARX.INS'                                                SXDOT      15
      INCLUDE 'CNPT.INS'                                                SXDOT      16
      INCLUDE 'CNIPTR.INS'                                              SXDOT      17
      INCLUDE 'CNB4.INS'                                                SXDOT      18
      INCLUDE 'CNB9.INS'                                                SXDOT      19
      INCLUDE 'CNB19.INS'                                               SXDOT      20
      INCLUDE 'CNB91.INS'                                               SXDOT      21
      INCLUDE 'CNEXC.INS'                                               SXDOT      22
      INCLUDE 'CNSVS.INS'                                               SXDOT      23
      INCLUDE 'CNUDM.INS'                                               SXDOT      24
C      INCLUDE 'CNUDMA.INS/LIST'                                        SXDOT      25
C      INCLUDE 'CNUDMB.INS/LIST'                                        SXDOT      26
C      INCLUDE 'CNUDMK.INS/LIST'                                        SXDOT      27
C                                                                       SXDOT      28
      INCLUDE 'CNXSTA.INS'                                              SXDOT      29
      INCLUDE 'CNQSTA.INS'                                              SXDOT      30
      INCLUDE 'CNZSTA.INS'                                              SXDOT      31
      INCLUDE 'CNMDAT.INS'                                              SXDOT      32
      INCLUDE 'CNVOLT.INS'                                              SXDOT      33
      INCLUDE 'CNMYVA.INS'                                              SXDOT      34
      INCLUDE 'CNYVAR.INS'                                              SXDOT      35
      INCLUDE 'CNXDOT.INS'                                              SXDOT      36
      INCLUDE 'CNIMPR.INS'                                              SXDOT      37
      INCLUDE 'CNJCOB.INS'                                              SXDOT      38
      INCLUDE 'CNGEAR.INS'                                              SXDOT      39
C                                                                       SXDOT      40
      CHARACTER*2 CID                                                   SXDOT      41
      DATA CID/'  '/                                                    SXDOT      42
C                                                                       SXDOT      43
      VI2=0.0                                                           SXDOT      44
C                                                                       SXDOT      45
      DO 540 N=1,NSVC                                                   SXDOT      46
C                                                                       SXDOT      47
      JS=JSDAT(N)                                                       SXDOT      48
      JSTATE=JXSVR(N)                                                   SXDOT      49
      ISTATE=JXSVR(N+1)-JSTATE                                          SXDOT      50
      JY=JVSVR(N)                                                       SXDOT      51
      NRTYPN=IDDAT(JS+9)                                                SXDOT      52
      KS=NROLD(N)                                                       SXDOT      53
      K13=KS*3                                                          SXDOT      54
      NLF1=NOLD(KS)                                                     SXDOT      55
C                                                                       SXDOT      56
      IF (NRTYPN.NE.50) GOTO 180                                        SXDOT      57
C                                                                       SXDOT      58
C     TYPE 50 -- USER DEFINED SVC                                       SXDOT      59
C                                                                       SXDOT      60
      LSTATE=0                                                          SXDOT      61
C                                                                       SXDOT      62
C     GET THE INPUT VALUES                                              SXDOT      63
C                                                                       SXDOT      64
      JE0=JS                                                            SXDOT      65
      JE1=JE0+13                                                        SXDOT      66
      CALL RINUDM                                                       SXDOT      67
C                                                                       SXDOT      68
      VRE=REAL(VOLT(KS))                                                SXDOT      69
      VIM=AIMAG(VOLT(KS))                                               SXDOT      70
      VMG=SQRT(VRE*VRE+VIM*VIM)                                         SXDOT      71
      VALIN(7)=VMG                                                      SXDOT      72
      VALIN(8)=0.0                                                      SXDOT      73
      IF (VMG.GT.0.05) THEN                                             SXDOT      74
         VAG=ATAN2(VIM,VRE)                                             SXDOT      75
         VAGD=DDAT(JE0+2)-VAG                                           SXDOT      76
         DDAT(JE0+2)=VAG                                                SXDOT      77
         IF (VAGD.GT.3.15) THEN                                         SXDOT      78
            IDDAT(JE0+1)=IDDAT(JE0+1)+1                                 SXDOT      79
         ELSE IF (VAGD.LT.-3.15) THEN                                   SXDOT      80
            IDDAT(JE0+1)=IDDAT(JE0+1)-1                                 SXDOT      81
         END IF                                                         SXDOT      82
         VALIN(9)=VAG+6.2831853*IDDAT(JE0+1)                            SXDOT      83
      ELSE                                                              SXDOT      84
         VALIN(9)=DDAT(JE0+2)+6.2831853*IDDAT(JE0+1)                    SXDOT      85
      END IF                                                            SXDOT      86
      VALIN(10)=0.0                                                     SXDOT      87
      IF(BASER(JY+4).GT.0.0) THEN                                       SXDOT      88
         VALIN(1)=VMG*BDEV(JY+5)                                        SXDOT      89
         VALIN(2)=VMG*BTCR(JY+6)                                        SXDOT      90
         VALIN(3)=VMG*VALIN(1)                                          SXDOT      91
         VALIN(4)=VMG*VALIN(2)                                          SXDOT      92
         VALIN(5)=BDEV(JY+5)                                            SXDOT      93
         VALIN(6)=BTCR(JY+6)                                            SXDOT      94
         VALIN(11)=STCR(JY+7)                                           SXDOT      95
      ELSE                                                              SXDOT      96
         VALIN(1)=BDEV(JY+5)                                            SXDOT      97
         VALIN(3)=VMG*VALIN(1)                                          SXDOT      98
         IF(VMG.GT.0.0001) THEN                                         SXDOT      99
            VALIN(5)=VALIN(1)/VMG                                       SXDOT     100
         ELSE                                                           SXDOT     101
            VALIN(5)=0.0                                                SXDOT     102
         ENDIF                                                          SXDOT     103
         VALIN(12)=STCR(JY+7)                                           SXDOT     104
      ENDIF                                                             SXDOT     105
      VALIN(20)=RVREF(JY+1)                                             SXDOT     106
C                                                                       SXDOT     107
      JE0=0                                                             SXDOT     108
      NXS=0                                                             SXDOT     109
      CALL DEUDM(H,NXS,NLF1,K13,CID)                                    SXDOT     110
      JE0=1                                                             SXDOT     111
C                                                                       SXDOT     112
      DO 170 JJ=1,ISTATE                                                SXDOT     113
         XDOT(JSTATE+JJ)=DSTATE(JJ)                                     SXDOT     114
  170 CONTINUE                                                          SXDOT     115
C                                                                       SXDOT     116
      IOUT=IDDAT(JE7+1)                                                 SXDOT     117
      BSVC(JY+2)=VALOUT(IOUT)*ABS(BASER(JY+4))+BSVCO(JY+8)              SXDOT     118
      BDEV(JY+5)=VALOUT(IOUT)                                           SXDOT     119
      IF(BASER(JY+4).GT.0.0) THEN                                       SXDOT     120
         BTCR(JY+6)=VALIN(6)                                            SXDOT     121
         STCR(JY+7)=VALIN(11)                                           SXDOT     122
      ELSE                                                              SXDOT     123
         STCR(JY+12)=VALIN(12)                                          SXDOT     124
      ENDIF                                                             SXDOT     125
C                                                                       SXDOT     126
C     UPDATE Y-VARIABLES                                                SXDOT     127
C                                                                       SXDOT     128
      JYUDM=JY+8                                                        SXDOT     129
      DO 150 J=1,NUDB                                                   SXDOT     130
         YVAR(JYUDM+J)=VALOUT(J)                                        SXDOT     131
  150 CONTINUE                                                          SXDOT     132
C                                                                       SXDOT     133
      GOTO 530                                                          SXDOT     134
C                                                                       SXDOT     135
  180 CONTINUE                                                          SXDOT     136
C                                                                       SXDOT     137
C     ALL STANDARD SVC                                                  SXDOT     138
C                                                                       SXDOT     139
      VMG=CABS(VOLT(KS))                                                SXDOT     140
C                                                                       SXDOT     141
      IF (NRTYPN.LT.6) GOTO 190                                         SXDOT     142
C                                                                       SXDOT     143
C     TYPE 6 SVC -- NO DYNAMICS                                         SXDOT     144
C                                                                       SXDOT     145
      V1=DDAT(JS+1)                                                     SXDOT     146
      V2=DDAT(JS+2)                                                     SXDOT     147
      G1=DDAT(JS+3)                                                     SXDOT     148
      G2=DDAT(JS+4)                                                     SXDOT     149
      CALL SATFU(VMG,V1,V2,G1,G2,FACT)                                  SXDOT     150
      DDAT(JS+6)=FACT                                                   SXDOT     151
C                                                                       SXDOT     152
      GOTO 530                                                          SXDOT     153
C                                                                       SXDOT     154
  190 CONTINUE                                                          SXDOT     155
C                                                                       SXDOT     156
C     TYPE 1, 2 AND 3 SVC                                               SXDOT     157
C                                                                       SXDOT     158
      L=IDDAT(JS+10)                                                    SXDOT     159
      VL=CABS(VOLT(L))                                                  SXDOT     160
      BSVCX=BSVC(JY+2)/BASER(JY+4)                                      SXDOT     161
C                                                                       SXDOT     162
      IF (NRTYPN.NE.1) GOTO 290                                         SXDOT     163
C                                                                       SXDOT     164
C     TYPE 1 SVC                                                        SXDOT     165
C                                                                       SXDOT     166
      IF (ABS(VL-DDAT(JS+13)).LT.DBTOL) VL=DDAT(JS+13)                  SXDOT     167
C                                                                       SXDOT     168
      NSUBD=IDDAT(JS+12)                                                SXDOT     169
      VSUM=DDAT(JS+1)*(VL-RVREF(JY+1))                                  SXDOT     170
C                                                                       SXDOT     171
      NXS=0                                                             SXDOT     172
      X1=VSUM                                                           SXDOT     173
C                                                                       SXDOT     174
C     T1, T3 BLOCK                                                      SXDOT     175
C                                                                       SXDOT     176
      IF (IDDAT(JS+6).NE.0) THEN                                        SXDOT     177
         NXS=NXS+1                                                      SXDOT     178
         IWS1=JSTATE+NXS                                                SXDOT     179
         XDOT(IWS1)=(VSUM-XSTATE(IWS1))*DDAT(JS+6)                      SXDOT     180
         X1=XSTATE(IWS1)+DDAT(JS+4)*XDOT(IWS1)                          SXDOT     181
      END IF                                                            SXDOT     182
C                                                                       SXDOT     183
C     T2, T4 BLOCK                                                      SXDOT     184
C                                                                       SXDOT     185
      IF (IDDAT(JS+7).NE.0) THEN                                        SXDOT     186
         NXS=NXS+1                                                      SXDOT     187
         IWS1=JSTATE+NXS                                                SXDOT     188
         XDOT(IWS1)=(X1-XSTATE(IWS1))*DDAT(JS+7)                        SXDOT     189
         X1=XSTATE(IWS1)+DDAT(JS+5)*XDOT(IWS1)                          SXDOT     190
      END IF                                                            SXDOT     191
C                                                                       SXDOT     192
      XMIN=-DDAT(JS+3)                                                  SXDOT     193
      XMAX=1.0+XMIN                                                     SXDOT     194
C                                                                       SXDOT     195
      WSL=XMIN-ABS(XMIN)*DEADBD                                         SXDOT     196
      WSU=XMAX+ABS(XMAX)*DEADBD                                         SXDOT     197
C                                                                       SXDOT     198
      IF (X1.GT.WSU) THEN                                               SXDOT     199
         X1=WSU                                                         SXDOT     200
      ELSE IF (X1.LT.WSL) THEN                                          SXDOT     201
         X1=WSL                                                         SXDOT     202
      END IF                                                            SXDOT     203
C                                                                       SXDOT     204
C     T5 BLOCK                                                          SXDOT     205
C                                                                       SXDOT     206
      IF (IDDAT(JS+8).NE.0) THEN                                        SXDOT     207
         NXS=NXS+1                                                      SXDOT     208
         IWS1=JSTATE+NXS                                                SXDOT     209
         XDOT(IWS1)=(X1-XSTATE(IWS1))*DDAT(JS+8)                        SXDOT     210
         X1=XSTATE(IWS1)                                                SXDOT     211
         IF (X1.GE.XMAX) THEN                                           SXDOT     212
            IF (XDOT(IWS1).GT.0.0) XDOT(IWS1)=0.0                       SXDOT     213
            X1=XMAX                                                     SXDOT     214
         ELSE IF (X1.LE.XMIN) THEN                                      SXDOT     215
            IF (XDOT(IWS1).LT.0.0) XDOT(IWS1)=0.0                       SXDOT     216
            X1=XMIN                                                     SXDOT     217
         END IF                                                         SXDOT     218
      END IF                                                            SXDOT     219
C                                                                       SXDOT     220
      BSVC(JY+2)=X1*BASER(JY+4)                                         SXDOT     221
C                                                                       SXDOT     222
      GOTO 530                                                          SXDOT     223
C                                                                       SXDOT     224
  290 CONTINUE                                                          SXDOT     225
C                                                                       SXDOT     226
C     TYPE 2 AND 3 SVC                                                  SXDOT     227
C                                                                       SXDOT     228
      IF (NRTYPN.NE.2.AND.NRTYPN.NE.3) GOTO 530                         SXDOT     229
      INFLAG=0                                                          SXDOT     230
      VSCS=0.0                                                          SXDOT     231
      NXS=0                                                             SXDOT     232
C                                                                       SXDOT     233
      IF (NRTYPN.NE.3) GOTO 450                                         SXDOT     234
C                                                                       SXDOT     235
C     TYPE 3 SVC                                                        SXDOT     236
C                                                                       SXDOT     237
      IF (INFLAG.EQ.0) THEN                                             SXDOT     238
         INFLAG=1                                                       SXDOT     239
         MT1=IDDAT(JS+28)                                               SXDOT     240
         MT2=IDDAT(JS+29)                                               SXDOT     241
         IF (MT1.NE.0) GOTO 350                                         SXDOT     242
C                                                                       SXDOT     243
C     MT1 = LINE POWER                                                  SXDOT     244
C                                                                       SXDOT     245
         NLF1=IDDAT(JS+30)                                              SXDOT     246
         VRE=REAL(VOLT(NLF1))                                           SXDOT     247
         VIM=AIMAG(VOLT(NLF1))                                          SXDOT     248
         MLIN=IDDAT(JS+8)                                               SXDOT     249
         VI1=0.0                                                        SXDOT     250
         DO 340 I=1,MLIN                                                SXDOT     251
            LOC=IDDAT(JS+45+2*I)                                        SXDOT     252
            CALL GETCUR(CURR,CURI,LOC)                                  SXDOT     253
            VI1=VI1+VRE*CURR+VIM*CURI                                   SXDOT     254
  340    CONTINUE                                                       SXDOT     255
C                                                                       SXDOT     256
  350    IF (MT1.NE.1) GOTO 360                                         SXDOT     257
C                                                                       SXDOT     258
C     MT1 = BUS FREQUENCY                                               SXDOT     259
C                                                                       SXDOT     260
         NLF1=IDDAT(JS+31)                                              SXDOT     261
         VRE=REAL(VOLT(NLF1))                                           SXDOT     262
         VIM=AIMAG(VOLT(NLF1))                                          SXDOT     263
         VMG1=SQRT(VRE*VRE+VIM*VIM)                                     SXDOT     264
         IF (VMG1.GT.0.05) THEN                                         SXDOT     265
            VI1=ATAN2(VIM,VRE)                                          SXDOT     266
            VI1D=DDAT(JS+45)-VI1                                        SXDOT     267
            DDAT(JS+45)=VI1                                             SXDOT     268
            IF (VI1D.GT.3.15) THEN                                      SXDOT     269
               IDDAT(JS+44)=IDDAT(JS+44)+1                              SXDOT     270
            ELSE IF (VI1D.LT.-3.15) THEN                                SXDOT     271
               IDDAT(JS+44)=IDDAT(JS+44)-1                              SXDOT     272
            END IF                                                      SXDOT     273
            VI1=VI1+6.2831853*IDDAT(JS+44)                              SXDOT     274
         ELSE                                                           SXDOT     275
            VI1=DDAT(JS+45)+6.2831853*IDDAT(JS+44)                      SXDOT     276
         END IF                                                         SXDOT     277
         NXS=NXS+1                                                      SXDOT     278
         IWS1=JSTATE+NXS                                                SXDOT     279
         XDOT(IWS1)=(VI1-XSTATE(IWS1))*DDAT(JS+30)                      SXDOT     280
         VI1=XDOT(IWS1)/WXBASE                                          SXDOT     281
C                                                                       SXDOT     282
  360    IF (MT1.NE.2) GOTO 370                                         SXDOT     283
C                                                                       SXDOT     284
C     MT1 = GENERATOR ACCELERATION POWER                                SXDOT     285
C                                                                       SXDOT     286
         NLF1=IDDAT(JS+30)                                              SXDOT     287
         IDGEN=IDDAT(JS+31)                                             SXDOT     288
         JYGR=MYVAR(1,IDGEN)                                            SXDOT     289
         VI1=YVAR(JYGR+6)                                               SXDOT     290
C                                                                       SXDOT     291
C     VI1 = INPUT TO TS7 BLOCK                                          SXDOT     292
C                                                                       SXDOT     293
  370    IF (MT2.NE.0) GOTO 380                                         SXDOT     294
         VI2=VL                                                         SXDOT     295
  380    IF (MT2.NE.1) GOTO 390                                         SXDOT     296
         VI2=BSVCX*VMG**2                                               SXDOT     297
  390    IF (MT2.NE.2) GOTO 400                                         SXDOT     298
         VI2=BSVCX*VMG                                                  SXDOT     299
C                                                                       SXDOT     300
C     VI2 = INPUT TO TS10 BLOCK                                         SXDOT     301
C                                                                       SXDOT     302
  400    VI1=VI1*DDAT(JS+33)                                            SXDOT     303
         VI2=VI2*DDAT(JS+40)                                            SXDOT     304
      END IF                                                            SXDOT     305
C                                                                       SXDOT     306
      VI1X=VI1                                                          SXDOT     307
      VI2X=VI2                                                          SXDOT     308
C                                                                       SXDOT     309
C     TS7 BLOCK                                                         SXDOT     310
C                                                                       SXDOT     311
      IF (IDDAT(JS+34).NE.0) THEN                                       SXDOT     312
         NXS=NXS+1                                                      SXDOT     313
         IWS1=JSTATE+NXS                                                SXDOT     314
         XDOT(IWS1)=(VI1X-XSTATE(IWS1))*DDAT(JS+34)                     SXDOT     315
         VI1X=XSTATE(IWS1)                                              SXDOT     316
      END IF                                                            SXDOT     317
C                                                                       SXDOT     318
C     TS8, TS9 BLOCK                                                    SXDOT     319
C                                                                       SXDOT     320
      IF (IDDAT(JS+36).NE.0) THEN                                       SXDOT     321
         NXS=NXS+1                                                      SXDOT     322
         IWS1=JSTATE+NXS                                                SXDOT     323
         XDOT(IWS1)=(VI1X-XSTATE(IWS1))*DDAT(JS+36)                     SXDOT     324
         VI1X=XSTATE(IWS1)+DDAT(JS+35)*XDOT(IWS1)                       SXDOT     325
      END IF                                                            SXDOT     326
C                                                                       SXDOT     327
C     TS10 BLOCK                                                        SXDOT     328
C                                                                       SXDOT     329
      IF (IDDAT(JS+41).NE.0) THEN                                       SXDOT     330
         NXS=NXS+1                                                      SXDOT     331
         IWS1=JSTATE+NXS                                                SXDOT     332
         XDOT(IWS1)=(VI2X-XSTATE(IWS1))*DDAT(JS+41)                     SXDOT     333
         VI2X=XSTATE(IWS1)                                              SXDOT     334
      END IF                                                            SXDOT     335
C                                                                       SXDOT     336
C     TS11, TS12 BLOCK                                                  SXDOT     337
C                                                                       SXDOT     338
      IF (IDDAT(JS+43).NE.0) THEN                                       SXDOT     339
         NXS=NXS+1                                                      SXDOT     340
         IWS1=JSTATE+NXS                                                SXDOT     341
         XDOT(IWS1)=(VI2X-XSTATE(IWS1))*DDAT(JS+43)                     SXDOT     342
         VI2X=XSTATE(IWS1)+DDAT(JS+42)*XDOT(IWS1)                       SXDOT     343
      END IF                                                            SXDOT     344
C                                                                       SXDOT     345
C     TS13 BLOCK (COMPULSORY)                                           SXDOT     346
C                                                                       SXDOT     347
      VIN=VI1X+VI2X                                                     SXDOT     348
      NXS=NXS+1                                                         SXDOT     349
      IWS1=JSTATE+NXS                                                   SXDOT     350
      UMX=VIN-XSTATE(IWS1)                                              SXDOT     351
      XDOT(IWS1)=UMX*DDAT(JS+37)                                        SXDOT     352
      VSCS=UMX*DDAT(JS+38)                                              SXDOT     353
C                                                                       SXDOT     354
      VMAX=DDAT(JS+39)                                                  SXDOT     355
      VMIN=-VMAX                                                        SXDOT     356
      IF (VSCS.GT.VMAX) VSCS=VMAX                                       SXDOT     357
      IF (VSCS.LT.VMIN) VSCS=VMIN                                       SXDOT     358
C                                                                       SXDOT     359
  450 VIN=VL                                                            SXDOT     360
C                                                                       SXDOT     361
C     TYPE 2 SVC -- COMMON WITH TYPE 3 SVC                              SXDOT     362
C                                                                       SXDOT     363
C     TS1 BLOCK                                                         SXDOT     364
C                                                                       SXDOT     365
      IF (IDDAT(JS+1).NE.0) THEN                                        SXDOT     366
         NXS=NXS+1                                                      SXDOT     367
         IWS1=JSTATE+NXS                                                SXDOT     368
         XDOT(IWS1)=(VIN-XSTATE(IWS1))*DDAT(JS+1)                       SXDOT     369
         VIN=XSTATE(IWS1)                                               SXDOT     370
      END IF                                                            SXDOT     371
C                                                                       SXDOT     372
      VERR=VIN-RVREF(JY+1)                                              SXDOT     373
      VSUM=VERR+VSCS                                                    SXDOT     374
      VEMAX=DDAT(JS+2)                                                  SXDOT     375
      VEMIN=DDAT(JS+23)                                                 SXDOT     376
      VMAX=DDAT(JS+21)                                                  SXDOT     377
      VMIN=DDAT(JS+22)                                                  SXDOT     378
      NXS1=NXS                                                          SXDOT     379
      IF(VMAX.LT.0.0.OR.VMAX.GT.0.0.OR.VMIN.LT.0.0.OR.VMIN.GT.0.0) THEN SXDOT     380
C                                                                       SXDOT     381
C     TS2, TS3 BLOCK                                                    SXDOT     382
C                                                                       SXDOT     383
         IF (IDDAT(JS+4).NE.0) THEN                                     SXDOT     384
            NXS=NXS+1                                                   SXDOT     385
            IWS1=JSTATE+NXS                                             SXDOT     386
            XDOT(IWS1)=(VSUM-XSTATE(IWS1))*DDAT(JS+4)                   SXDOT     387
            VSUM=XSTATE(IWS1)+DDAT(JS+3)*XDOT(IWS1)                     SXDOT     388
            IF(VSUM.GE.VMAX) THEN                                       SXDOT     389
               VSUM=VMAX                                                SXDOT     390
               IF(XDOT(IWS1).GT.0.0) THEN                               SXDOT     391
                  IF(IDDAT(JS+3).EQ.0.0) THEN                           SXDOT     392
                     XDOT(IWS1)=0.0                                     SXDOT     393
                  ELSE                                                  SXDOT     394
                     XDOT(IWS1)=(VSUM-XSTATE(IWS1))/DDAT(JS+3)          SXDOT     395
                  ENDIF                                                 SXDOT     396
               ENDIF                                                    SXDOT     397
            ELSEIF(VSUM.LE.VMIN) THEN                                   SXDOT     398
               VSUM=VMIN                                                SXDOT     399
               IF(XDOT(IWS1).LT.0.0) THEN                               SXDOT     400
                  IF(IDDAT(JS+3).EQ.0.0) THEN                           SXDOT     401
                     XDOT(IWS1)=0.0                                     SXDOT     402
                  ELSE                                                  SXDOT     403
                     XDOT(IWS1)=(VSUM-XSTATE(IWS1))/DDAT(JS+3)          SXDOT     404
                  ENDIF                                                 SXDOT     405
               ENDIF                                                    SXDOT     406
            ENDIF                                                       SXDOT     407
         END IF                                                         SXDOT     408
C                                                                       SXDOT     409
C     TS4, TS5 BLOCK                                                    SXDOT     410
C                                                                       SXDOT     411
         IF (IDDAT(JS+6).NE.0) THEN                                     SXDOT     412
            NXS=NXS+1                                                   SXDOT     413
            IWS1=JSTATE+NXS                                             SXDOT     414
            TINV=DDAT(JS+6)                                             SXDOT     415
            TRAT=DDAT(JS+5)*TINV                                        SXDOT     416
            XDOT(IWS1)=(VSUM-XSTATE(IWS1))*DDAT(JS+6)                   SXDOT     417
            VSUM=XSTATE(IWS1)+DDAT(JS+5)*XDOT(IWS1)                     SXDOT     418
            IF(VSUM.GE.VEMAX) THEN                                      SXDOT     419
               VSUM=VEMAX                                               SXDOT     420
               IF(XDOT(IWS1).GT.0.0) THEN                               SXDOT     421
                  IF(IDDAT(JS+5).EQ.0.0) THEN                           SXDOT     422
                     XDOT(IWS1)=0.0                                     SXDOT     423
                  ELSE                                                  SXDOT     424
                     XDOT(IWS1)=(VSUM-XSTATE(IWS1))/DDAT(JS+5)          SXDOT     425
                  ENDIF                                                 SXDOT     426
               ENDIF                                                    SXDOT     427
            ELSEIF(VSUM.LE.VEMIN) THEN                                  SXDOT     428
               VSUM=VEMIN                                               SXDOT     429
               IF(XDOT(IWS1).LT.0.0) THEN                               SXDOT     430
                  IF(IDDAT(JS+5).EQ.0.0) THEN                           SXDOT     431
                     XDOT(IWS1)=0.0                                     SXDOT     432
                  ELSE                                                  SXDOT     433
                     XDOT(IWS1)=(VSUM-XSTATE(IWS1))/DDAT(JS+5)          SXDOT     434
                  ENDIF                                                 SXDOT     435
               ENDIF                                                    SXDOT     436
            ENDIF                                                       SXDOT     437
         END IF                                                         SXDOT     438
      ELSE                                                              SXDOT     439
         IF (VSUM.GT.VEMAX) VSUM=VEMAX                                  SXDOT     440
         IF (VSUM.LT.VEMIN) VSUM=VEMIN                                  SXDOT     441
C                                                                       SXDOT     442
C     TS2, TS3 BLOCK                                                    SXDOT     443
C                                                                       SXDOT     444
         IF (IDDAT(JS+4).NE.0) THEN                                     SXDOT     445
            NXS=NXS+1                                                   SXDOT     446
            IWS1=JSTATE+NXS                                             SXDOT     447
            XDOT(IWS1)=(VSUM-XSTATE(IWS1))*DDAT(JS+4)                   SXDOT     448
            VSUM=XSTATE(IWS1)+DDAT(JS+3)*XDOT(IWS1)                     SXDOT     449
         END IF                                                         SXDOT     450
C                                                                       SXDOT     451
C     TS4, TS5 BLOCK                                                    SXDOT     452
C                                                                       SXDOT     453
         IF (IDDAT(JS+6).NE.0) THEN                                     SXDOT     454
            NXS=NXS+1                                                   SXDOT     455
            IWS1=JSTATE+NXS                                             SXDOT     456
            TINV=DDAT(JS+6)                                             SXDOT     457
            TRAT=DDAT(JS+5)*TINV                                        SXDOT     458
            XDOT(IWS1)=(VSUM-XSTATE(IWS1))*DDAT(JS+6)                   SXDOT     459
            VSUM=XSTATE(IWS1)+DDAT(JS+5)*XDOT(IWS1)                     SXDOT     460
         END IF                                                         SXDOT     461
      END IF                                                            SXDOT     462
C                                                                       SXDOT     463
      SVCK=DDAT(JS+7)                                                   SXDOT     464
      BRIN=VSUM*SVCK                                                    SXDOT     465
C                                                                       SXDOT     466
      IF (IDDAT(JS+19).EQ.0) THEN                                       SXDOT     467
         DVHI=DDAT(JS+15)/SVCK                                          SXDOT     468
         DVLO=DDAT(JS+16)/SVCK                                          SXDOT     469
      ELSE                                                              SXDOT     470
         DVHI=DDAT(JS+19)                                               SXDOT     471
         DVLO=-DVHI                                                     SXDOT     472
      END IF                                                            SXDOT     473
C                                                                       SXDOT     474
C     FAST OVERRIDE BLOCK                                               SXDOT     475
C                                                                       SXDOT     476
      BPR=BRIN                                                          SXDOT     477
      IF (VERR.LT.DVHI) GOTO 500                                        SXDOT     478
      BPR=DDAT(JS+15)                                                   SXDOT     479
      IF (BPR.LT.BRIN) BPR=BRIN                                         SXDOT     480
      GOTO 510                                                          SXDOT     481
C                                                                       SXDOT     482
  500 IF (VERR.GT.DVLO) GOTO 510                                        SXDOT     483
      BPR=DDAT(JS+16)+DDAT(JS+13)*(DDAT(JS+19)+VERR)                    SXDOT     484
      IF (BPR.GT.BRIN) BPR=BRIN                                         SXDOT     485
C                                                                       SXDOT     486
  510 BMIN=-DDAT(JS+17)                                                 SXDOT     487
      BMAX=1.0+BMIN                                                     SXDOT     488
      IF (BPR.GT.BMAX) BPR=BMAX                                         SXDOT     489
      IF (BPR.LT.BMIN) BPR=BMIN                                         SXDOT     490
C                                                                       SXDOT     491
C     TS6 BLOCK                                                         SXDOT     492
C                                                                       SXDOT     493
      IF (IDDAT(JS+18).NE.0) THEN                                       SXDOT     494
         NXS=NXS+1                                                      SXDOT     495
         IWS1=JSTATE+NXS                                                SXDOT     496
         TINV=DDAT(JS+18)                                               SXDOT     497
         XDOT(IWS1)=(BPR-XSTATE(IWS1))*DDAT(JS+18)                      SXDOT     498
         BPR=XSTATE(IWS1)                                               SXDOT     499
         IF (BPR.GE.BMAX) THEN                                          SXDOT     500
            BPR=BMAX                                                    SXDOT     501
            IF (XDOT(IWS1).GT.0.0) XDOT(IWS1)=0.0                       SXDOT     502
         ELSE IF (BPR.LE.BMIN) THEN                                     SXDOT     503
            BPR=BMIN                                                    SXDOT     504
            IF (XDOT(IWS1).LT.0.0) XDOT(IWS1)=0.0                       SXDOT     505
         END IF                                                         SXDOT     506
      END IF                                                            SXDOT     507
C                                                                       SXDOT     508
      IF(DDAT(JS+20).GT.-0.1) THEN                                      SXDOT     509
         IF(-VERR.LT.DDAT(JS+25)) THEN                                  SXDOT     510
            DDAT(JS+20)=TS                                              SXDOT     511
         ELSE                                                           SXDOT     512
            TDD=TS-DDAT(JS+20)                                          SXDOT     513
            IF(TDD.GE.DDAT(JS+27)) THEN                                 SXDOT     514
               DDAT(JS+20)=-1.0                                         SXDOT     515
               DDAT(JS+24)=DDAT(JS+24)+DDAT(JS+26)                      SXDOT     516
            ENDIF                                                       SXDOT     517
         ENDIF                                                          SXDOT     518
      ENDIF                                                             SXDOT     519
      BSVC(JY+2)=(BPR-DDAT(JS+24))*BASER(JY+4)                          SXDOT     520
C                                                                       SXDOT     521
  530 CONTINUE                                                          SXDOT     522
C                                                                       SXDOT     523
C     UPDATE JACOBIAN MATRICES IF NECESSARY                             SXDOT     524
C                                                                       SXDOT     525
      IF (NRTYPN.GT.5.AND.NRTYPN.NE.50) GOTO 540                        SXDOT     526
C                                                                       SXDOT     527
      IF (NITER.GT.0) GOTO 550                                          SXDOT     528
C                                                                       SXDOT     529
      EPD=REAL(VOLT(KS))                                                SXDOT     530
      EPQ=AIMAG(VOLT(KS))                                               SXDOT     531
      BSVCS=BSVC(JY+2)                                                  SXDOT     532
      BSRAT=BASER(JY+4)                                                 SXDOT     533
      IF (NRTYPN.LE.5) THEN                                             SXDOT     534
         KR=IDDAT(JS+10)                                                SXDOT     535
         VSR=REAL(VOLT(KR))                                             SXDOT     536
         VSI=AIMAG(VOLT(KR))                                            SXDOT     537
         VSM=SQRT(VSR*VSR+VSI*VSI)                                      SXDOT     538
      END IF                                                            SXDOT     539
      CALL SVCLN(1,KS,L,EPD,EPQ,ISTATE)                                 SXDOT     540
C                                                                       SXDOT     541
C     UPDATE COUNTERS                                                   SXDOT     542
C                                                                       SXDOT     543
  550 CONTINUE                                                          SXDOT     544
      IAIDEX=IAIDEX+ISTATE*ISTATE                                       SXDOT     545
      ICIDEX=ICIDEX+2*ISTATE                                            SXDOT     546
C                                                                       SXDOT     547
  560 IBIDEX=IBIDEX+1                                                   SXDOT     548
      KS=IBJCOB(IBIDEX)                                                 SXDOT     549
      IF (KS.EQ.0) GOTO 540                                             SXDOT     550
      IBIDEX=IBIDEX+2*ISTATE                                            SXDOT     551
      GOTO 560                                                          SXDOT     552
C                                                                       SXDOT     553
  540 CONTINUE                                                          SXDOT     554
C                                                                       SXDOT     555
      RETURN                                                            SXDOT     556
      END                                                               SXDOT     557
