CFPRIME DSTAB4                                                          DSTAB4      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 DSTAB4(NXS,NWSS)                                       DSTAB4      3
CD                                                                      DSTAB4      4
CD    TO CALCULATE THE DERIVATIVES OF THE STATES OF TYPES 4, 5, 6 AND 7 DSTAB4      5
CD    STABILIZER, USED BY BOTH RUNGE-KUTTA AND TRAPEZOIDAL METHOD.      DSTAB4      6
CD                                                                      DSTAB4      7
CD    THE DATA STRUCTURES OF THESE TYPES OF STABILIZERS ARE GIVEN BELOW.DSTAB4      8
CD                                                                      DSTAB4      9
CD   4.4 Stabilizer type 4                                              DSTAB4     10
CD                                                                      DSTAB4     11
CD     Stabilizer data                                                  DSTAB4     12
CD                                                                      DSTAB4     13
CD     IDDAT(JS+1)    = BUSR         : sensing bus number               DSTAB4     14
CD     IDDAT(JS+2)    = TYPE         : type of input signal:            DSTAB4     15
CD                                     = 1 rotor speed                  DSTAB4     16
CD                                     = 2 acceleration power           DSTAB4     17
CD                                     = 3 bus frequency                DSTAB4     18
CD                                     = 4 electrical power             DSTAB4     19
CD                                     = 5 bus voltage magnitude        DSTAB4     20
CD                                     = 6 voltage deviation from steadyDSTAB4     21
CD                                        state value                   DSTAB4     22
CD     DDAT(JS+ 3)    = KS                                              DSTAB4     23
CD     DDAT(JS+ 4)    = T5                                              DSTAB4     24
CD     DDAT(JS+ 5)    = T1                                              DSTAB4     25
CD     DDAT(JS+ 6)    = T2                                              DSTAB4     26
CD     DDAT(JS+ 7)    = T3                                              DSTAB4     27
CD     DDAT(JS+ 8)    = T4                                              DSTAB4     28
CD     DDAT(JS+ 9)    = VSMAX                                           DSTAB4     29
CD     DDAT(JS+10)    = VSMIN                                           DSTAB4     30
CD     DDAT(JS+11)    = TF                                              DSTAB4     31
CD     DDAT(JS+12)    = RC                                              DSTAB4     32
CD     DDAT(JS+13)    = XC                                              DSTAB4     33
CD     DDAT(JS+14)    = PTHR                                            DSTAB4     34
CD                                                                      DSTAB4     35
CD     Stabilizer states                                                DSTAB4     36
CD                                                                      DSTAB4     37
CD     XSTATE(JSS+1)  = TF block if input is bus frequency              DSTAB4     38
CD                                                  : optional          DSTAB4     39
CD     XSTATE(JSS+2)  = T5 block                    : compulsory        DSTAB4     40
CD     XSTATE(JSS+3)  = first state of T2/T4 block  : optional          DSTAB4     41
CD     XSTATE(JSS+4)  = second state of T2/T4 block : optional          DSTAB4     42
CD                                                                      DSTAB4     43
CD     Stabilizer Y-variables                                           DSTAB4     44
CD                                                                      DSTAB4     45
CD     VSS(JYS+1)     = stabilizer output                               DSTAB4     46
CD                                                                      DSTAB4     47
CD   4.5 Stabilizer type 5                                              DSTAB4     48
CD                                                                      DSTAB4     49
CD     Stabilizer data                                                  DSTAB4     50
CD                                                                      DSTAB4     51
CD     IDDAT(JS+1)    = BUSR         : sensing bus number               DSTAB4     52
CD     IDDAT(JS+2)    = TYPE         : type of input signal:            DSTAB4     53
CD                                     = 1 rotor speed                  DSTAB4     54
CD                                     = 2 acceleration power           DSTAB4     55
CD                                     = 3 bus frequency                DSTAB4     56
CD                                     = 4 electrical power             DSTAB4     57
CD                                     = 5 bus voltage magnitude        DSTAB4     58
CD                                     = 6 voltage deviation from steadyDSTAB4     59
CD                                        state value                   DSTAB4     60
CD     DDAT(JS+ 3)    = KS                                              DSTAB4     61
CD     DDAT(JS+ 4)    = T5                                              DSTAB4     62
CD     DDAT(JS+ 5)    = T1                                              DSTAB4     63
CD     DDAT(JS+ 6)    = T2                                              DSTAB4     64
CD     DDAT(JS+ 7)    = T3                                              DSTAB4     65
CD     DDAT(JS+ 8)    = T4                                              DSTAB4     66
CD     DDAT(JS+ 9)    = VSMAX                                           DSTAB4     67
CD     DDAT(JS+10)    = VSMIN                                           DSTAB4     68
CD     DDAT(JS+11)    = TF                                              DSTAB4     69
CD     DDAT(JS+12)    = RC                                              DSTAB4     70
CD     DDAT(JS+13)    = XC                                              DSTAB4     71
CD     DDAT(JS+14)    = PTHR                                            DSTAB4     72
CD     DDAT(JS+15)    = KANG                                            DSTAB4     73
CD     DDAT(JS+16)    = TANG                                            DSTAB4     74
CD     DDAT(JS+17)    = DWTHR                                           DSTAB4     75
CD     DDAT(JS+18)    = EIHR                                            DSTAB4     76
CD     DDAT(JS+19)    = VS3MX                                           DSTAB4     77
CD     DDAT(JS+20)    = VS3MN                                           DSTAB4     78
CD     DDAT(JS+21)    = VANGM                                           DSTAB4     79
CD     DDAT(JS+22)    = VANGMX                                          DSTAB4     80
CD                                                                      DSTAB4     81
CD     Stabilizer states                                                DSTAB4     82
CD                                                                      DSTAB4     83
CD     XSTATE(JSS+1)  = TF block if input is bus frequency              DSTAB4     84
CD                                                  : optional          DSTAB4     85
CD     XSTATE(JSS+2)  = T5 block                    : compulsory        DSTAB4     86
CD     XSTATE(JSS+3)  = first state of T2/T4 block  : optional          DSTAB4     87
CD     XSTATE(JSS+4)  = second state of T2/T4 block : optional          DSTAB4     88
CD     XSTATE(JSS+5)  = TANG block                       : compulsory   DSTAB4     89
CD                                                                      DSTAB4     90
CD     Stabilizer Y-variables                                           DSTAB4     91
CD                                                                      DSTAB4     92
CD     VSS(JYS+1)     = stabilizer output                               DSTAB4     93
CD                                                                      DSTAB4     94
CD   4.6 Stabilizer type 6                                              DSTAB4     95
CD                                                                      DSTAB4     96
CD     Stabilizer data                                                  DSTAB4     97
CD                                                                      DSTAB4     98
CD     IDDAT(JS+1)    = BUSR         : sensing bus number               DSTAB4     99
CD     IDDAT(JS+2)    = TYPE         : type of input signal:            DSTAB4    100
CD                                     = 1 rotor speed                  DSTAB4    101
CD                                     = 2 acceleration power           DSTAB4    102
CD                                     = 3 bus frequency                DSTAB4    103
CD                                     = 4 electrical power             DSTAB4    104
CD                                     = 5 bus voltage magnitude        DSTAB4    105
CD                                     = 6 voltage deviation from steadyDSTAB4    106
CD                                        state value                   DSTAB4    107
CD     DDAT(JS+ 3)    = KS                                              DSTAB4    108
CD     DDAT(JS+ 4)    = T5                                              DSTAB4    109
CD     DDAT(JS+ 5)    = T1                                              DSTAB4    110
CD     DDAT(JS+ 6)    = T2                                              DSTAB4    111
CD     DDAT(JS+ 7)    = T3                                              DSTAB4    112
CD     DDAT(JS+ 8)    = T4                                              DSTAB4    113
CD     DDAT(JS+ 9)    = VSMAX                                           DSTAB4    114
CD     DDAT(JS+10)    = VSMIN                                           DSTAB4    115
CD     DDAT(JS+11)    = TF                                              DSTAB4    116
CD     DDAT(JS+12)    = RC                                              DSTAB4    117
CD     DDAT(JS+13)    = XC                                              DSTAB4    118
CD     DDAT(JS+14)    = PTHR                                            DSTAB4    119
CD     DDAT(JS+15)    = KANG                                            DSTAB4    120
CD     DDAT(JS+16)    = TANG                                            DSTAB4    121
CD     DDAT(JS+17)    = DWTHR                                           DSTAB4    122
CD     DDAT(JS+18)    = ETHR                                            DSTAB4    123
CD     DDAT(JS+19)    = VS3MX                                           DSTAB4    124
CD     DDAT(JS+20)    = VS3MN                                           DSTAB4    125
CD     DDAT(JS+21)    = VANGM                                           DSTAB4    126
CD     DDAT(JS+22)    = VANGMX                                          DSTAB4    127
CD                                                                      DSTAB4    128
CD     Stabilizer states                                                DSTAB4    129
CD                                                                      DSTAB4    130
CD     XSTATE(JSS+1)  = TF block if input is bus frequency              DSTAB4    131
CD                                                  : optional          DSTAB4    132
CD     XSTATE(JSS+2)  = T5 block                    : compulsory        DSTAB4    133
CD     XSTATE(JSS+3)  = first state of T2/T4 block  : optional          DSTAB4    134
CD     XSTATE(JSS+4)  = second state of T2/T4 block : optional          DSTAB4    135
CD     XSTATE(JSS+5)  = TANG block                       : compulsory   DSTAB4    136
CD                                                                      DSTAB4    137
CD     Stabilizer Y-variables                                           DSTAB4    138
CD                                                                      DSTAB4    139
CD     VSS(JYS+1)     = stabilizer output                               DSTAB4    140
CD                                                                      DSTAB4    141
CD   4.7 Stabilizer type 7                                              DSTAB4    142
CD                                                                      DSTAB4    143
CD     Not functional                                                   DSTAB4    144
CD                                                                      DSTAB4    145
      INCLUDE 'PARX.INS'                                                DSTAB4    146
      INCLUDE 'CNMDAT.INS'                                              DSTAB4    147
      INCLUDE 'CNEXC.INS'                                               DSTAB4    148
      INCLUDE 'CNXSTA.INS'                                              DSTAB4    149
      INCLUDE 'CNQSTA.INS'                                              DSTAB4    150
      INCLUDE 'CNYVAR.INS'                                              DSTAB4    151
      INCLUDE 'CNPRGV.INS'                                              DSTAB4    152
      INCLUDE 'CNFLAG.INS'                                              DSTAB4    153
      INCLUDE 'CNUNIT.INS'                                              DSTAB4    154
      INCLUDE 'CNB9.INS'                                                DSTAB4    155
