CFPRIME DSGNAL                                                          DSGNAL      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 DSGNAL(K,H)                                            DSGNAL      3
CD                                                                      DSGNAL      4
CD    TO PRE-PROCESS THE INPUT SIGNAL(S) OF STABILIZER (ALL TYPES) FOR  DSGNAL      5
CD    CALCULATING THE STATE DERIVATIVES.                                DSGNAL      6
CD                                                                      DSGNAL      7
CD    NOTE THAT THE TF BLOCK IS INCLUDED IF THE INPUT IS FROM BUS       DSGNAL      8
CD    FREQUENCY.                                                        DSGNAL      9
CD                                                                      DSGNAL     10
      INCLUDE 'PARX.INS'                                                DSGNAL     11
      INCLUDE 'CNB4.INS'                                                DSGNAL     12
      INCLUDE 'CNB5.INS'                                                DSGNAL     13
      INCLUDE 'CNB9.INS'                                                DSGNAL     14
      INCLUDE 'CNB19.INS'                                               DSGNAL     15
      INCLUDE 'CNEXC.INS'                                               DSGNAL     16
      INCLUDE 'CNXSTA.INS'                                              DSGNAL     17
      INCLUDE 'CNMDAT.INS'                                              DSGNAL     18
      INCLUDE 'CNVOLT.INS'                                              DSGNAL     19
      INCLUDE 'CNUNIT.INS'                                              DSGNAL     20
      INCLUDE 'CNFLAG.INS'                                              DSGNAL     21
      INCLUDE 'CNPARX.INS'                                              DSGNAL     22
      INCLUDE 'CNYVAR.INS'                                              DSGNAL     23
      INCLUDE 'EQYVAR.INS'                                              DSGNAL     24
      INCLUDE 'CNSGAL.INS'                                              DSGNAL     25
C                                                                       DSGNAL     26
*IF DEBUG                                                               DSGNAL     27
      LDEB=(JDEB(88).NE.0)                                              DSGNAL     28
      IF (LDEB) ICOUNT=ICOUNT+1                                         DSGNAL     29
*ENDIF                                                                  DSGNAL     30
C                                                                       DSGNAL     31
        JS2=JYS+2                                                       DSGNAL     32
C                                                                       DSGNAL     33
        NSNO1=IDDAT(JS+1)                                               DSGNAL     34
        ITYP1=IDDAT(JS+2)                                               DSGNAL     35
        IF (ISTABN.EQ.9.OR.ISTABN.EQ.12) THEN                           DSGNAL     36
           NSNO2=IDDAT(JS+3)                                            DSGNAL     37
           ITYP2=IDDAT(JS+4)                                            DSGNAL     38
        ENDIF                                                           DSGNAL     39
C                                                                       DSGNAL     40
C  FIRST INPUT SIGNAL                                                   DSGNAL     41
C                                                                       DSGNAL     42
C  INPUT TYPE DOM PAC DF   P   V  DV                                    DSGNAL     43
        GOTO (510,520,530,540,550,560), ITYP1                           DSGNAL     44
  510   VSI1=XSTATE(IDOMG)                                              DSGNAL     45
        GOTO 590                                                        DSGNAL     46
  520   VSI1=PACCL                                                      DSGNAL     47
        GOTO 590                                                        DSGNAL     48
  530   KSTATE=KSTATE+1                                                 DSGNAL     49
C                                                                       DSGNAL     50
C     COUNT CURRENT COMPENSATION FOR BUS FREQUENCY INPUT (FIRST)        DSGNAL     51
C                                                                       DSGNAL     52
C              1   2   3   4   5   6   7   8                            DSGNAL     53
        GOTO (100,100,100,100,100,100,150,150,                          DSGNAL     54
C                                                                       DSGNAL     55
C              9   10  11  12                                           DSGNAL     56
     *        110,120,130,140), ISTABN                                  DSGNAL     57
C                                                                       DSGNAL     58
 100    RCMP=DDAT(JS+12)                                                DSGNAL     59
        XCMP=DDAT(JS+13)                                                DSGNAL     60
        JSTF=JS+11                                                      DSGNAL     61
        GOTO 150                                                        DSGNAL     62
C                                                                       DSGNAL     63
 110    RCMP=DDAT(JS+27)                                                DSGNAL     64
        XCMP=DDAT(JS+28)                                                DSGNAL     65
        JSTF=JS+26                                                      DSGNAL     66
        GOTO 150                                                        DSGNAL     67
