CFPRIME DUAL                                                            DUAL        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 DUAL                                                   DUAL        3
CD                                                                      DUAL        4
CD    TO CALCULATE THE DERIVATIVES OF THE STATES OF TYPES 1, 2 AND 3    DUAL        5
CD    UNDEREXCITED CURRENT LIMITER, USED BY BOTH RUNGE-KUTTA AND        DUAL        6
CD    TRAPEZOIDAL METHOD.                                               DUAL        7
CD                                                                      DUAL        8
CD    THE DATA STRUCTURES OF THESE LIMITERS ARE GIVEN BELOW.            DUAL        9
CD                                                                      DUAL       10
CD   8.1 Under excitation current limiter types 1 and 11                DUAL       11
CD                                                                      DUAL       12
CD     Under excitation current limiter data                            DUAL       13
CD                                                                      DUAL       14
CD     DDAT(JU+ 1)    = K1                                              DUAL       15
CD     DDAT(JU+ 2)    = K2                                              DUAL       16
CD     DDAT(JU+ 3)    = K3                                              DUAL       17
CD     DDAT(JU+ 4)    = K4                                              DUAL       18
CD     DDAT(JU+ 5)    = K5                                              DUAL       19
CD     DDAT(JU+ 6)    = K6                                              DUAL       20
CD     DDAT(JU+ 7)    = T9                                              DUAL       21
CD     DDAT(JU+ 8)    = (reserved for future use)                       DUAL       22
CD     DDAT(JU+ 9)    = T1                                              DUAL       23
CD     DDAT(JU+10)    = T2                                              DUAL       24
CD     DDAT(JU+11)    = T3                                              DUAL       25
CD     DDAT(JU+12)    = T4                                              DUAL       26
CD     DDAT(JU+13)    = T5                                              DUAL       27
CD     DDAT(JU+14)    = T6                                              DUAL       28
CD     DDAT(JU+15)    = T7                                              DUAL       29
CD     DDAT(JU+16)    = T8                                              DUAL       30
CD                                                                      DUAL       31
CD     Under excitation current limiter states                          DUAL       32
CD                                                                      DUAL       33
CD     XSTATE(JUS+1)  = first state of T1, T2 block :     optional      DUAL       34
CD     XSTATE(JUS+2)  = second state of T1, T2 block     :     optional DUAL       35
CD     XSTATE(JUS+3)  = first state of T5, T6 block :     optional      DUAL       36
CD     XSTATE(JUS+4)  = second state of T5, T6 block     :     optional DUAL       37
CD     XSTATE(JUS+5)  = first state of T3, T4 block :     optional      DUAL       38
CD     XSTATE(JUS+6)  = second state of T3, T4 block     :     optional DUAL       39
CD     XSTATE(JUS+7)  = first state of T7, T8 block :     optional      DUAL       40
CD     XSTATE(JUS+8)  = second state of T7, T8 block     :     optional DUAL       41
CD                                                                      DUAL       42
CD     Under excitation current limiter Y-variables                     DUAL       43
CD                                                                      DUAL       44
CD     VUAL(JYU+1)    = UEL output                                      DUAL       45
CD                                                                      DUAL       46
CD   8.2 Under excitation current limiter types 2 and 12                DUAL       47
CD                                                                      DUAL       48
CD     Under excitation current limiter data                            DUAL       49
CD                                                                      DUAL       50
CD     DDAT(JU+ 1)    = K1                                              DUAL       51
CD     DDAT(JU+ 2)    = K2                                              DUAL       52
CD     DDAT(JU+ 3)    = K3                                              DUAL       53
CD     DDAT(JU+ 4)    = K4                                              DUAL       54
CD     DDAT(JU+ 5)    = K5                                              DUAL       55
CD     DDAT(JU+ 6)    = (reserved for future use)                       DUAL       56
CD     DDAT(JU+ 7)    = T9                                              DUAL       57
CD     DDAT(JU+ 8)    = (reserved for future use)                       DUAL       58
CD     DDAT(JU+ 9)    = T1                                              DUAL       59
CD     DDAT(JU+10)    = T2                                              DUAL       60
CD     DDAT(JU+11)    = T3                                              DUAL       61
CD     DDAT(JU+12)    = T4                                              DUAL       62
CD     DDAT(JU+13)    = T5                                              DUAL       63
CD     DDAT(JU+14)    = T6                                              DUAL       64
CD     DDAT(JU+15)    = T7                                              DUAL       65
CD     DDAT(JU+16)    = T8                                              DUAL       66
CD                                                                      DUAL       67
CD     Under excitation current limiter states                          DUAL       68
CD                                                                      DUAL       69
CD     XSTATE(JUS+1)  = T1 block                    : optional          DUAL       70
CD     XSTATE(JUS+2)  = T2 block                    : optional          DUAL       71
CD     XSTATE(JUS+3)  = T3 block                    : optional          DUAL       72
CD     XSTATE(JUS+4)  = T4 block                    : optional          DUAL       73
CD     XSTATE(JUS+5)  = T5 block                    : optional          DUAL       74
CD     XSTATE(JUS+6)  = T6 block                    : optional          DUAL       75
CD     XSTATE(JUS+7)  = first state of T7, T8 block : optional          DUAL       76
CD     XSTATE(JUS+8)  = second state of T7, T8 block     : optional     DUAL       77
CD                                                                      DUAL       78
CD     Under excitation current limiter Y-variables                     DUAL       79
CD                                                                      DUAL       80
CD     VUAL(JYU+1)    = UEL output                                      DUAL       81
CD                                                                      DUAL       82
CD   8.3 Under excitation current limiter types 3 and 13                DUAL       83
CD                                                                      DUAL       84
CD     Under excitation current limiter data                            DUAL       85
CD                                                                      DUAL       86
CD     DDAT(JU+ 1)    = K1                                              DUAL       87
CD     DDAT(JU+ 2)    = K2                                              DUAL       88
CD     DDAT(JU+ 3)    = K3                                              DUAL       89
CD     DDAT(JU+ 4)    = K4                                              DUAL       90
CD     DDAT(JU+ 5)    = K5                                              DUAL       91
CD     DDAT(JU+ 6)    = K6                                              DUAL       92
CD     DDAT(JU+ 7)    = (reserved for future use)                       DUAL       93
CD     DDAT(JU+ 8)    = (reserved for future use)                       DUAL       94
CD     DDAT(JU+ 9)    = T1                                              DUAL       95
CD     DDAT(JU+10)    = T2                                              DUAL       96
CD     DDAT(JU+11)    = T3                                              DUAL       97
CD     DDAT(JU+12)    = T4                                              DUAL       98
CD     DDAT(JU+13)    = T5                                              DUAL       99
CD     DDAT(JU+14)    = T6                                              DUAL      100
CD                                                                      DUAL      101
CD     Under excitation current limiter states                          DUAL      102
CD                                                                      DUAL      103
CD     XSTATE(JUS+1)  = T1 block                    : optional          DUAL      104
CD     XSTATE(JUS+2)  = T2 block                    : optional          DUAL      105
CD     XSTATE(JUS+3)  = T3 block                    : optional          DUAL      106
CD     XSTATE(JUS+4)  = T6 block                    : optional          DUAL      107
CD     XSTATE(JUS+5)  = T4 block                    : optional          DUAL      108
CD     XSTATE(JUS+6)  = T5 block                    : optional          DUAL      109
CD                                                                      DUAL      110
CD     Under excitation current limiter Y-variables                     DUAL      111
CD                                                                      DUAL      112
CD     VUAL(JYU+1)    = UEL output                                      DUAL      113
CD                                                                      DUAL      114
      INCLUDE 'PARX.INS'                                                DUAL      115
      INCLUDE 'CNPT.INS'                                                DUAL      116
      INCLUDE 'CNVOLT.INS'                                              DUAL      117
      INCLUDE 'CNIPTR.INS'                                              DUAL      118
      INCLUDE 'CNMDAT.INS'                                              DUAL      119
      INCLUDE 'CNB3.INS'                                                DUAL      120
      INCLUDE 'CNB5.INS'                                                DUAL      121
      INCLUDE 'CNB8.INS'                                                DUAL      122
      INCLUDE 'CNB9.INS'                                                DUAL      123
      INCLUDE 'CNB10.INS'                                               DUAL      124
      INCLUDE 'CNB19.INS'                                               DUAL      125
      INCLUDE 'CNEXC.INS'                                               DUAL      126
      INCLUDE 'CNXSTA.INS'                                              DUAL      127
      INCLUDE 'CNMYVA.INS'                                              DUAL      128
      INCLUDE 'CNYVAR.INS'                                              DUAL      129