C                                                                       DSTAB4    156
*IF DEBUG                                                               DSTAB4    157
      LDEB=(JDEB(85).NE.0)                                              DSTAB4    158
*ENDIF                                                                  DSTAB4    159
C                                                                       DSTAB4    160
      NXS=KSTATE                                                        DSTAB4    161
C                                                                       DSTAB4    162
C TYPE 7 STABILIZER                                                     DSTAB4    163
C                                                                       DSTAB4    164
      IF (ISTABN.EQ.7) THEN                                             DSTAB4    165
         NXS=NXS+1                                                      DSTAB4    166
         VSUM=DDAT(JS+2)*XSTATE(IDOMG)+DDAT(JS+3)*PDGN                  DSTAB4    167
         IF (IGVN.NE.0) VSUM=VSUM+DDAT(JS+4)*CVP(JYP+2)                 DSTAB4    168
         DSTATE(LSTATE+NXS)=VSUM-XSTATE(JSTATE+NXS)/DDAT(JS+5)          DSTAB4    169
C                                                                       DSTAB4    170
         IF(VSX.GT.DDAT(JS+8)) VSX=DDAT(JS+8)                           DSTAB4    171
         IF(VSX.LT.DDAT(JS+9)) VSX=DDAT(JS+9)                           DSTAB4    172
         VSS(JYS+1)=VSX                                                 DSTAB4    173
      ELSE                                                              DSTAB4    174