C                                                                       DSGNAL     68
 120    RCMP=DDAT(JS+18)                                                DSGNAL     69
        XCMP=DDAT(JS+19)                                                DSGNAL     70
        JSTF=JS+17                                                      DSGNAL     71
        GOTO 150                                                        DSGNAL     72
C                                                                       DSGNAL     73
 130    RCMP=DDAT(JS+27)                                                DSGNAL     74
        XCMP=DDAT(JS+28)                                                DSGNAL     75
        JSTF=JS+26                                                      DSGNAL     76
        GOTO 150                                                        DSGNAL     77
C                                                                       DSGNAL     78
 140    RCMP=DDAT(JS+20)                                                DSGNAL     79
        XCMP=DDAT(JS+21)                                                DSGNAL     80
        JSTF=JS+19                                                      DSGNAL     81
C                                                                       DSGNAL     82
 150    CONTINUE                                                        DSGNAL     83
C                                                                       DSGNAL     84
        IF (NSNO1.NE.K) THEN                                            DSGNAL     85
           RCMP=0.0                                                     DSGNAL     86
           XCMP=0.0                                                     DSGNAL     87
        END IF                                                          DSGNAL     88
C                                                                       DSGNAL     89
        VREAL=REAL(VOLT(NSNO1))+RCMP*CDG(1,N)-XCMP*CDG(2,N)             DSGNAL     90
        VAMG=AIMAG(VOLT(NSNO1))+XCMP*CDG(1,N)+RCMP*CDG(2,N)             DSGNAL     91
        VM=VREAL*VREAL+VAMG*VAMG                                        DSGNAL     92
        IF (VM.GT.1.E-6) THEN                                           DSGNAL     93
           VSI1=ATAN2(VAMG,VREAL)                                       DSGNAL     94
        ELSE                                                            DSGNAL     95
           VSI1=0.0                                                     DSGNAL     96
        END IF                                                          DSGNAL     97
        IF (VSI1.LT.0.0) VSI1=VSI1+6.2831853                            DSGNAL     98
        IF (VREAL.GT.0.0) THEN                                          DSGNAL     99
           IF (VAMG.GT.0.0) IQUAT1=1                                    DSGNAL    100
           IF (VAMG.LT.0.0) IQUAT1=4                                    DSGNAL    101
        END IF                                                          DSGNAL    102
        IF (IQUAT1.EQ.1.AND.IYVAR(JS2+1).EQ.4)                          DSGNAL    103
     *     IYVAR(JS2+2)=IYVAR(JS2+2)+1                                  DSGNAL    104
        VSI1=VSI1+IYVAR(JS2+2)*6.2831853                                DSGNAL    105
        IF ((VSI1-XSTATE(JSTATE+KSTATE)).GT.6.0) THEN                   DSGNAL    106
           VSI1=VSI1-6.2831853                                          DSGNAL    107
           IYVAR(JS2+2)=IYVAR(JS2+2)-1                                  DSGNAL    108
        END IF                                                          DSGNAL    109
C                                                                       DSGNAL    110
        IF (H.EQ.0.0) THEN                                              DSGNAL    111
           DSTATE(LSTATE+KSTATE)=YVAR(JS2+3)                            DSGNAL    112
           XSTATE(JSTATE+KSTATE)=VSI1-YVAR(JS2+3)*DDAT(JSTF)            DSGNAL    113
           VSI1=YVAR(JS2+3)/WXBASE                                      DSGNAL    114
        ELSE                                                            DSGNAL    115
           DSTATE(LSTATE+KSTATE)=(VSI1-XSTATE(JSTATE+KSTATE))           DSGNAL    116
     &                           /DDAT(JSTF)                            DSGNAL    117
           VSI1=DSTATE(LSTATE+KSTATE)/WXBASE                            DSGNAL    118
        END IF                                                          DSGNAL    119
C                                                                       DSGNAL    120
        IYVAR(JS2+1)=IQUAT1                                             DSGNAL    121
        YVAR(JS2+3)=DSTATE(LSTATE+KSTATE)                               DSGNAL    122
        JS2=JS2+3                                                       DSGNAL    123
        GOTO 590                                                        DSGNAL    124
  540   VSI1=PDGN                                                       DSGNAL    125
        GOTO 590                                                        DSGNAL    126
  550   VSI1=CABS(VOLT(NSNO1))                                          DSGNAL    127
        GOTO 590                                                        DSGNAL    128
  560   VSI1=CABS(VOLT(NSNO1))-YVAR(JS2+1)                              DSGNAL    129
        JS2=JS2+1                                                       DSGNAL    130
