/[MITgcm]/MITgcm/eesupp/src/different_multiple.F
ViewVC logotype

Contents of /MITgcm/eesupp/src/different_multiple.F

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.3 - (show annotations) (download)
Mon May 24 14:57:55 1999 UTC (25 years ago) by adcroft
Branch: MAIN
CVS Tags: checkpoint28, checkpoint29, checkpoint23, checkpoint24, checkpoint25, checkpoint27, branch-atmos-merge-freeze, branch-atmos-merge-start, checkpoint26, branch-atmos-merge-shapiro, checkpoint33, checkpoint32, checkpoint31, checkpoint30, checkpoint34, branch-atmos-merge-zonalfilt, branch-atmos-merge-phase5, branch-atmos-merge-phase4, branch-atmos-merge-phase7, branch-atmos-merge-phase6, branch-atmos-merge-phase1, branch-atmos-merge-phase3, branch-atmos-merge-phase2
Branch point for: branch-atmos-merge
Changes since 1.2: +24 -21 lines
Re-arranged the IF statements to avoid using RETURNs.

1 C $Header: /u/gcmpack/models/MITgcmUV/eesupp/src/different_multiple.F,v 1.2 1998/11/03 15:28:03 cnh Exp $
2 #include "CPP_EEOPTIONS.h"
3
4 CStartofinterface
5 LOGICAL FUNCTION DIFFERENT_MULTIPLE( freq, val1, val2 )
6 C /==========================================================\
7 C | LOGICAL FUNCTION DIFFERENT_MULTIPLE |
8 C | o Checks two numbers multiple of a third number. |
9 C |==========================================================|
10 C | This routine is used for diagnostic and other periodic |
11 C | operations. It is very sensitive to arithmetic precision.|
12 C | For IEEE conforming arithmetic is works well but for |
13 C | cases where short cut arithmetic is used it may not work|
14 C | as expected. To overcome this issue compile this routine |
15 C | separately with no optimisation. |
16 C \==========================================================/
17 IMPLICIT NONE
18 C Returns TRUE if val1 and val2 are different multiples of freq.
19 _RL freq, val1, val2
20 CEndofinterface
21 _RL f, v1, v2, v3, v4, d1, d2, d3, step
22
23 C o Do easy cases first.
24 DIFFERENT_MULTIPLE = .FALSE.
25
26 IF ( freq .NE. 0. ) THEN
27 IF ( ABS(val1-val2) .GT. freq ) THEN
28 DIFFERENT_MULTIPLE = .TRUE.
29 ELSE
30
31 C o This case is more complex because of round-off error
32 f = freq
33 v1 = val1
34 v2 = val2
35 step = v1-v2
36
37 C Test v1 to see if its a "closest multiple"
38 v3 = v1 + step
39 v4 = NINT(v1/f)*f
40 d1 = v1-v4
41 d2 = v2-v4
42 d3 = v3-v4
43 IF ( ABS(d1) .LE. ABS(d2) .AND. ABS(d1) .LE. ABS(d3) )
44 & DIFFERENT_MULTIPLE = .TRUE.
45
46 ENDIF ! |val1-val2| > freq
47 ENDIF ! freq != 0
48
49 END

  ViewVC Help
Powered by ViewVC 1.1.22