C                                                                       DSTAB4    175
C   ISTAB=4,5,6                                                         DSTAB4    176
C                                                                       DSTAB4    177
         NS1=NXS+1                                                      DSTAB4    178
C                                                                       DSTAB4    179
*IF DEBUG                                                               DSTAB4    180
       IF (LDEB) WRITE(IUD6,7110) VSI1                                  DSTAB4    181
*ENDIF                                                                  DSTAB4    182
C                                                                       DSTAB4    183
         DSTATE(LSTATE+NS1)=(DDAT(JS+3)*VSI1-XSTATE(JSTATE+NS1))        DSTAB4    184
     *                      /DDAT(JS+4)                                 DSTAB4    185
         VS1=DDAT(JS+4)*DSTATE(LSTATE+NS1)                              DSTAB4    186
C                                                                       DSTAB4    187
*IF DEBUG                                                               DSTAB4    188
       IF(LDEB)WRITE(IUD6,7120) NS1,JSTATE,LSTATE,XSTATE(LSTATE+NS1),   DSTAB4    189
     +                 DSTATE(LSTATE+NS1)                               DSTAB4    190
*ENDIF                                                                  DSTAB4    191
        IF(IDDAT(JS+6).EQ.0.AND.IDDAT(JS+8).EQ.0) GOTO 50               DSTAB4    192
        IF(IDDAT(JS+8).NE.0)THEN                                        DSTAB4    193
           NS2=NXS+2                                                    DSTAB4    194
           NS3=NXS+3                                                    DSTAB4    195
           DSTATE(LSTATE+NS2)=VS1-(DDAT(JS+6)*XSTATE(JSTATE+NS2)+       DSTAB4    196
     +                        XSTATE(JSTATE+NS3))/DDAT(JS+8)            DSTAB4    197
           DSTATE(LSTATE+NS3)=XSTATE(JSTATE+NS2)                        DSTAB4    198
           TLDG=DDAT(JS+7)/DDAT(JS+8)                                   DSTAB4    199
           VSX=XSTATE(JSTATE+NS3)*(1.-TLDG)                             DSTAB4    200
           VSX=VSX+XSTATE(JSTATE+NS2)*(DDAT(JS+5)-DDAT(JS+6)*TLDG)      DSTAB4    201
           VSX=VSX/DDAT(JS+8)+VS1*TLDG                                  DSTAB4    202
           NS=NS3                                                       DSTAB4    203
        ELSE                                                            DSTAB4    204
           NS2=NXS+2                                                    DSTAB4    205
           DSTATE(LSTATE+NS2)=(VS1-XSTATE(JSTATE+NS2))/DDAT(JS+6)       DSTAB4    206
           VSX=XSTATE(JSTATE+NS2)+DDAT(JS+5)*DSTATE(LSTATE+NS2)         DSTAB4    207
           NS=NS2                                                       DSTAB4    208
        ENDIF                                                           DSTAB4    209
  50    CONTINUE                                                        DSTAB4    210
