CFPRIME DE1N2                                                           DE1N2       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 DE1N2(H)                                               DE1N2       3
CD                                                                      DE1N2       4
CD    TO CALCULATE THE DERIVATIVES OF THE STATES OF TYPES 1 AND 2       DE1N2       5
CD    EXCITER, USED BY BOTH RUNGE-KUTTA AND TRAPEZOIDAL METHOD.         DE1N2       6
CD                                                                      DE1N2       7
CD    THE DATA STRUCTURE FOR THIS TYPE OF EXCITER IS GIVEN BELOW.       DE1N2       8
CD                                                                      DE1N2       9
CD   3.1 Exciter types 1 and 2                                          DE1N2      10
CD                                                                      DE1N2      11
CD     Exciter data                                                     DE1N2      12
CD                                                                      DE1N2      13
CD     IDDAT(JE+1)    = IVTN         : sensing bus number               DE1N2      14
CD     DDAT(JE+ 2)    = KA                                              DE1N2      15
CD     DDAT(JE+ 3)    = TA                                              DE1N2      16
CD     DDAT(JE+ 4)    = KE                                              DE1N2      17
CD     DDAT(JE+ 5)    = TE                                              DE1N2      18
CD     DDAT(JE+ 6)    = SE(VSAT) or AEX                                 DE1N2      19
CD     DDAT(JE+ 7)    = SE(0.75VSAT) or BEX                             DE1N2      20
CD     DDAT(JE+ 8)    = VSAT                                            DE1N2      21
CD     DDAT(JE+ 9)    = (reserved for future use)                       DE1N2      22
CD     DDAT(JE+10)    = KF                                              DE1N2      23
CD     DDAT(JE+11)    = TF                                              DE1N2      24
CD     DDAT(JE+12)    = TC                                              DE1N2      25
CD     DDAT(JE+13)    = TB                                              DE1N2      26
CD     DDAT(JE+14)    = VRMAX                                           DE1N2      27
CD     DDAT(JE+15)    = VRMIN                                           DE1N2      28
CD     DDAT(JE+16)    = ETV                                             DE1N2      29
CD     DDAT(JE+17)    = ETMIN                                           DE1N2      30
CD     DDAT(JE+18)    = TR                                              DE1N2      31
CD     DDAT(JE+19)    = RC                                              DE1N2      32
CD     DDAT(JE+20)    = XC                                              DE1N2      33
CD                                                                      DE1N2      34
CD     Exciter states                                                   DE1N2      35
CD                                                                      DE1N2      36
CD     XSTATE(JES+1)  = TR block     : compulsory                       DE1N2      37
CD     XSTATE(JES+2)  = TF block     : compulsory                       DE1N2      38
CD     XSTATE(JES+3)  = TB block     : compulsory                       DE1N2      39
CD     XSTATE(JES+4)  = TA block     : compulsory                       DE1N2      40
CD     XSTATE(JES+5)  = TE block     : compulsory                       DE1N2      41
CD                                                                      DE1N2      42
CD     Exciter Y-variables                                              DE1N2      43
CD                                                                      DE1N2      44
CD     VREG(JYE+1)    = VC (input to the TR block)                      DE1N2      45
CD     VREF(JYE+2)    = reference value                                 DE1N2      46
CD                                                                      DE1N2      47
      INCLUDE 'PARX.INS'                                                DE1N2      48
      INCLUDE 'CNPT.INS'                                                DE1N2      49
      INCLUDE 'CNVOLT.INS'                                              DE1N2      50
      INCLUDE 'CNIPTR.INS'                                              DE1N2      51
      INCLUDE 'CNMDAT.INS'                                              DE1N2      52
      INCLUDE 'CNB3.INS'                                                DE1N2      53
      INCLUDE 'CNB5.INS'                                                DE1N2      54
      INCLUDE 'CNB8.INS'                                                DE1N2      55
      INCLUDE 'CNB9.INS'                                                DE1N2      56
      INCLUDE 'CNB10.INS'                                               DE1N2      57
      INCLUDE 'CNB19.INS'                                               DE1N2      58
      INCLUDE 'CNEXC.INS'                                               DE1N2      59
      INCLUDE 'CNXSTA.INS'                                              DE1N2      60
      INCLUDE 'CNQSTA.INS'                                              DE1N2      61
      INCLUDE 'CNMYVA.INS'                                              DE1N2      62
      INCLUDE 'CNYVAR.INS'                                              DE1N2      63
      INCLUDE 'CNPREV.INS'                                              DE1N2      64
      INCLUDE 'CNIMPR.INS'                                              DE1N2      65
