CFPRIME NWDP                                                            NWDP        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 NWDP(JSGV,NWSS,STEP)                                   NWDP        3
CD                                                                      NWDP        4
CD    TO UPDATE THE NON-WINDUP LIMITER AT END OF INTEGRATION STEP.      NWDP        5
CD                                                                      NWDP        6
      INCLUDE 'PARX.INS'                                                NWDP        7
      INCLUDE 'CNFLAG.INS'                                              NWDP        8
      INCLUDE 'CNMDAT.INS'                                              NWDP        9
      INCLUDE 'CNPT.INS'                                                NWDP       10
      INCLUDE 'CNB3.INS'                                                NWDP       11
      INCLUDE 'CNB8.INS'                                                NWDP       12
      INCLUDE 'CNB19.INS'                                               NWDP       13
      INCLUDE 'CNEXC.INS'                                               NWDP       14
      INCLUDE 'CNPRGV.INS'                                              NWDP       15
      INCLUDE 'CNMSTA.INS'                                              NWDP       16
      INCLUDE 'CNXSTA.INS'                                              NWDP       17
      INCLUDE 'CNMYVA.INS'                                              NWDP       18
      INCLUDE 'CNYVAR.INS'                                              NWDP       19
      INCLUDE 'CNUNIT.INS'                                              NWDP       20
      INCLUDE 'CNUDM.INS'                                               NWDP       21
C                                                                       NWDP       22
C                                                                       NWDP       23
*IF DEBUG                                                               NWDP       24
      LDEB=(JDEB(64).NE.0)                                              NWDP       25
*ENDIF                                                                  NWDP       26
C                                                                       NWDP       27
C  (1)EXCITERS                                                          NWDP       28
C                                                                       NWDP       29
      IF(IEXN.NE.0)THEN                                                 NWDP       30
      IF(IEXN.EQ.50) THEN                                               NWDP       31
         JE0=JE                                                         NWDP       32
         JE1=JE0+9                                                      NWDP       33
         NRBUS=IDDAT(JE1)                                               NWDP       34
         JE2=JE1+3*NRBUS+1                                              NWDP       35
         NRLIN=IDDAT(JE2)                                               NWDP       36
         JE3=JE2+4*NRLIN+1                                              NWDP       37
         NUDB=IDDAT(JE3)                                                NWDP       38
         JE4=JE3+17*NUDB+1                                              NWDP       39
         CALL UDMNWL(1)                                                 NWDP       40
         GO TO 200                                                      NWDP       41
      ENDIF                                                             NWDP       42
      JEST=MSTATE(2,N)                                                  NWDP       43
C                                                                       NWDP       44
*IF DEBUG                                                               NWDP       45
      IF(LDEB)WRITE(IUD6,1010)                                          NWDP       46
     &IEXN,JEST,VEMIN,VRMAX,VRMIN,EFMX,EFMN                             NWDP       47
*ENDIF                                                                  NWDP       48
C                                                                       NWDP       49
      IF(IEXN.LT.30)THEN                                                NWDP       50
C               1   2   3   4   5   6   7   8   9  10  11  12           NWDP       51
         GOTO(120,120,110,100,110,100,130,140,160,150,200,200,          NWDP       52
C              13  14  15                                               NWDP       53
     +        200,110,120),IEXN                                         NWDP       54
      ELSE                                                              NWDP       55
         IEXNN=IEXN-29                                                  NWDP       56
C               30  31  32  33  34                                      NWDP       57
         GOTO (170,180,190,200,150), IEXNN                              NWDP       58
      ENDIF                                                             NWDP       59
 100  IF(XSTATE(JEST+5).GT.VEMAX)XSTATE(JEST+5)=VEMAX                   NWDP       60
*IF DEBUG                                                               NWDP       61
      IF(LDEB)WRITE(IUD6,1740)JEST,XSTATE(JEST+5),VEMAX                 NWDP       62
*ENDIF                                                                  NWDP       63
 110  IF(XSTATE(JEST+5).LT.VEMIN)XSTATE(JEST+5)=VEMIN                   NWDP       64
*IF DEBUG                                                               NWDP       65
      IF(LDEB)WRITE(IUD6,1760)JEST,XSTATE(JEST+5),VEMIN                 NWDP       66
