CFPRIME DFREQ                                                           DFREQ       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  DFREQ(TH1, CK1, CK2, DT1)                             DFREQ       3
CD -------------------------------------------------------------------  DFREQ       4
CD                                                                      DFREQ       5
CD              *****     DFREQ   ROUTINE   *****                       DFREQ       6
CD                                                                      DFREQ       7
CD -------------------------------------------------------------------  DFREQ       8
CD                                                                      DFREQ       9
CD       PURPOSE:  THIS SUBPROGRAM COMPUTES THE CHANGE IN FREQUENCY.    DFREQ      10
CD                                                                      DFREQ      11
CD                                                                      DFREQ      12
CD       COMMENTS:  ON 'RETURN', 'CK1' CONTAINS THE NEW THETA AND       DFREQ      13
CD                 'CK2' CONTAINS THE CHANGE IN FREQUENCY.              DFREQ      14
CD                 CHANGE IN FREQUENCY = (NEW THETA - OLD THETA) /      DFREQ      15
CD                     CHANGE IN TIME = (TH2 - TH1) / DT1               DFREQ      16
CD                                                                      DFREQ      17
CD                                                                      DFREQ      18
CD       DEFINITION OF LOCAL VARIABLES:                                 DFREQ      19
CD                 CK1    = DOUBLE PRECISION ARGUMENT 2, THE REAL PART  DFREQ      20
CD                          OF THE VOLTAGE.                             DFREQ      21
CD                 CK2    = DOUBLE PRECISION, ARGUMENT 3, THE IMAGINARY DFREQ      22
CD                          PART OF THE VOLTAGE.                        DFREQ      23
CD                 DT1    = ARGUMENT 4, THE TIME INCREMENT.             DFREQ      24
CD                 TH1    = ARGUMENT 1, THE OLD VALUE OF THETA.         DFREQ      25
CD                 TH2    = TEMPORARY STORAGE FOR THE NEW VALUE OF      DFREQ      26
CD                          THETA.                                      DFREQ      27
CD                 TWOPI  = DOUBLE PRECISION, 2.0 * PII.                DFREQ      28
CD                 ZPI2   = DOUBLE PRECISION, PII / 2.0.                DFREQ      29
CD                                                                      DFREQ      30
CD -------------------------------------------------------------------  DFREQ      31
C                                                                       DFREQ      32
      DOUBLE PRECISION  CK1, CK2, TWOPI, ZPI2                           DFREQ      33
C                                                                       DFREQ      34
      DATA              TWOPI /6.283185307/                             DFREQ      35
      DATA              ZPI2  /1.570796327/                             DFREQ      36
C                                                                       DFREQ      37
C---------------------------------------------------------------------  DFREQ      38
C                                                                       DFREQ      39
      IF (ABS(CK1) + ABS(CK2) .LE. 0.0)  GO TO 40                       DFREQ      40
      TH2 = ATAN2(CK2,CK1)                                              DFREQ      41
C---------------------------------------------------------------------  DFREQ      42
C     ANGLE AT TIME2 IN RADIANS                                         DFREQ      43
C---------------------------------------------------------------------  DFREQ      44
      IF (SIGN(1.0,TH1) - SIGN(1.0,TH2) .LE. 0.0)  GO TO 50             DFREQ      45
      IF (TH1 .LT. 0.0)                GO TO 10                         DFREQ      46
      IF (TH1 .GT. ZPI2)               GO TO 20                         DFREQ      47
      GO TO 50                                                          DFREQ      48
C                                                                       DFREQ      49
   10 IF (TH1 .LT. -ZPI2)              GO TO 30                         DFREQ      50
      GO TO 50                                                          DFREQ      51
C                                                                       DFREQ      52
C---------------------------------------------------------------------  DFREQ      53
C     TH1 IS IN QUADRANT 2 , TH2 IN QUADRANT 3 OR 4                     DFREQ      54
C---------------------------------------------------------------------  DFREQ      55
   20 CK2 = (TWOPI - TH1 + TH2) / DT1                                   DFREQ      56
      GO TO 60                                                          DFREQ      57
C                                                                       DFREQ      58
   30 CK2 = (TH2 - TH1 - TWOPI) / DT1                                   DFREQ      59
      GO TO 60                                                          DFREQ      60
C                                                                       DFREQ      61
C---------------------------------------------------------------------  DFREQ      62
C        THE VOLTAGE IS ZERO.  SET THE ANGLE TO ZERO.                   DFREQ      63
C---------------------------------------------------------------------  DFREQ      64
   40 TH2 = 0.0                                                         DFREQ      65
   50 CK2 = (TH2 - TH1) / DT1                                           DFREQ      66
   60 CK1 = TH2                                                         DFREQ      67
      RETURN                                                            DFREQ      68
C                                                                       DFREQ      69
      END                                                               DFREQ      70