C                                                                       DE1N2      66
      LOGICAL SLOGIC                                                    DE1N2      67
C                                                                       DE1N2      68
C     DECIDE IF SMALLER TIME STEP SHOULD BE TAKEN                       DE1N2      69
C                                                                       DE1N2      70
      DELT=0.0                                                          DE1N2      71
      IF (IDDAT(JE+21).NE.0) THEN                                       DE1N2      72
         IF (H.LE.DDAT(JE+22)) THEN                                     DE1N2      73
            SLOGIC=.FALSE.                                              DE1N2      74
            KTM=1                                                       DE1N2      75
         ELSE                                                           DE1N2      76
            SLOGIC=.TRUE.                                               DE1N2      77
            KTM=INT(H/DDAT(JE+22)/KSBINT)+1                             DE1N2      78
            DELT=H/KTM/KSBINT                                           DE1N2      79
         END IF                                                         DE1N2      80
      ELSE                                                              DE1N2      81
         SLOGIC=.FALSE.                                                 DE1N2      82
         KTM=1                                                          DE1N2      83
      END IF                                                            DE1N2      84
C                                                                       DE1N2      85
      VRMAX=DDAT(JE+14)                                                 DE1N2      86
      VRMIN=DDAT(JE+15)                                                 DE1N2      87
      IF (IDDAT(JE+16).NE.0) THEN                                       DE1N2      88
         ETR=ET/DDAT(JE+16)                                             DE1N2      89
         VRMAX=VRMAX*ETR                                                DE1N2      90
         VRMIN=VRMIN*ETR                                                DE1N2      91
      END IF                                                            DE1N2      92
      IF (IDDAT(JE+17).NE.0) THEN                                       DE1N2      93
         IF (ET.LT.DDAT(JE+17)) THEN                                    DE1N2      94
            VRMAX=0.0                                                   DE1N2      95
            VRMIN=0.0                                                   DE1N2      96
         END IF                                                         DE1N2      97
      END IF                                                            DE1N2      98
C                                                                       DE1N2      99
      DO 500 ITM=1,KTM                                                  DE1N2     100
C                                                                       DE1N2     101
      SEKX=DDAT(JE+4)*XSTATE(JSTATE+5)                                  DE1N2     102
      SEKX=SEKX+DDAT(JE+6)*EXP(DDAT(JE+7)*XSTATE(JSTATE+5))             DE1N2     103
C                                                                       DE1N2     104
C     RATE FEEDBACK BLOCK                                               DE1N2     105
C                                                                       DE1N2     106
      XRATE=EFDN                                                        DE1N2     107
      IF (IDDAT(JE+11).NE.0) THEN                                       DE1N2     108
         DSTATE(LSTATE+2)=(XRATE-XSTATE(JSTATE+2))/DDAT(JE+11)          DE1N2     109
         V2=DSTATE(LSTATE+2)*DDAT(JE+10)                                DE1N2     110
      ELSE                                                              DE1N2     111
         V2=0.0                                                         DE1N2     112
         DSTATE(LSTATE+2)=0.0                                           DE1N2     113
         XSTATE(JSTATE+2)=XRATE                                         DE1N2     114
      END IF                                                            DE1N2     115