*ENDIF                                                                  NWDP       67
      IF(IEXN.EQ.14)THEN                                                NWDP       68
         IF(XSTATE(JEST+6).GT.DDAT(JE+31)) XSTATE(JEST+6)=DDAT(JE+31)   NWDP       69
         IF(XSTATE(JEST+6).LT.0.0) XSTATE(JEST+6)=0.0                   NWDP       70
      ENDIF                                                             NWDP       71
 120  IF(XSTATE(JEST+4).GT.VRMAX)XSTATE(JEST+4)=VRMAX                   NWDP       72
      IF(XSTATE(JEST+4).LT.VRMIN)XSTATE(JEST+4)=VRMIN                   NWDP       73
      IF(IEXN.EQ.15) VRFIN(JYE+3)=XSTATE(JEST+4)                        NWDP       74
*IF DEBUG                                                               NWDP       75
      IF(LDEB)WRITE(IUD6,1770)JEST,XSTATE(JEST+4),VRMAX,VRMIN           NWDP       76
*ENDIF                                                                  NWDP       77
      GOTO 200                                                          NWDP       78
 130  IF(XSTATE(JEST+5).LT.0.)XSTATE(JEST+5)=0.                         NWDP       79
      IF(XSTATE(JEST+5).GT.VEMIN)XSTATE(JEST+5)=VEMIN                   NWDP       80
      GOTO 120                                                          NWDP       81
 140  IF(XSTATE(JEST+4).GT.VMMAX)XSTATE(JEST+4)=VMMAX                   NWDP       82
      IF(XSTATE(JEST+4).LT.VMMIN)XSTATE(JEST+4)=VMMIN                   NWDP       83
*IF DEBUG                                                               NWDP       84
      IF(LDEB)WRITE(IUD6,1770)JEST,XSTATE(JEST+4),VMMAX,VMMIN           NWDP       85
*ENDIF                                                                  NWDP       86
      IF(XSTATE(JEST+5).GT.VRMAX)XSTATE(JEST+5)=VRMAX                   NWDP       87
      IF(XSTATE(JEST+5).LT.VRMIN)XSTATE(JEST+5)=VRMIN                   NWDP       88
*IF DEBUG                                                               NWDP       89
      IF(LDEB)WRITE(IUD6,1780)JEST,XSTATE(JEST+5),VRMAX,VRMIN           NWDP       90
*ENDIF                                                                  NWDP       91
      GOTO 200                                                          NWDP       92
 150  IF(XSTATE(JEST+3).GT.VRMAX)XSTATE(JEST+3)=VRMAX                   NWDP       93
      IF(XSTATE(JEST+3).LT.VRMIN)XSTATE(JEST+3)=VRMIN                   NWDP       94
      VRFIN(JYE+3)=XSTATE(JEST+3)                                       NWDP       95
*IF DEBUG                                                               NWDP       96
      IF(LDEB)WRITE(IUD6,1880)JEST,XSTATE(JEST+2),VRMAX,VRMIN           NWDP       97
*ENDIF                                                                  NWDP       98
      GOTO 200                                                          NWDP       99
 160  IF(XSTATE(JEST+2).GT.VRMAX)XSTATE(JEST+2)=VRMAX                   NWDP      100
      IF(XSTATE(JEST+2).LT.VRMIN)XSTATE(JEST+2)=VRMIN                   NWDP      101
      GOTO 200                                                          NWDP      102
 170  IF(IDDAT(JE+3).NE.0)THEN                                          NWDP      103
        NXS=MSTATE(3,N)                                                 NWDP      104
C                                                                       NWDP      105
C+  NOW SWITCHING TO NON-WINDUP LIMITER REPRESENTATION                  NWDP      106
C                                                                       NWDP      107
C        IF(XSTATE(NXS).GT.EFMX) EFD(JYG+4)=EFMX                        NWDP      108
C        IF(XSTATE(NXS).LT.EFMN) EFD(JYG+4)=EFMN                        NWDP      109
        IF(XSTATE(NXS).GT.EFMX) XSTATE(NXS)=EFMX                        NWDP      110
        IF(XSTATE(NXS).LT.EFMN) XSTATE(NXS)=EFMN                        NWDP      111
*IF DEBUG                                                               NWDP      112
        IF(LDEB)WRITE(IUD6,1790)NXS,XSTATE(NXS),EFMX,EFMN               NWDP      113
