1 |
C $Header$ |
C $Header$ |
2 |
|
C $Name$ |
3 |
|
|
4 |
#include "CPP_EEOPTIONS.h" |
#include "CPP_EEOPTIONS.h" |
5 |
|
|
6 |
CStartofinterface |
CBOP |
7 |
LOGICAL FUNCTION DIFFERENT_MULTIPLE( freq, val1, val2 ) |
C !ROUTINE: DIFFERENT_MULTIPLE |
8 |
C /==========================================================\ |
|
9 |
C | LOGICAL FUNCTION DIFFERENT_MULTIPLE | |
C !INTERFACE: |
10 |
C | o Checks two numbers multiple of a third number. | |
LOGICAL FUNCTION DIFFERENT_MULTIPLE( freq, val1, step ) |
|
C |==========================================================| |
|
|
C | This routine is used for diagnostic and other periodic | |
|
|
C | operations. It is very sensitive to arithmetic precision.| |
|
|
C | For IEEE conforming arithmetic is works well but for | |
|
|
C | cases where short cut arithmetic is used it may not work| |
|
|
C | as expected. To overcome this issue compile this routine | |
|
|
C | separately with no optimisation. | |
|
|
C \==========================================================/ |
|
11 |
IMPLICIT NONE |
IMPLICIT NONE |
12 |
C Returns TRUE if val1 and val2 are different multiples of freq. |
|
13 |
REAL freq, val1, val2 |
C !DESCRIPTION: |
14 |
CEndofinterface |
C *==========================================================* |
15 |
|
C | LOGICAL FUNCTION DIFFERENT\_MULTIPLE |
16 |
|
C | o Checks if a multiple of freq exist |
17 |
|
C | around val1 +/- step/2 |
18 |
|
C *==========================================================* |
19 |
|
C | This routine is used for diagnostic and other periodic |
20 |
|
C | operations. It is very sensitive to arithmetic precision. |
21 |
|
C | For IEEE conforming arithmetic it works well but for |
22 |
|
C | cases where short cut arithmetic is used it may not work |
23 |
|
C | as expected. To overcome this issue compile this routine |
24 |
|
C | separately with no optimisation. |
25 |
|
C *==========================================================* |
26 |
|
|
27 |
|
C !INPUT PARAMETERS: |
28 |
|
C == Routine arguments == |
29 |
|
C freq :: Frequency by which time is divided. |
30 |
|
C val1 :: time that is checked |
31 |
|
C step :: length of time interval (around val1) that is checked |
32 |
|
_RL freq, val1, step |
33 |
|
|
34 |
|
C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----| |
35 |
|
|
36 |
|
C !LOCAL VARIABLES: |
37 |
|
C == Local variables == |
38 |
|
C v1, v2, v3, v4 :: Temp. for holding time |
39 |
|
C d1, d2, d3 :: Temp. for hold difference |
40 |
|
_RL v1, v2, v3, v4, d1, d2, d3 |
41 |
|
CEOP |
42 |
|
|
43 |
|
C o Do easy cases first. |
44 |
DIFFERENT_MULTIPLE = .FALSE. |
DIFFERENT_MULTIPLE = .FALSE. |
|
IF ( freq .EQ. 0. ) THEN |
|
|
DIFFERENT_MULTIPLE = .FALSE. |
|
|
ELSE |
|
|
DIFFERENT_MULTIPLE = INT(val1/freq) .NE. INT(val2/freq) |
|
|
ENDIF |
|
|
END |
|
45 |
|
|
46 |
|
IF ( freq .NE. 0. ) THEN |
47 |
|
IF ( ABS(step) .GT. freq ) THEN |
48 |
|
DIFFERENT_MULTIPLE = .TRUE. |
49 |
|
ELSE |
50 |
|
|
51 |
|
C o This case is more complex because of round-off error |
52 |
|
v1 = val1 |
53 |
|
v2 = val1 - step |
54 |
|
v3 = val1 + step |
55 |
|
|
56 |
|
C Test v1 to see if its a "closest multiple" |
57 |
|
v4 = NINT(v1/freq)*freq |
58 |
|
d1 = v1-v4 |
59 |
|
d2 = v2-v4 |
60 |
|
d3 = v3-v4 |
61 |
|
IF ( ABS(d1) .LT. ABS(d2) .AND. ABS(d1) .LE. ABS(d3) ) |
62 |
|
& DIFFERENT_MULTIPLE = .TRUE. |
63 |
|
|
64 |
|
ENDIF |
65 |
|
ENDIF |
66 |
|
|
67 |
|
RETURN |
68 |
|
END |