C                                                                       DSTAB4    211
*IF DEBUG                                                               DSTAB4    212
      IF(LDEB)WRITE(IUD6,7130)NS2,XSTATE(JSTATE+NS2),DSTATE(LSTATE+NS2),DSTAB4    213
     +                NS3,XSTATE(JSTATE+NS3),DSTATE(LSTATE+NS3)         DSTAB4    214
*ENDIF                                                                  DSTAB4    215
C                                                                       DSTAB4    216
           IF (ISTABN.EQ.4) THEN                                        DSTAB4    217
              IF(VSX.GT.DDAT(JS+9)) VSX=DDAT(JS+9)                      DSTAB4    218
              IF(VSX.LT.DDAT(JS+10)) VSX=DDAT(JS+10)                    DSTAB4    219
              GOTO 100                                                  DSTAB4    220
           ENDIF                                                        DSTAB4    221
C                                                                       DSTAB4    222
C   ISTAB=5 & 6 : S1-ANG BLOCK-S2 PATH                                  DSTAB4    223
C       IDDAT(JS+23) IS THE STATUS OF S1 : = 0  ORIGINALLY OPEN         DSTAB4    224
C                                          = 1  CLOSE                   DSTAB4    225
C                                          = 2  REOPEN AND STAY OPENED  DSTAB4    226
C                                                                       DSTAB4    227
          XANG=0.0                                                      DSTAB4    228
          IF (IDDAT(JS+23).NE.2)THEN                                    DSTAB4    229
             IF (ET.LT.DDAT(JS+18).AND.XVARB.GE.REFMX.AND.VSI1.GE.      DSTAB4    230
     +           DDAT(JS+17)) IDDAT(JS+23)=1                            DSTAB4    231
             IF (IDDAT(JS+23).EQ.1) XANG=VSI1*DDAT(JS+15)               DSTAB4    232
          ENDIF                                                         DSTAB4    233