*ENDIF                                                                  NWDP      114
      ENDIF                                                             NWDP      115
      GOTO 200                                                          NWDP      116
C                                                                       NWDP      117
 180  IF(IDDAT(JE+5).NE.0)THEN                                          NWDP      118
        NXS=MSTATE(3,N)                                                 NWDP      119
        IF(XSTATE(NXS).GT.EFMX)XSTATE(NXS)=EFMX                         NWDP      120
        IF(XSTATE(NXS).LT.EFMN)XSTATE(NXS)=EFMN                         NWDP      121
        VRFIN(JYE+3)=XSTATE(NXS)                                        NWDP      122
      ENDIF                                                             NWDP      123
      GOTO 200                                                          NWDP      124
 190  NXS=MSTATE(3,N)                                                   NWDP      125
      IF(XSTATE(NXS).GT.EFMX)XSTATE(NXS)=EFMX                           NWDP      126
      IF(XSTATE(NXS).LT.EFMN)XSTATE(NXS)=EFMN                           NWDP      127
      VRFIN(JYE+3)=XSTATE(NXS)                                          NWDP      128
      IF(XSTATE(JEST+2).GT.DDAT(JE+30))XSTATE(JEST+2)=DDAT(JE+30)       NWDP      129
      IF(XSTATE(JEST+2).LT.DDAT(JE+31))XSTATE(JEST+2)=DDAT(JE+31)       NWDP      130
C                                                                       NWDP      131
C   (2) STABILIZERS                                                     NWDP      132
C                                                                       NWDP      133
C  TEST FOR OPENING S1 FOR ISTAB=2,3,5,6                                NWDP      134
C                                                                       NWDP      135
 200  CONTINUE                                                          NWDP      136
C                                                                       NWDP      137
      IF(ISTABN.EQ.50) THEN                                             NWDP      138
         JE0=JS                                                         NWDP      139
         JE1=JE0+9                                                      NWDP      140
         NRBUS=IDDAT(JE1)                                               NWDP      141
         JE2=JE1+3*NRBUS+1                                              NWDP      142
         NRLIN=IDDAT(JE2)                                               NWDP      143
         JE3=JE2+4*NRLIN+1                                              NWDP      144
         NUDB=IDDAT(JE3)                                                NWDP      145
         JE4=JE3+17*NUDB+1                                              NWDP      146
         CALL UDMNWL(0)                                                 NWDP      147
         GO TO 250                                                      NWDP      148
      ENDIF                                                             NWDP      149
      IF(ISTABN.EQ.2.OR.ISTABN.EQ.3.OR.ISTABN.EQ.5.OR.ISTABN.EQ.6)THEN  NWDP      150
        IF(XSTATE(NWSS).GT.DDAT(JS+21)) XSTATE(NWSS)=DDAT(JS+21)        NWDP      151
      ENDIF                                                             NWDP      152
C                                                                       NWDP      153
C   ISTABN=11, TEST SIGNAL "U" AND DETERMINE THE STATUS OF SWITCH "S1"  NWDP      154
C                                                                       NWDP      155
      IF(ISTABN.EQ.11)THEN                                              NWDP      156
         IF(IDDAT(JS+18).NE.0)THEN                                      NWDP      157
            IF(IDDAT(JS+32).EQ.0)THEN                                   NWDP      158
               IF(DELOMG.LT.DDAT(JS+24))DELOMG=DDAT(JS+24)              NWDP      159
               IF(DOMG.LT.DDAT(JS+25))DOMG=DDAT(JS+25)                  NWDP      160
               UOUT=DDAT(JS+31)*(DELOMG-DDAT(JS+31))-DOMG               NWDP      161
               IF(UOUT.LT.0.0)THEN                                      NWDP      162
                  DDAT(JS+33)=-10.0                                     NWDP      163
               ELSE                                                     NWDP      164
                  IF(IDDAT(JS+33).LT.0)THEN                             NWDP      165
                      DDAT(JS+33)=0.0                                   NWDP      166
                  ELSE                                                  NWDP      167
                      DDAT(JS+33)=DDAT(JS+33)+STEP                      NWDP      168
                      IF(DDAT(JS+33).GE.DDAT(JS+29))IDDAT(JS+32)=1      NWDP      169
                  ENDIF                                                 NWDP      170
               ENDIF                                                    NWDP      171
            ENDIF                                                       NWDP      172
         ENDIF                                                          NWDP      173
      ENDIF                                                             NWDP      174