C                                                                       DUAL      130
      KUALN=IUALN                                                       DUAL      131
      IF(IUALN.GT.10) KUALN=IUALN-10                                    DUAL      132
C                                                                       DUAL      133
C   UNDER EXCITED REACTIVE CURRENT LIMIT CIRCUIT                        DUAL      134
C                                                                       DUAL      135
      IF(IUALN.GT.10)IUALN=IUALN-10                                     DUAL      136
      LXS=0                                                             DUAL      137
      IF (IUALN.EQ.1)THEN                                               DUAL      138
C                                                                       DUAL      139
C   TYPE 1  LIMITER                                                     DUAL      140
C                                                                       DUAL      141
C   TERMINAL VOLTAGE INPUT BLOCK                                        DUAL      142
C                                                                       DUAL      143
      IF (IDDAT(JU+9).EQ.0.AND.IDDAT(JU+10).EQ.0)THEN                   DUAL      144
      ETIN=ET*DDAT(JU+1)*DDAT(JU+3)                                     DUAL      145
      ELSE                                                              DUAL      146
      LXS=1                                                             DUAL      147
           IF (IDDAT(JU+10).EQ.0)THEN                                   DUAL      148
           DSTATE(LXS)=(DDAT(JU+1)*ET-XSTATE(JSTATE+LXS))/DDAT(JU+9)    DUAL      149
           ELSE                                                         DUAL      150
           DSTATE(LXS)=(DDAT(JU+1)*ET-DDAT(JU+9)*XSTATE(JSTATE+LXS)-    DUAL      151
     &     XSTATE(JSTATE+LXS+1))/DDAT(JU+10)                            DUAL      152
           LXS=LXS+1                                                    DUAL      153
           DSTATE(LXS)=XSTATE(JSTATE+LXS-1)                             DUAL      154
           ENDIF                                                        DUAL      155
      ETIN=XSTATE(JSTATE+LXS)*DDAT(JU+3)                                DUAL      156
      ENDIF                                                             DUAL      157