C                                                                       DE1N2     116
      VSUM=VREF(JYE+2)-V1-V2                                            DE1N2     117
      IF (ISTABN.GT.0) VSUM=VSUM+VSS(JYS+1)                             DE1N2     118
      IF (IUALN.NE.0.AND.LVUEL.EQ.1) VSUM=VSUM+VUAL(JYU+1)              DE1N2     119
      IF (ITEBN.NE.0) VSUM=VSUM+TEB(JYTB+1)                             DE1N2     120
      IF (IMXLN.NE.0) VSUM=VSUM-VMXL(JYMX+1)                            DE1N2     121
C                                                                       DE1N2     122
C     LEAD/LAG BLOCK                                                    DE1N2     123
C                                                                       DE1N2     124
      IF (IDDAT(JE+13).NE.0) THEN                                       DE1N2     125
         DSTATE(LSTATE+3)=(VSUM-XSTATE(JSTATE+3))/DDAT(JE+13)           DE1N2     126
         V3=XSTATE(JSTATE+3)+DDAT(JE+12)*DSTATE(LSTATE+3)               DE1N2     127
      ELSE                                                              DE1N2     128
         V3=VSUM                                                        DE1N2     129
         DSTATE(LSTATE+3)=0.0                                           DE1N2     130
         XSTATE(JSTATE+3)=V3                                            DE1N2     131
      END IF                                                            DE1N2     132
C                                                                       DE1N2     133
C     ALTERNATE VUEL CONNECTION POINT                                   DE1N2     134
C                                                                       DE1N2     135
      IF (IUALN.NE.0.AND.LVUEL.EQ.2) THEN                               DE1N2     136
         IF(V3.LT.VUAL(JYU+1)) V3=VUAL(JYU+1)                           DE1N2     137
      END IF                                                            DE1N2     138
C                                                                       DE1N2     139
C     AMPILIFIER BLOCK                                                  DE1N2     140
C                                                                       DE1N2     141
      IF (IDDAT(JE+3).NE.0) THEN                                        DE1N2     142
         DSTATE(LSTATE+4)=(DDAT(JE+2)*V3-XSTATE(JSTATE+4))/DDAT(JE+3)   DE1N2     143
         VR=XSTATE(JSTATE+4)                                            DE1N2     144
      ELSE                                                              DE1N2     145
         VR=DDAT(JE+2)*V3                                               DE1N2     146
         DSTATE(LSTATE+4)=0.                                            DE1N2     147
C         XSTATE(JSTATE+4)=VR                                           DE1N2     148
      END IF                                                            DE1N2     149
C                                                                       DE1N2     150
      IF (VR.GE.VRMAX) THEN                                             DE1N2     151
         VR=VRMAX                                                       DE1N2     152
         IF (DSTATE(LSTATE+4).GT.0.0) THEN                              DE1N2     153
            DSTATE(LSTATE+4)=0.0                                        DE1N2     154
            QSTATE(JSTATE+4)=0.0                                        DE1N2     155
         END IF                                                         DE1N2     156
      ELSE IF (VR.LE.VRMIN) THEN                                        DE1N2     157
         VR=VRMIN                                                       DE1N2     158
         IF (DSTATE(LSTATE+4).LT.0.0) THEN                              DE1N2     159
            DSTATE(LSTATE+4)=0.0                                        DE1N2     160
            QSTATE(JSTATE+4)=0.0                                        DE1N2     161
         END IF                                                         DE1N2     162
      END IF                                                            DE1N2     163
      XSTATE(JSTATE+4)=VR                                               DE1N2     164
C                                                                       DE1N2     165
C      IF (IUALN.GT.10.AND.IUALN.NE.50) VR=VR+VUAL(JYU+1)               DE1N2     166
C                                                                       DE1N2     167
      VEIN=VR-SEKX                                                      DE1N2     168
C                                                                       DE1N2     169
      DSTATE(LSTATE+5)=VEIN/DDAT(JE+5)                                  DE1N2     170