C                                                                       NWDP      175
      ENDIF                                                             NWDP      176
C                                                                       NWDP      177
 250  CONTINUE                                                          NWDP      178
C                                                                       NWDP      179
C     (3) UEL                                                           NWDP      180
C                                                                       NWDP      181
      IF (IUALN.EQ.50.AND.ISTABN.NE.50) THEN                            NWDP      182
         JE0=JU                                                         NWDP      183
         JE1=JE0+9                                                      NWDP      184
         NRBUS=IDDAT(JE1)                                               NWDP      185
         JE2=JE1+3*NRBUS+1                                              NWDP      186
         NRLIN=IDDAT(JE2)                                               NWDP      187
         JE3=JE2+4*NRLIN+1                                              NWDP      188
         NUDB=IDDAT(JE3)                                                NWDP      189
         JE4=JE3+17*NUDB+1                                              NWDP      190
         CALL UDMNWL(0)                                                 NWDP      191
      ENDIF                                                             NWDP      192
C                                                                       NWDP      193
C   (4) GOVERNORS                                                       NWDP      194
C                                                                       NWDP      195
      IF (IGVN .EQ. 46) IGVN=0                                          NWDP      196
      IF(IGVN.NE.0)THEN                                                 NWDP      197
C                                                                       NWDP      198
C      JSGV=MSTATE(5,N)                                                 NWDP      199
      JGG=JCONTA(2,N)                                                   NWDP      200
      IF(IGVN.GT.40.AND.IGVN.LT.50) GOTO 900                            NWDP      201
C                                                                       NWDP      202
      IF(IGVN.EQ.50) THEN                                               NWDP      203
         JE0=JGG                                                        NWDP      204
         JE1=JE0+3                                                      NWDP      205
         NRBUS=IDDAT(JE1)                                               NWDP      206
         JE2=JE1+3*NRBUS+1                                              NWDP      207
         NRLIN=IDDAT(JE2)                                               NWDP      208
         JE3=JE2+4*NRLIN+1                                              NWDP      209
         NUDB=IDDAT(JE3)                                                NWDP      210
         JE4=JE3+17*NUDB+1                                              NWDP      211
         CALL UDMNWL(2)                                                 NWDP      212
         GO TO 900                                                      NWDP      213
      ENDIF                                                             NWDP      214
      IGVNB=0                                                           NWDP      215
      IF(IGVN.GE.31.AND.IGVN.LE.35)THEN                                 NWDP      216
        IGVNB=IGVN                                                      NWDP      217
        IGVN=IGVN-30                                                    NWDP      218
      ENDIF                                                             NWDP      219
C                                                                       NWDP      220
C                                                                       NWDP      221
C  TYPE :    1   2   3   4   5   6   7                                  NWDP      222
C                                                                       NWDP      223
      GOTO (300,300,900,400,900,600,600,900,900,900,900,900,900,900,    NWDP      224
C                                20  21  22                             NWDP      225
     +      900,900,900,900,900,800,820,900), IGVN                      NWDP      226
 300  CONTINUE                                                          NWDP      227
C  TYPE=1,2                                                             NWDP      228
C      NON WINDUP LIMITS . . . AT THE END OF TIME STEP                  NWDP      229
      IF(XSTATE(JSGV+5).LT.0.0)XSTATE(JSGV+5)=0.0                       NWDP      230
      IF(XSTATE(JSGV+5).GT.1.0)XSTATE(JSGV+5)=1.0                       NWDP      231
      IF(XSTATE(JSGV+8).LT.0.0)XSTATE(JSGV+8)=0.0                       NWDP      232
      IF(XSTATE(JSGV+8).GT.1.0)XSTATE(JSGV+8)=1.0                       NWDP      233
      IF(IGVNB.NE.0)THEN                                                NWDP      234
       IF(XSTATE(JSGV+19).LT.DDAT(JGG+88))XSTATE(JSGV+19)=DDAT(JGG+88)  NWDP      235
       IF(XSTATE(JSGV+19).GT.DDAT(JGG+89))XSTATE(JSGV+19)=DDAT(JGG+89)  NWDP      236
      ENDIF                                                             NWDP      237
      IF(IGVNB.NE.0)IGVN=IGVNB                                          NWDP      238
      GOTO 900                                                          NWDP      239
 400  CONTINUE                                                          NWDP      240
