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

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

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

revision 1.2 by cnh, Tue Nov 3 15:28:03 1998 UTC revision 1.8 by jmc, Sun May 15 02:58:40 2005 UTC
# Line 1  Line 1 
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        _RL  freq, val1, val2  C     !DESCRIPTION:
14  CEndofinterface  C     *==========================================================*
15        _RL  f, v1, v2, v3, v4, d1, d2, d3, step  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.  C     o Do easy cases first.
44        DIFFERENT_MULTIPLE = .FALSE.        DIFFERENT_MULTIPLE = .FALSE.
       IF ( freq .EQ. 0. ) RETURN  
       IF ( ABS(val1-val2) .GT. freq ) THEN  
        DIFFERENT_MULTIPLE = .TRUE.  
        RETURN  
       ENDIF  
45    
46  C     o This case is more complex because of round-off error        IF ( freq .NE. 0. ) THEN
47        f = freq          IF ( ABS(step) .GT. freq ) THEN
48        v1 = val1           DIFFERENT_MULTIPLE = .TRUE.
49        v2 = val2          ELSE
50        step = v1-v2  
51    C         o This case is more complex because of round-off error
52  C     Test v1 to see if its a "closest multiple"            v1 = val1
53        v3 = v1 + step            v2 = val1 - step
54        v4 = NINT(v1/f)*f            v3 = val1 + step
55        d1 = v1-v4  
56        d2 = v2-v4  C         Test v1 to see if its a "closest multiple"
57        d3 = v3-v4            v4 = NINT(v1/freq)*freq
58        IF ( ABS(d1) .LE. ABS(d2) .AND.            d1 = v1-v4
59       &     ABS(d1) .LE. ABS(d3) ) DIFFERENT_MULTIPLE = .TRUE.            d2 = v2-v4
60              d3 = v3-v4
61              IF ( ABS(d1) .LE. ABS(d2) .AND. ABS(d1) .LE. ABS(d3) )
62         &        DIFFERENT_MULTIPLE = .TRUE.
63    
64            ENDIF
65          ENDIF
66    
67          RETURN
68        END        END

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.8

  ViewVC Help
Powered by ViewVC 1.1.22