C                                                                       DSGNAL    131
  590   CONTINUE                                                        DSGNAL    132
*IF DEBUG                                                               DSGNAL    133
        IF((LDEB).AND.ICOUNT.EQ.4)WRITE(IUD6,1000)NSNO1,ITYP1,VSI1      DSGNAL    134
        IF((LDEB).AND.ICOUNT.EQ.4)WRITE(IUD6,1110)TS,VSI1,              DSGNAL    135
     &    XSTATE(IDOMG)/WXBASE                                          DSGNAL    136
*ENDIF                                                                  DSGNAL    137
C                                                                       DSGNAL    138
C  SECOND INPUT SIGNAL (TYPE 9 AND 12 ONLY)                             DSGNAL    139
C                                                                       DSGNAL    140
      IF (ISTABN.EQ.9.OR.ISTABN.EQ.12) THEN                             DSGNAL    141
C  INPUT TYPE DOM PAC DF   P   V  DV                                    DSGNAL    142
        GOTO (610,620,630,640,650,660), ITYP2                           DSGNAL    143
  610   VSI2=XSTATE(IDOMG)                                              DSGNAL    144
        GOTO 690                                                        DSGNAL    145
  620   VSI2=PACCL                                                      DSGNAL    146
        GOTO 690                                                        DSGNAL    147
  630   KSTATE=KSTATE+1                                                 DSGNAL    148
C                                                                       DSGNAL    149
C     COUNT CURRENT COMPENSATION FOR BUS FREQUENCY INPUT (SECOND)       DSGNAL    150
C                                                                       DSGNAL    151
C              1   2   3   4   5   6   7   8                            DSGNAL    152
        GOTO (200,200,200,200,200,200,250,250,                          DSGNAL    153
C                                                                       DSGNAL    154
C              9   10  11  12                                           DSGNAL    155
     *        210,220,230,240), ISTABN                                  DSGNAL    156
C                                                                       DSGNAL    157
 200    RCMP=DDAT(JS+12)                                                DSGNAL    158
        XCMP=DDAT(JS+13)                                                DSGNAL    159
        JSTF=JS+11                                                      DSGNAL    160
        GOTO 250                                                        DSGNAL    161
C                                                                       DSGNAL    162
 210    RCMP=DDAT(JS+27)                                                DSGNAL    163
        XCMP=DDAT(JS+28)                                                DSGNAL    164
        JSTF=JS+26                                                      DSGNAL    165
        GOTO 250                                                        DSGNAL    166
C                                                                       DSGNAL    167
 220    RCMP=DDAT(JS+18)                                                DSGNAL    168
        XCMP=DDAT(JS+19)                                                DSGNAL    169
        JSTF=JS+17                                                      DSGNAL    170
        GOTO 250                                                        DSGNAL    171
C                                                                       DSGNAL    172
 230    RCMP=DDAT(JS+27)                                                DSGNAL    173
        XCMP=DDAT(JS+28)                                                DSGNAL    174
        JSTF=JS+26                                                      DSGNAL    175
        GOTO 250                                                        DSGNAL    176
C                                                                       DSGNAL    177
 240    RCMP=DDAT(JS+20)                                                DSGNAL    178
        XCMP=DDAT(JS+21)                                                DSGNAL    179
        JSTF=JS+19                                                      DSGNAL    180
C                                                                       DSGNAL    181
 250    CONTINUE                                                        DSGNAL    182
C                                                                       DSGNAL    183
        IF (NSNO2.NE.K) THEN                                            DSGNAL    184
           RCMP=0.0                                                     DSGNAL    185
           XCMP=0.0                                                     DSGNAL    186
        END IF                                                          DSGNAL    187