C                                                                       DE1N2     171
C     EULER FORWARD METHOD                                              DE1N2     172
C                                                                       DE1N2     173
      IF (SLOGIC) THEN                                                  DE1N2     174
         DO 310 JX=2,5                                                  DE1N2     175
            XSTATE(JSTATE+JX)=XSTATE(JSTATE+JX)+DELT*DSTATE(LSTATE+JX)  DE1N2     176
  310    CONTINUE                                                       DE1N2     177
         IF (XSTATE(JSTATE+4).GT.VRMAX) THEN                            DE1N2     178
            XSTATE(JSTATE+4)=VRMAX                                      DE1N2     179
         ELSE IF (XSTATE(JSTATE+4).LT.VRMIN) THEN                       DE1N2     180
            XSTATE(JSTATE+4)=VRMIN                                      DE1N2     181
         END IF                                                         DE1N2     182
         EFDN=XSTATE(JSTATE+5)                                          DE1N2     183
      END IF                                                            DE1N2     184
C                                                                       DE1N2     185
  500 CONTINUE                                                          DE1N2     186
C                                                                       DE1N2     187
C     IF STATES ARE UPDATED BY INNER LOOP, FOOL THE RKG                 DE1N2     188
C                                                                       DE1N2     189
      IF (SLOGIC) THEN                                                  DE1N2     190
         DO 320 JX=2,5                                                  DE1N2     191
            DSTATE(LSTATE+JX)=0.0                                       DE1N2     192
  320    CONTINUE                                                       DE1N2     193
         EFD(JYG+4)=EFDN                                                DE1N2     194
      ELSE                                                              DE1N2     195
         EFD(JYG+4)=XSTATE(JSTATE+5)                                    DE1N2     196
      END IF                                                            DE1N2     197
C                                                                       DE1N2     198
C   EXTR VARIABLE FOR TSEC                                              DE1N2     199
C                                                                       DE1N2     200
      XVARB=XSTATE(JSTATE+4)                                            DE1N2     201
      REFMX=0.99*DDAT(JE+14)                                            DE1N2     202
C                                                                       DE1N2     203
      LSTATE=LSTATE+5                                                   DE1N2     204
C                                                                       DE1N2     205
      RETURN                                                            DE1N2     206
C                                                                       DE1N2     207
      ENTRY DEI1N2(H)                                                   DE1N2     208
CD                                                                      DE1N2     209
CD    TO CALCULATE THE DERIVATIVES OF THE STATES OF TYPES 1 AND 2       DE1N2     210
CD    EXCITER, USED BY TRAPEZOIDAL METHOD.                              DE1N2     211
CD                                                                      DE1N2     212
C                                                                       DE1N2     213
C     DECIDE IF SMALLER TIME STEP SHOULD BE TAKEN                       DE1N2     214
C                                                                       DE1N2     215
      DELT=0.0                                                          DE1N2     216
      IF (IDDAT(JE+21).NE.0) THEN                                       DE1N2     217
         IF (H.LE.DDAT(JE+22)) THEN                                     DE1N2     218
            SLOGIC=.FALSE.                                              DE1N2     219
            KTM=1                                                       DE1N2     220
         ELSE                                                           DE1N2     221
            SLOGIC=.TRUE.                                               DE1N2     222
            KTM=INT(H/DDAT(JE+22))+1                                    DE1N2     223
            DELT=H/KTM                                                  DE1N2     224
            IF (NITER.EQ.0) THEN                                        DE1N2     225
               DO 90 JX=2,5                                             DE1N2     226
                  XSTATE(JSTATE+JX)=XPREV(1,JSTATE+JX)                  DE1N2     227
   90          CONTINUE                                                 DE1N2     228
            END IF                                                      DE1N2     229
         END IF                                                         DE1N2     230
      ELSE                                                              DE1N2     231
         SLOGIC=.FALSE.                                                 DE1N2     232
         KTM=1                                                          DE1N2     233
      END IF                                                            DE1N2     234
C                                                                       DE1N2     235
C     BYPASS IF SUBDIVISION IS ON AND NITER > 0                         DE1N2     236
C                                                                       DE1N2     237
      IF (SLOGIC.AND.NITER.GT.0) THEN                                   DE1N2     238
         EFDN=EFD(JYG+4)                                                DE1N2     239
         GOTO 130                                                       DE1N2     240
      END IF                                                            DE1N2     241
