CFPRIME DPAINT                                                          DPAINT      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 DPAINT(IEBK)                                           DPAINT      3
CD                                                                      DPAINT      4
CD   THIS SUBROUTINE INITIALIZES THE POWER ANGLE RELAY                  DPAINT      5
CD   IT ALSO SEARCHES THE REMOTE RELAY TABLES TO FIND THE INDICES OF    DPAINT      6
CD   THE REMOTE RELAYS FOR THIS RELAY.                                  DPAINT      7
CD                                                                      DPAINT      8
CD   ROUTINE OUTPUT:                                                    DPAINT      9
CD                                                                      DPAINT     10
CD   IEBK =0 NO ERROR                                                   DPAINT     11
CD   IEBK =1 WHEN                                                       DPAINT     12
CD   LINE OF THE POWER ANGLE RELAY CAN NOT BE FOUND                     DPAINT     13
CD                                                                      DPAINT     14
CD   STEPS OF INITIALIZATION ARE:                                       DPAINT     15
CD                                                                      DPAINT     16
C                                                                       DPAINT     17
      INCLUDE 'PARX.INS'                                                DPAINT     18
      INCLUDE 'CNPT.INS'                                                DPAINT     19
      INCLUDE 'CNAUTO.INS'                                              DPAINT     20
      INCLUDE 'CNNNEW.INS'                                              DPAINT     21
      INCLUDE 'CNSTN.INS'                                               DPAINT     22
      INCLUDE 'CNB19.INS'                                               DPAINT     23
      INCLUDE 'CNUNIT.INS'                                              DPAINT     24
      INCLUDE 'CNLFDA.INS'                                              DPAINT     25
      INCLUDE 'CNVOLT.INS'                                              DPAINT     26
      INCLUDE 'CNSELI.INS'                                              DPAINT     27
      INCLUDE 'CNMSG.INS'                                               DPAINT     28
C                                                                       DPAINT     29
      CHARACTER*2 CID                                                   DPAINT     30
      INTEGER*4 ICID                                                    DPAINT     31
C                                                                       DPAINT     32
      COMPLEX VOLTK                                                     DPAINT     33
      DIMENSION VOLTX(2)                                                DPAINT     34
      EQUIVALENCE (VOLTK,VOLTX(1)),(VOLTX(1),VREAL),(VOLTX(2),VIMAG)    DPAINT     35
CD                                                                      DPAINT     36
CD 1. REORDER BUS NUMBERS IN POWER ANGLE RELAY                          DPAINT     37
CD                                                                      DPAINT     38
      IEBK=0                                                            DPAINT     39
      DO 1000 I=LDPDA,NDPDA                                             DPAINT     40
C                                                                       DPAINT     41
      K=IDATPT(I)                                                       DPAINT     42
C                                                                       DPAINT     43
      IF(IADATA(K+1).GT.9)GOTO 1000                                     DPAINT     44
C                                                                       DPAINT     45
      NLFI=IADATA(K+2)                                                  DPAINT     46
      NLFJ=IADATA(K+3)                                                  DPAINT     47
      NABUS=IADATA(K+5)                                                 DPAINT     48
      NPROGI=NNEW(NLFI)                                                 DPAINT     49
      NPROGJ=NNEW(NLFJ)                                                 DPAINT     50
      NAPROG=NNEW(NABUS)                                                DPAINT     51
      IADATA(K+1)=0                                                     DPAINT     52
      IADATA(K+2)=NPROGI                                                DPAINT     53
      IADATA(K+3)=NPROGJ                                                DPAINT     54
      IADATA(K+5)=NAPROG                                                DPAINT     55
      NI3=NPROGI*3                                                      DPAINT     56
      NJ3=NPROGJ*3                                                      DPAINT     57
      ICID=IADATA(K+4)                                                  DPAINT     58
      CALL UNPACK(CID,JJJ,ICID)                                         DPAINT     59
      IDRRR=IADATA(K+7)                                                 DPAINT     60
C                                                                       DPAINT     61
      CALL LOLINE(NPROGI,NPROGJ,CID,JNL)                                DPAINT     62
      IF(JNL.EQ.0)THEN                                                  DPAINT     63
       IEBK=1                                                           DPAINT     64
       WRITE (MSG(1), 6100) NLFI, INAME(NI3 - 2), INAME(NI3 - 1),       DPAINT     65
     +                      INAME(NI3), NLFJ, INAME(NJ3 - 2),           DPAINT     66
     +                      INAME(NJ3 - 1), INAME(NJ3)                  DPAINT     67
       WRITE (MSG(2), 6200) CID                                         DPAINT     68
       CALL PRTMSG (2)                                                  DPAINT     69
      IADATA(K+1)=10                                                    DPAINT     70
       GOTO 1000                                                        DPAINT     71
      ELSE                                                              DPAINT     72
CD                                                                      DPAINT     73
CD 2. LOAD THE LINE PARAMETER INTO ADDAT ARRAY                          DPAINT     74
CD                                                                      DPAINT     75
       JNL5=IABS(JNL)                                                   DPAINT     76
       JNL5=JNL5*5                                                      DPAINT     77
       ITFK=LFTB(JNL5-4)                                                DPAINT     78
       CALL UNPACK(CID,NJSELI,ITFK)                                     DPAINT     79
       IADATA(K+36)=NJSELI                                              DPAINT     80
       IF(NJSELI.NE.0)THEN                                              DPAINT     81
        ADATA(K+32)=EQPI(1,NJSELI)                                      DPAINT     82
        ADATA(K+33)=-EQPI(2,NJSELI)                                     DPAINT     83
        ADATA(K+34)=EQPI(3,NJSELI)                                      DPAINT     84
        ADATA(K+35)=EQPI(4,NJSELI)                                      DPAINT     85
       ELSE                                                             DPAINT     86
        ADATA(K+32)=GA(JNL5-2)                                          DPAINT     87
        ADATA(K+33)=-BA(JNL5-1)                                         DPAINT     88
        ADATA(K+34)=0.                                                  DPAINT     89
        ADATA(K+35)=BCHG(JNL5)/2.                                       DPAINT     90
       ENDIF                                                            DPAINT     91
      ENDIF                                                             DPAINT     92