C                                                                       DUAL      158
C                                                                       DUAL      159
C   TERMINAL CURRENT INPUT SINO BLOCK                                   DUAL      160
C                                                                       DUAL      161
      PSGN=SQRT(PDGN*PDGN+PQGN*PQGN)                                    DUAL      162
      PDET=PDGN*DDAT(JU+2)/PSGN                                         DUAL      163
      QDET=PQGN*DDAT(JU+2)/PSGN                                         DUAL      164
      IF (IDDAT(JU+13).EQ.0.AND.IDDAT(JU+14).EQ.0)THEN                  DUAL      165
      XIT1=QDET*DDAT(JU+5)                                              DUAL      166
      ELSE                                                              DUAL      167
      LXS=LXS+1                                                         DUAL      168
           IF (IDDAT(JU+14).EQ.0)THEN                                   DUAL      169
           DSTATE(LXS)=(QDET-XSTATE(JSTATE+LXS))/DDAT(JU+13)            DUAL      170
           ELSE                                                         DUAL      171
           DSTATE(LXS)=(QDET-DDAT(JU+13)*XSTATE(JSTATE+LXS)-            DUAL      172
     &     XSTATE(JSTATE+LXS+1))/DDAT(JU+14)                            DUAL      173
           LXS=LXS+1                                                    DUAL      174
           DSTATE(LXS)=XSTATE(JSTATE+LXS-1)                             DUAL      175
           ENDIF                                                        DUAL      176
           XIT1=XSTATE(JSTATE+LXS)*DDAT(JU+5)                           DUAL      177
C                                                                       DUAL      178
      ENDIF                                                             DUAL      179
C                                                                       DUAL      180
C                                                                       DUAL      181
C   TERMINAL CURRENT INPUT COSO BLOCK                                   DUAL      182
      IF (IDDAT(JU+11).EQ.0.AND.IDDAT(JU+12).EQ.0)THEN                  DUAL      183
      XIT2=PDET*DDAT(JU+4)                                              DUAL      184
      ELSE                                                              DUAL      185
      LXS=LXS+1                                                         DUAL      186
           IF (IDDAT(JU+12).EQ.0)THEN                                   DUAL      187
           DSTATE(LXS)=(PDET-XSTATE(JSTATE+LXS))/DDAT(JU+11)            DUAL      188
           ELSE                                                         DUAL      189
           DSTATE(LXS)=(PDET-DDAT(JU+11)*XSTATE(JSTATE+LXS)-            DUAL      190
     &     XSTATE(JSTATE+LXS+1))/DDAT(JU+12)                            DUAL      191
           LXS=LXS+1                                                    DUAL      192
           DSTATE(LXS)=XSTATE(JSTATE+LXS-1)                             DUAL      193
           ENDIF                                                        DUAL      194
           XIT2=XSTATE(JSTATE+LXS)*DDAT(JU+4)                           DUAL      195