C                                                                       NWDP      241
C  TYPE=4                                                               NWDP      242
C      NON WINDUP LIMITS . . . AT THE END OF TIME STEP                  NWDP      243
      IF(XSTATE(JSGV+2).GT.1.0) XSTATE(JSGV+2)=1.0                      NWDP      244
      IF(XSTATE(JSGV+2).LT.0.0) XSTATE(JSGV+2)=0.0                      NWDP      245
      IF(IGVNB.NE.0)THEN                                                NWDP      246
       IF(XSTATE(JSGV+14).LT.DDAT(JGG+26))XSTATE(JSGV+14)=DDAT(JGG+26)  NWDP      247
       IF(XSTATE(JSGV+14).GT.DDAT(JGG+27))XSTATE(JSGV+14)=DDAT(JGG+27)  NWDP      248
      ENDIF                                                             NWDP      249
      IF(IGVNB.NE.0)IGVN=IGVNB                                          NWDP      250
      GOTO 900                                                          NWDP      251
 600  CONTINUE                                                          NWDP      252
C                                                                       NWDP      253
C  TYPE=6,7                                                             NWDP      254
C                                                                       NWDP      255
      IF(XSTATE(JSGV+1).GT.1.0)XSTATE(JSGV+1)=1.0                       NWDP      256
      IF(XSTATE(JSGV+1).LT.DDAT(JGG+6))XSTATE(JSGV+1)=DDAT(JGG+6)       NWDP      257
      GOTO 900                                                          NWDP      258
C                                                                       NWDP      259
 800  CONTINUE                                                          NWDP      260
C                                                                       NWDP      261
C   TYPE 20                                                             NWDP      262
C                                                                       NWDP      263
C  NON WINDUP LIMITS . . . AT THE END OF TIME STEP                      NWDP      264
C                                                                       NWDP      265
      IF(XSTATE(JSGV+1).GT.1.0)XSTATE(JSGV+1)=1.0                       NWDP      266
      IF(XSTATE(JSGV+1).LT.0.0)XSTATE(JSGV+1)=0.0                       NWDP      267
      GOTO 900                                                          NWDP      268
C                                                                       NWDP      269
C   TYPE 21                                                             NWDP      270
C                                                                       NWDP      271
  820 IF(XSTATE(JSGV+1).GT.DDAT(JGG+10))XSTATE(JSGV+1)=DDAT(JGG+10)     NWDP      272
      IF(XSTATE(JSGV+1).LT.DDAT(JGG+11))XSTATE(JSGV+1)=DDAT(JGG+11)     NWDP      273
      IF(XSTATE(JSGV+2).GT.DDAT(JGG+7))XSTATE(JSGV+2)=DDAT(JGG+7)       NWDP      274
      IF(XSTATE(JSGV+2).LT.DDAT(JGG+8))XSTATE(JSGV+2)=DDAT(JGG+8)       NWDP      275
      ENDIF                                                             NWDP      276
C                                                                       NWDP      277
 900  CONTINUE                                                          NWDP      278
C                                                                       NWDP      279
      RETURN                                                            NWDP      280
 1010 FORMAT(1X,'DB-NWDP:IEXN,JSTATE,VEMIN,VRMAX,VRMIN,EFMX,EFMN ',     NWDP      281
     +2I5,5G12.5)                                                       NWDP      282
 1740 FORMAT(1X,'NWDP_NEW:JEST,X5,VEMAX ',I5,2F12.5)                    NWDP      283
 1760 FORMAT(1X,'NWDP_NEW:JEST,X5,VEMIN ',I5,2G12.5)                    NWDP      284
 1770 FORMAT(1X,'NWDP_NEW:JEST,X4,VRMAX,VRMIN ',I5,3G12.5)              NWDP      285
 1780 FORMAT(1X,'NWDP_NEW:JEST,X5,VMMAX,VMMIN ',I5,3G12.5)              NWDP      286
 1880 FORMAT(1X,'NWDP_NEW:JEST,X2,VRMAX,VRMIN ',I5,3G12.5)              NWDP      287
 1790 FORMAT(1X,'NWDP_NEW:NXS,XNXS,EFMX,EFMN ',I5,3G12.5)               NWDP      288
C                                                                       NWDP      289
      END                                                               NWDP      290