C                                                                       DE1N2     242
      VRMAX=DDAT(JE+14)                                                 DE1N2     243
      VRMIN=DDAT(JE+15)                                                 DE1N2     244
      IF (IDDAT(JE+16).NE.0) THEN                                       DE1N2     245
         ETR=ET/DDAT(JE+16)                                             DE1N2     246
         VRMAX=VRMAX*ETR                                                DE1N2     247
         VRMIN=VRMIN*ETR                                                DE1N2     248
      END IF                                                            DE1N2     249
      IF (IDDAT(JE+17).NE.0) THEN                                       DE1N2     250
         IF (ET.LT.DDAT(JE+17)) THEN                                    DE1N2     251
            VRMAX=0.0                                                   DE1N2     252
            VRMIN=0.0                                                   DE1N2     253
         END IF                                                         DE1N2     254
      END IF                                                            DE1N2     255
C                                                                       DE1N2     256
      DO 100 ITM=1,KTM                                                  DE1N2     257
C                                                                       DE1N2     258
      SEKX=DDAT(JE+4)*XSTATE(JSTATE+5)                                  DE1N2     259
      SEKX=SEKX+DDAT(JE+6)*EXP(DDAT(JE+7)*XSTATE(JSTATE+5))             DE1N2     260
C                                                                       DE1N2     261
C     RATE FEEDBACK BLOCK                                               DE1N2     262
C                                                                       DE1N2     263
      XRATE=EFDN                                                        DE1N2     264
      IF (IDDAT(JE+11).NE.0) THEN                                       DE1N2     265
         DSTATE(LSTATE+2)=(XRATE-XSTATE(JSTATE+2))/DDAT(JE+11)          DE1N2     266
         V2=DSTATE(LSTATE+2)*DDAT(JE+10)                                DE1N2     267
      ELSE                                                              DE1N2     268
         V2=0.0                                                         DE1N2     269
         DSTATE(LSTATE+2)=0.0                                           DE1N2     270
         XSTATE(JSTATE+2)=XRATE                                         DE1N2     271
      END IF                                                            DE1N2     272
C                                                                       DE1N2     273
      VSUM=VREF(JYE+2)-V1-V2                                            DE1N2     274
      IF (ISTABN.GT.0) VSUM=VSUM+VSS(JYS+1)                             DE1N2     275
      IF (IUALN.NE.0.AND.LVUEL.EQ.1) VSUM=VSUM+VUAL(JYU+1)              DE1N2     276
      IF (ITEBN.NE.0) VSUM=VSUM+TEB(JYTB+1)                             DE1N2     277
      IF (IMXLN.NE.0) VSUM=VSUM-VMXL(JYMX+1)                            DE1N2     278
C                                                                       DE1N2     279
C     LEAD/LAG BLOCK                                                    DE1N2     280
C                                                                       DE1N2     281
      IF (IDDAT(JE+13).NE.0) THEN                                       DE1N2     282
         DSTATE(LSTATE+3)=(VSUM-XSTATE(JSTATE+3))/DDAT(JE+13)           DE1N2     283
         V3=XSTATE(JSTATE+3)+DDAT(JE+12)*DSTATE(LSTATE+3)               DE1N2     284
      ELSE                                                              DE1N2     285
         V3=VSUM                                                        DE1N2     286
         DSTATE(LSTATE+3)=0.0                                           DE1N2     287
         XSTATE(JSTATE+3)=V3                                            DE1N2     288
      END IF                                                            DE1N2     289
C                                                                       DE1N2     290
C     ALTERNATE VUEL CONNECTION POINT                                   DE1N2     291
C                                                                       DE1N2     292
      IF (IUALN.NE.0.AND.LVUEL.EQ.2) THEN                               DE1N2     293
         IF(V3.LT.VUAL(JYU+1)) V3=VUAL(JYU+1)                           DE1N2     294
      END IF                                                            DE1N2     295