C==                                                                     DSTAB4    234
C       WRITE(IUD6,711) IDDAT(JS+23),XANG,VSX                           DSTAB4    235
C  711  FORMAT(1X,'DB-DSTAB4:IDDAT21,XANG,VSX ',I5,2G12.5)              DSTAB4    236
C==                                                                     DSTAB4    237
          NS=NS+1                                                       DSTAB4    238
          DSTATE(LSTATE+NS)=(XANG-XSTATE(JSTATE+NS))/DDAT(JS+16)        DSTAB4    239
          VANG=XSTATE(JSTATE+NS)                                        DSTAB4    240
C==                                                                     DSTAB4    241
C       WRITE(IUD6,721) JSTATE,NS,DSTATE(JSTATE+NS),VANG                DSTAB4    242
C  721  FORMAT(1X,'DB-DSTAB4:JSTATE,NS4,DX,VANG ',2I2,2G12.5)           DSTAB4    243
C==                                                                     DSTAB4    244
          IF (VANG.GE.DDAT(JS+21)) THEN                                 DSTAB4    245
             VANG=DDAT(JS+21)                                           DSTAB4    246
             IF (DSTATE(LSTATE+NS).GT.0.0) THEN                         DSTAB4    247
                DSTATE(LSTATE+NS)=0.0                                   DSTAB4    248
                QSTATE(JSTATE+NS)=0.0                                   DSTAB4    249
             END IF                                                     DSTAB4    250
          END IF                                                        DSTAB4    251
C==                                                                     DSTAB4    252
C       WRITE(IUD6,722) DSTATE(JSTATE+NS),VANG,VSX                      DSTAB4    253
C  722  FORMAT(1X,'DB-DSTAB4:DX,VANG,VSX ',3G12.5)                      DSTAB4    254
C==                                                                     DSTAB4    255
          IF (ISTABN.EQ.6) THEN                                         DSTAB4    256
             IF (VSI1.LT.0.0) THEN                                      DSTAB4    257
                VANG=0.0                                                DSTAB4    258
                IDDAT(JS+24)=0                                          DSTAB4    259
             ELSE                                                       DSTAB4    260
                IDDAT(JS+24)=1                                          DSTAB4    261
             END IF                                                     DSTAB4    262
          END IF                                                        DSTAB4    263
C==                                                                     DSTAB4    264
C       WRITE(IUD6,712) VANG,VSX                                        DSTAB4    265
C  712  FORMAT(1X,'DB-DSTAB4:VANG,VSX ',3G12.5)                         DSTAB4    266
C==                                                                     DSTAB4    267
C                                                                       DSTAB4    268
*IF DEBUG                                                               DSTAB4    269
      IF(LDEB)WRITE(IUD6,7140) NS,XSTATE(JSTATE+NS),DSTATE(LSTATE+NS)   DSTAB4    270
     +,VANG                                                             DSTAB4    271
*ENDIF                                                                  DSTAB4    272
C                                                                       DSTAB4    273
C      LIMITERS ON VANG,VSX; SUMIMG JUNCTION; LIMITER ON VSS            DSTAB4    274
C                                                                       DSTAB4    275
*IF DEBUG                                                               DSTAB4    276
      IF(LDEB) WRITE(IUD6,7160) VANG,VSX                                DSTAB4    277
*ENDIF                                                                  DSTAB4    278
C                                                                       DSTAB4    279
          IF (VANG.GT.DDAT(JS+22)) VANG=DDAT(JS+22)                     DSTAB4    280
          IF (VANG.LT.0.0) VANG=0.0                                     DSTAB4    281
          IF (VSX.GT.DDAT(JS+19)) VSX=DDAT(JS+19)                       DSTAB4    282
          IF (VSX.LT.DDAT(JS+20)) VSX=DDAT(JS+20)                       DSTAB4    283
C==                                                                     DSTAB4    284
C       WRITE(IUD6,712) VANG,VSX                                        DSTAB4    285
C==                                                                     DSTAB4    286
C          YVAR(JYS+3)=VANG                                             DSTAB4    287
C          YVAR(JYS+4)=VSX                                              DSTAB4    288
C==                                                                     DSTAB4    289
C       WRITE(IUD6,713) JYS,YVAR(JYS+3),YVAR(JYS+4)                     DSTAB4    290
C  713  FORMAT(1X,'DB-DSTAB4:JYS,Y3-4 ',I5,2G12.5)                      DSTAB4    291
C==                                                                     DSTAB4    292
          VSX=VSX+VANG                                                  DSTAB4    293