C                                                                       DSGNAL    188
        VREAL=REAL(VOLT(NSNO2))+RCMP*CDG(1,N)-XCMP*CDG(2,N)             DSGNAL    189
        VAMG=AIMAG(VOLT(NSNO2))+XCMP*CDG(1,N)+RCMP*CDG(2,N)             DSGNAL    190
        VM=VREAL*VREAL+VAMG*VAMG                                        DSGNAL    191
        IF (VM.GT.1.E-6) THEN                                           DSGNAL    192
           VSI2=ATAN2(VAMG,VREAL)                                       DSGNAL    193
        ELSE                                                            DSGNAL    194
           VSI2=0.0                                                     DSGNAL    195
        END IF                                                          DSGNAL    196
        IF (VSI2.LT.0.0) VSI2=VSI2+6.2831853                            DSGNAL    197
        IF (VREAL.GT.0.0) THEN                                          DSGNAL    198
           IF (VAMG.GT.0.0) IQUAT2=1                                    DSGNAL    199
           IF (VAMG.LT.0.0) IQUAT2=4                                    DSGNAL    200
        END IF                                                          DSGNAL    201
        IF (IQUAT2.EQ.1.AND.IYVAR(JS2+1).EQ.4)                          DSGNAL    202
     *     IYVAR(JS2+2)=IYVAR(JS2+2)+1                                  DSGNAL    203
        VSI2=VSI2+IYVAR(JS2+2)*6.2831853                                DSGNAL    204
        IF ((VSI2-XSTATE(JSTATE+KSTATE)).GT.6.0) THEN                   DSGNAL    205
           VSI2=VSI2-6.2831853                                          DSGNAL    206
           IYVAR(JS2+2)=IYVAR(JS2+2)-1                                  DSGNAL    207
        END IF                                                          DSGNAL    208
C                                                                       DSGNAL    209
        IF (H.EQ.0.0) THEN                                              DSGNAL    210
           DSTATE(LSTATE+KSTATE)=YVAR(JS2+3)                            DSGNAL    211
           XSTATE(JSTATE+KSTATE)=VSI2-YVAR(JS2+3)*DDAT(JSTF)            DSGNAL    212
           VSI2=YVAR(JS2+3)/WXBASE                                      DSGNAL    213
        ELSE                                                            DSGNAL    214
           DSTATE(LSTATE+KSTATE)=(VSI2-XSTATE(JSTATE+KSTATE))           DSGNAL    215
     &                           /DDAT(JSTF)                            DSGNAL    216
           VSI2=DSTATE(LSTATE+KSTATE)/WXBASE                            DSGNAL    217
        END IF                                                          DSGNAL    218
        IYVAR(JS2+1)=IQUAT2                                             DSGNAL    219
        YVAR(JS2+3)=DSTATE(LSTATE+KSTATE)                               DSGNAL    220
        JS2=JS2+3                                                       DSGNAL    221
        GOTO 690                                                        DSGNAL    222
  640   VSI2=PDGN                                                       DSGNAL    223
        GOTO 690                                                        DSGNAL    224
  650   VSI2=CABS(VOLT(NSNO2))                                          DSGNAL    225
        GOTO 690                                                        DSGNAL    226
  660   VSI2=CABS(VOLT(NSNO2))-YVAR(JS2+1)                              DSGNAL    227
        JS2=JS2+1                                                       DSGNAL    228
C                                                                       DSGNAL    229
  690   CONTINUE                                                        DSGNAL    230
*IF DEBUG                                                               DSGNAL    231
        IF((LDEB).AND.ICOUNT.EQ.4)WRITE(IUD6,2000)NSNO2,ITYP2,VSI2      DSGNAL    232
        IF((LDEB).AND.ICOUNT.EQ.4)WRITE(IUD6,2110)TS,VSI2,              DSGNAL    233
     &    XSTATE(IDOMG)/WXBASE                                          DSGNAL    234
*ENDIF                                                                  DSGNAL    235
      ENDIF                                                             DSGNAL    236
C                                                                       DSGNAL    237
*IF DEBUG                                                               DSGNAL    238
        IF (LDEB) THEN                                                  DSGNAL    239
           IF(ICOUNT.EQ.4)ICOUNT=0                                      DSGNAL    240
        ENDIF                                                           DSGNAL    241
*ENDIF                                                                  DSGNAL    242
C                                                                       DSGNAL    243
 1000   FORMAT(' %DEBUG IN DSGNAL : NSNO1 =',I5,'  ITYP1 = ',I5,        DSGNAL    244
     &         '  VSI1 = ',F12.5)                                       DSGNAL    245
 1110   FORMAT(1X,6F14.6)                                               DSGNAL    246
 2000   FORMAT(' %DEBUG IN DSGNAL : NSNO2 =',I5,'  ITYP2 = ',I5,        DSGNAL    247
     &         '  VSI2 = ',F12.5)                                       DSGNAL    248
 2110   FORMAT(1X,6F14.6)                                               DSGNAL    249
      RETURN                                                            DSGNAL    250
      END                                                               DSGNAL    251
