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