C                                                                       DSTAB4    294
*IF DEBUG                                                               DSTAB4    295
      IF(LDEB) WRITE(IUD6,7160) VANG,VSX                                DSTAB4    296
*ENDIF                                                                  DSTAB4    297
C                                                                       DSTAB4    298
          IF (VSX.GT.DDAT(JS+9)) VSX=DDAT(JS+9)                         DSTAB4    299
          IF (VSX.LT.DDAT(JS+10)) VSX=DDAT(JS+10)                       DSTAB4    300
C                                                                       DSTAB4    301
*IF DEBUG                                                               DSTAB4    302
      IF(LDEB) WRITE(IUD6,7160) VANG,VSX                                DSTAB4    303
*ENDIF                                                                  DSTAB4    304
C                                                                       DSTAB4    305
C     CHECK IF SW1 SHOULD REOPEN                                        DSTAB4    306
C                                                                       DSTAB4    307
          IF (LIR4.AND.IDDAT(JS+23).EQ.1) THEN                          DSTAB4    308
             IF(XVARB.LT.REFMX.OR.VSI1.LT.DDAT(JS+17)) IDDAT(JS+23)=2   DSTAB4    309
          ENDIF                                                         DSTAB4    310
C                                                                       DSTAB4    311
  100    NXS=NS                                                         DSTAB4    312
         VSS(JYS+1)=VSX                                                 DSTAB4    313
C                                                                       DSTAB4    314
*IF DEBUG                                                               DSTAB4    315
       IF(LDEB) WRITE(IUD6,7170) VSX,JYS,VSS(JYS+1)                     DSTAB4    316
*ENDIF                                                                  DSTAB4    317
C                                                                       DSTAB4    318
C                                                                       DSTAB4    319
       ENDIF                                                            DSTAB4    320
C                                                                       DSTAB4    321
      LSTATE=LSTATE+NXS                                                 DSTAB4    322
      JSTATE=JSTATE+NXS                                                 DSTAB4    323
      NWSS=JSTATE                                                       DSTAB4    324
C==                                                                     DSTAB4    325
C      WRITE(IUD6,723) NWSS                                             DSTAB4    326
C  723 FORMAT(1X,'DB-DSTAB4:NWSS ',I5)                                  DSTAB4    327
C==                                                                     DSTAB4    328
C                                                                       DSTAB4    329
*IF DEBUG                                                               DSTAB4    330
      IF(LDEB)WRITE(IUD6,1100) JS,LSTATE,(IDDAT(JS+LK),LK=1,2)          DSTAB4    331
     &,(DDAT(JS+LK),LK=3,17)                                            DSTAB4    332
*ENDIF                                                                  DSTAB4    333
C                                                                       DSTAB4    334
      RETURN                                                            DSTAB4    335
C                                                                       DSTAB4    336
 1100 FORMAT(1X,'DB-DSTAB:JS,LSTATE,DDAT(1:17) ',2I5,2X,2I5,/,          DSTAB4    337
     & (8X,10G12.5))                                                    DSTAB4    338
 7110  FORMAT(1X,'DB-DSTAB4:VSI1 ',G12.5)                               DSTAB4    339
 7120  FORMAT(1X,'DB-DSTAB4:NS1,JSTATE,LSTATE,X,DX ',3I5,2G12.5)        DSTAB4    340
 7130 FORMAT(1X,'DB-DSTAB4:NS2,X2,DX2,NS3,X3,DX3 ',2(I5,2G12.5))        DSTAB4    341
 7140 FORMAT(1X,'DB-DSTAB4:NS4,X4,DX4 ',I5,3G12.5)                      DSTAB4    342
 7160 FORMAT(1X,'DB-DSTAB4:VANG,VSX ',2G12.5)                           DSTAB4    343
 7170  FORMAT(1X,'DB-DSTAB4:VSX,JYS,VSS ',G12.5,I5,G12.5)               DSTAB4    344
C                                                                       DSTAB4    345
      END                                                               DSTAB4    346