C                                                                       DUAL      196
      ENDIF                                                             DUAL      197
C                                                                       DUAL      198
C                                                                       DUAL      199
C   LIMITER OUTPUT BLOCK                                                DUAL      200
C                                                                       DUAL      201
      VSUM=XIT2-XIT1-ETIN                                               DUAL      202
      VSUM=VSUM*DDAT(JU+6)                                              DUAL      203
      GO TO 930                                                         DUAL      204
C                                                                       DUAL      205
C                                                                       DUAL      206
C   TYPE 2 AND TYPE 3 LIMITERS                                          DUAL      207
C                                                                       DUAL      208
      ELSE                                                              DUAL      209
C                                                                       DUAL      210
C   TERMINAL POWRT BLOCK                                                DUAL      211
C                                                                       DUAL      212
      IF (IDDAT(JU+9).EQ.0)THEN                                         DUAL      213
      PTIN=PDGN*DDAT(JU+1)                                              DUAL      214
      ELSE                                                              DUAL      215
      LXS=LXS+1                                                         DUAL      216
      DSTATE(LXS)=(DDAT(JU+1)*PDGN-XSTATE(JSTATE+LXS))/DDAT(JU+9)       DUAL      217
      PTIN=XSTATE(JSTATE+LXS)                                           DUAL      218
      ENDIF                                                             DUAL      219
      IF (IDDAT(JU+10).EQ.0)THEN                                        DUAL      220
      QTIN=PQGN*DDAT(JU+2)                                              DUAL      221
      ELSE                                                              DUAL      222
      LXS=LXS+1                                                         DUAL      223
      DSTATE(LXS)=(DDAT(JU+2)*PQGN-XSTATE(JSTATE+LXS))/DDAT(JU+10)      DUAL      224
      QTIN=XSTATE(JSTATE+LXS)                                           DUAL      225
      ENDIF                                                             DUAL      226
C                                                                       DUAL      227
C   TERMINAL VOLTAGE BLOCK                                              DUAL      228
C                                                                       DUAL      229
      ETX=ET*DDAT(JU+3)                                                 DUAL      230
      IF (KUALN.EQ.2) ETX=ETX*ETX*DDAT(JU+4)                            DUAL      231
      IF (IDDAT(JU+11).EQ.0)THEN                                        DUAL      232
      ETIN=ETX                                                          DUAL      233
      ELSE                                                              DUAL      234
      LXS=LXS+1                                                         DUAL      235
      DSTATE(LXS)=(ETX-XSTATE(JSTATE+LXS))/DDAT(JU+11)                  DUAL      236
      ETIN=XSTATE(JSTATE+LXS)                                           DUAL      237
      ENDIF                                                             DUAL      238
C                                                                       DUAL      239
C   LIMITER OUTPUT BLOCK                                                DUAL      240
C                                                                       DUAL      241
      IF (KUALN.GT.2) GO TO 890                                         DUAL      242
C        TYPE 2 LIMITER                                                 DUAL      243
      VSUM=PTIN-QTIN-ETIN                                               DUAL      244
      VSUM=VSUM*DDAT(JU+5)                                              DUAL      245
      IF (IDDAT(JU+12).NE.0)THEN                                        DUAL      246
      LXS=LXS+1                                                         DUAL      247
      DSTATE(LXS)=(VSUM-XSTATE(JSTATE+LXS))/DDAT(JU+12)                 DUAL      248
      VSUM=XSTATE(JSTATE+LXS)                                           DUAL      249
      ENDIF                                                             DUAL      250
      IF (IDDAT(JU+13).NE.0)THEN                                        DUAL      251
      LXS=LXS+1                                                         DUAL      252
      DSTATE(LXS)=(VSUM-XSTATE(JSTATE+LXS))/DDAT(JU+13)                 DUAL      253
      VSUM=XSTATE(JSTATE+LXS)                                           DUAL      254
      ENDIF                                                             DUAL      255
      IF (IDDAT(JU+14).NE.0)THEN                                        DUAL      256
      LXS=LXS+1                                                         DUAL      257
      DSTATE(LXS)=(VSUM-XSTATE(JSTATE+LXS))/DDAT(JU+14)                 DUAL      258
      VSUM=XSTATE(JSTATE+LXS)                                           DUAL      259
      ENDIF                                                             DUAL      260