CD                                                                      DPAINT     93
CD 3. CONVERT CYCLE INTO SECOND ACCORDING TO FREQUENCY BASE.            DPAINT     94
CD                                                                      DPAINT     95
      ADATA(K+12)=ADATA(K+12)/FQBASE                                    DPAINT     96
      ADATA(K+17)=ADATA(K+17)/FQBASE                                    DPAINT     97
      ADATA(K+19)=ADATA(K+19)/FQBASE                                    DPAINT     98
      ADATA(K+20)=ADATA(K+20)/FQBASE                                    DPAINT     99
CD                                                                      DPAINT    100
CD 4. CONVERT THE RATE AND POWER SETTING TO PU                          DPAINT    101
CD                                                                      DPAINT    102
      ADATA(K+9)=ADATA(K+9)/BASPC                                       DPAINT    103
      ADATA(K+10)=ADATA(K+10)/BASPC                                     DPAINT    104
C                                                                       DPAINT    105
      ADATA(K+14)=ADATA(K+14)/BASPC                                     DPAINT    106
      ADATA(K+15)=ADATA(K+15)/BASPC                                     DPAINT    107
CD                                                                      DPAINT    108
CD 5. CALCULATE THE POWER FLOW IN THE RELAYED LINE                      DPAINT    109
CD                                                                      DPAINT    110
      GIJ = ADATA(K+32)                                                 DPAINT    111
      BIJ = ADATA(K+33)                                                 DPAINT    112
      GIO = ADATA(K+34)                                                 DPAINT    113
      BIO = ADATA(K+45)                                                 DPAINT    114
C                                                                       DPAINT    115
      GT = GIO + GIJ                                                    DPAINT    116
      BT = BIO + BIJ                                                    DPAINT    117
C                                                                       DPAINT    118
      VOLTK=VOLT(NPROGI)                                                DPAINT    119
      EI = VREAL                                                        DPAINT    120
      FI = VIMAG                                                        DPAINT    121
C                                                                       DPAINT    122
      VOLTK=VOLT(NPROGJ)                                                DPAINT    123
      EJ = VREAL                                                        DPAINT    124
      FJ = VIMAG                                                        DPAINT    125
C                                                                       DPAINT    126
      C1R = EI*GT - FI*BT                                               DPAINT    127
      C1I = EI*BT + FI*GT                                               DPAINT    128
      C2R = EJ*GIJ - FJ*BIJ                                             DPAINT    129
      C2I = EJ*BIJ + FJ*GIJ                                             DPAINT    130
      CTR = C1R - C2R                                                   DPAINT    131
      CTI = C1I -C2I                                                    DPAINT    132
      P3IOLD = EI*CTR + FI*CTI                                          DPAINT    133
CD                                                                      DPAINT    134
CD 6. INITIALIZE THE POWER AND THE OUTPUT OF THE BLOCK OF THE RELAY     DPAINT    135
CD                                                                      DPAINT    136
      ADATA(K+21) = P3IOLD                                              DPAINT    137
      VOLTK=VOLT(NAPROG)                                                DPAINT    138
      EI = VREAL                                                        DPAINT    139
      FI = VIMAG                                                        DPAINT    140
      ANGLE =0.0                                                        DPAINT    141
      IF(EI.NE.0.0)THEN                                                 DPAINT    142
        ANGLE= ATAN2(FI,EI)                                             DPAINT    143
        ANGLE=ANGLE*57.2958                                             DPAINT    144
        IF(ANGLE.LT.0.0)ANGLE=ANGLE+360.                                DPAINT    145
      ENDIF                                                             DPAINT    146
      ADATA(K+22)=ANGLE                                                 DPAINT    147
      DO 100 IJ=23,31                                                   DPAINT    148
        ADATA(K+IJ)=0.0                                                 DPAINT    149
 100  CONTINUE                                                          DPAINT    150
CD                                                                      DPAINT    151
CD 7. SET UP REMOTE TRIPPING IF REMOTE TRIPPING SCHEME IS SEPCIFIED     DPAINT    152
CD                                                                      DPAINT    153
      IF(IDRRR.NE.0)THEN                                                DPAINT    154
       KSHIFT=K+36                                                      DPAINT    155
       CALL REMINT(KSHIFT,IDRRR)                                        DPAINT    156
      ENDIF                                                             DPAINT    157
C                                                                       DPAINT    158
 1000 CONTINUE                                                          DPAINT    159
C                                                                       DPAINT    160
6100   FORMAT (' *** ERROR DP RELAY BRANCH BETWEEN BUSES',2(I6,1X,3A4)) DPAINT    161
6200   FORMAT ('     WITH CIRCUIT ID ', A2, ' DOES NOT EXIST.')         DPAINT    162
C                                                                       DPAINT    163
      RETURN                                                            DPAINT    164
C                                                                       DPAINT    165
      END                                                               DPAINT    166
