/[MITgcm]/MITgcm/verification/OpenAD/code_ad/different_multiple.F
ViewVC logotype

Contents of /MITgcm/verification/OpenAD/code_ad/different_multiple.F

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


Revision 1.1 - (show annotations) (download)
Sun Dec 4 06:39:18 2005 UTC (18 years, 6 months ago) by utke
Branch: MAIN
CVS Tags: checkpoint57y_pre, checkpoint58l_post, checkpoint58f_post, checkpoint58a_post, checkpoint57y_post, checkpoint58e_post, checkpoint58i_post, checkpoint58c_post, checkpoint58b_post, checkpoint58g_post, checkpoint57x_post, checkpoint58k_post, checkpoint58j_post, checkpoint58d_post, checkpoint57z_post, checkpoint58h_post, checkpoint58
various modifications (function to subroutine converions), control flow fix ups

1 C $Header: /u/gcmpack/MITgcm/eesupp/src/different_multiple.F,v 1.9 2005/09/27 18:38:28 jmc Exp $
2 C $Name: $
3
4 #include "CPP_EEOPTIONS.h"
5
6 CBOP
7 C !ROUTINE: DIFFERENT_MULTIPLE
8
9 C !INTERFACE:
10 LOGICAL FUNCTION DIFFERENT_MULTIPLE( freq, val1, step )
11 IMPLICIT NONE
12
13 C !DESCRIPTION:
14 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.
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
69
70 CBOP
71 C !ROUTINE: DIFFERENT_MULTIPLE
72
73 C !INTERFACE:
74 subroutine ad_s_DIFFERENT_MULTIPLE( freq, val1, step, isit )
75 IMPLICIT NONE
76
77 C !DESCRIPTION:
78 C *==========================================================*
79 C | LOGICAL FUNCTION DIFFERENT\_MULTIPLE
80 C | o Checks if a multiple of freq exist
81 C | around val1 +/- step/2
82 C *==========================================================*
83 C | This routine is used for diagnostic and other periodic
84 C | operations. It is very sensitive to arithmetic precision.
85 C | For IEEE conforming arithmetic it works well but for
86 C | cases where short cut arithmetic is used it may not work
87 C | as expected. To overcome this issue compile this routine
88 C | separately with no optimisation.
89 C *==========================================================*
90
91 C !INPUT PARAMETERS:
92 C == Routine arguments ==
93 C freq :: Frequency by which time is divided.
94 C val1 :: time that is checked
95 C step :: length of time interval (around val1) that is checked
96 _RL freq, val1, step
97 logical isit
98
99 C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----|
100
101 C !LOCAL VARIABLES:
102 C == Local variables ==
103 C v1, v2, v3, v4 :: Temp. for holding time
104 C d1, d2, d3 :: Temp. for hold difference
105 _RL v1, v2, v3, v4, d1, d2, d3
106 CEOP
107
108 C o Do easy cases first.
109 isit = .FALSE.
110
111 IF ( freq .NE. 0. ) THEN
112 IF ( ABS(step) .GT. freq ) THEN
113 isit = .TRUE.
114 ELSE
115
116 C o This case is more complex because of round-off error
117 v1 = val1
118 v2 = val1 - step
119 v3 = val1 + step
120
121 C Test v1 to see if its a "closest multiple"
122 v4 = NINT(v1/freq)*freq
123 d1 = v1-v4
124 d2 = v2-v4
125 d3 = v3-v4
126 IF ( ABS(d1) .LT. ABS(d2) .AND. ABS(d1) .LE. ABS(d3) )
127 & isit = .TRUE.
128
129 ENDIF
130 ENDIF
131
132 RETURN
133 END

  ViewVC Help
Powered by ViewVC 1.1.22