C                                                                       DUAL      261
      GO TO 930                                                         DUAL      262
C                                                                       DUAL      263
C   FINAL BLOCKS FOR IUAL 3                                             DUAL      264
C                                                                       DUAL      265
 890  CONTINUE                                                          DUAL      266
      VSUM=PTIN+QTIN+ETIN                                               DUAL      267
      IF (IDDAT(JU+14).NE.0)THEN                                        DUAL      268
         LXS=LXS+1                                                      DUAL      269
         DSTATE(LXS)=(EFDN*DDAT(JU+6)-XSTATE(JSTATE+LXS))/DDAT(JU+14)   DUAL      270
         VSUM=VSUM-XSTATE(JSTATE+LXS)                                   DUAL      271
      ELSE                                                              DUAL      272
         VSUM=VSUM-EFDN*DDAT(JU+6)                                      DUAL      273
      ENDIF                                                             DUAL      274
      VSUM=VSUM*DDAT(JU+4)                                              DUAL      275
      IF (IDDAT(JU+12).NE.0)THEN                                        DUAL      276
      LXS=LXS+1                                                         DUAL      277
      DSTATE(LXS)=(VSUM-XSTATE(JSTATE+LXS))/DDAT(JU+12)                 DUAL      278
      VSUM=XSTATE(JSTATE+LXS)                                           DUAL      279
      ENDIF                                                             DUAL      280
      WS1=1.0-DDAT(JU+5)                                                DUAL      281
      IF (IDDAT(JU+13).NE.0)THEN                                        DUAL      282
         LXS=LXS+1                                                      DUAL      283
         DSTATE(LXS)=(VSUM-WS1*XSTATE(JSTATE+LXS))/DDAT(JU+13)          DUAL      284
         VUALN=VSUM+DDAT(JU+5)*XSTATE(JSTATE+LXS)                       DUAL      285
      ELSE                                                              DUAL      286
         VUALN=VSUM/WS1                                                 DUAL      287
      ENDIF                                                             DUAL      288
C                                                                       DUAL      289
      GO TO 960                                                         DUAL      290
C                                                                       DUAL      291
C   ENDIF KUALN.GT.1                                                    DUAL      292
C                                                                       DUAL      293
      ENDIF                                                             DUAL      294
C                                                                       DUAL      295
C   FINAL BLOCK FOR IUAL 1& 2                                           DUAL      296
C                                                                       DUAL      297
 930  CONTINUE                                                          DUAL      298
      IF (IDDAT(JU+15).EQ.0.AND.IDDAT(JU+16).EQ.0)THEN                  DUAL      299
      VUALN=VSUM                                                        DUAL      300
      ELSE                                                              DUAL      301
           IF (IDDAT(JU+16).EQ.0)THEN                                   DUAL      302
           LXS=LXS+1                                                    DUAL      303
           DSTATE(LXS)=(VSUM-XSTATE(JSTATE+LXS))/DDAT(JU+15)            DUAL      304
           VUALN=XSTATE(JSTATE+LXS)+DDAT(JU+7)*DSTATE(LSTATE+LXS)       DUAL      305
           ELSE                                                         DUAL      306
           LXS=LXS+1                                                    DUAL      307
           DSTATE(LXS)=(VSUM-DDAT(JU+15)*XSTATE(JSTATE+LXS)-            DUAL      308
     &     XSTATE(JSTATE+LXS+1))/DDAT(JU+16)                            DUAL      309
           LXS=LXS+1                                                    DUAL      310
           DSTATE(LXS)=XSTATE(JSTATE+LXS-1)                             DUAL      311
           VUALN=XSTATE(JSTATE+LXS)+DDAT(JU+7)*XSTATE(JSTATE+LXS-1)     DUAL      312
           ENDIF                                                        DUAL      313
C                                                                       DUAL      314
      ENDIF                                                             DUAL      315
 960  CONTINUE                                                          DUAL      316
      VUAL(JYU+1)=VUALN                                                 DUAL      317
      IF (VUAL(JYU+1).LT.0.0) VUAL(JYU+1)=0.0                           DUAL      318
C                                                                       DUAL      319
      LSTATE=LSTATE+LXS                                                 DUAL      320
      RETURN                                                            DUAL      321
      END                                                               DUAL      322