C                                                                       DE1N2     296
C     AMPILIFIER BLOCK                                                  DE1N2     297
C                                                                       DE1N2     298
      IF (IDDAT(JE+3).NE.0) THEN                                        DE1N2     299
         DSTATE(LSTATE+4)=(DDAT(JE+2)*V3-XSTATE(JSTATE+4))/DDAT(JE+3)   DE1N2     300
         VR=XSTATE(JSTATE+4)                                            DE1N2     301
      ELSE                                                              DE1N2     302
         VR=DDAT(JE+2)*V3                                               DE1N2     303
         DSTATE(LSTATE+4)=0.                                            DE1N2     304
C         XSTATE(JSTATE+4)=VR                                           DE1N2     305
      END IF                                                            DE1N2     306
C                                                                       DE1N2     307
      IF (VR.GE.VRMAX) THEN                                             DE1N2     308
         VR=VRMAX                                                       DE1N2     309
         IF (DSTATE(LSTATE+4).GT.0.0) DSTATE(LSTATE+4)=0.0              DE1N2     310
      ELSE IF (VR.LE.VRMIN) THEN                                        DE1N2     311
         VR=VRMIN                                                       DE1N2     312
         IF (DSTATE(LSTATE+4).LT.0.0) DSTATE(LSTATE+4)=0.0              DE1N2     313
      END IF                                                            DE1N2     314
      XSTATE(JSTATE+4)=VR                                               DE1N2     315
C                                                                       DE1N2     316
C      IF (IUALN.GT.10.AND.IUALN.NE.50) VR=VR+VUAL(JYU+1)               DE1N2     317
C                                                                       DE1N2     318
      VEIN=VR-SEKX                                                      DE1N2     319
C                                                                       DE1N2     320
      DSTATE(LSTATE+5)=VEIN/DDAT(JE+5)                                  DE1N2     321
C                                                                       DE1N2     322
C     EULER FORWARD METHOD                                              DE1N2     323
C                                                                       DE1N2     324
      IF (SLOGIC) THEN                                                  DE1N2     325
         DO 110 JX=2,5                                                  DE1N2     326
            XSTATE(JSTATE+JX)=XSTATE(JSTATE+JX)+DELT*DSTATE(LSTATE+JX)  DE1N2     327
  110    CONTINUE                                                       DE1N2     328
         IF (XSTATE(JSTATE+4).GT.VRMAX) THEN                            DE1N2     329
            XSTATE(JSTATE+4)=VRMAX                                      DE1N2     330
         ELSE IF (XSTATE(JSTATE+4).LT.VRMIN) THEN                       DE1N2     331
            XSTATE(JSTATE+4)=VRMIN                                      DE1N2     332
         END IF                                                         DE1N2     333
         EFDN=XSTATE(JSTATE+5)                                          DE1N2     334
      END IF                                                            DE1N2     335
C                                                                       DE1N2     336
  100 CONTINUE                                                          DE1N2     337
C                                                                       DE1N2     338
C     IF STATES ARE UPDATED BY INNER LOOP, FOOL THE RKG                 DE1N2     339
C                                                                       DE1N2     340
  130 IF (SLOGIC) THEN                                                  DE1N2     341
         DO 140 JX=2,5                                                  DE1N2     342
            DSTATE(LSTATE+JX)=0.0                                       DE1N2     343
  140    CONTINUE                                                       DE1N2     344
         EFD(JYG+4)=EFDN                                                DE1N2     345
      ELSE                                                              DE1N2     346
         EFD(JYG+4)=XSTATE(JSTATE+5)                                    DE1N2     347
      END IF                                                            DE1N2     348
C                                                                       DE1N2     349
C   EXTR VARIABLE FOR TSEC                                              DE1N2     350
C                                                                       DE1N2     351
      XVARB=XSTATE(JSTATE+4)                                            DE1N2     352
      REFMX=0.99*DDAT(JE+14)                                            DE1N2     353
C                                                                       DE1N2     354
      LSTATE=LSTATE+5                                                   DE1N2     355
C                                                                       DE1N2     356
      RETURN                                                            DE1N2     357
      END                                                               DE1N2     358
