What you want is a relative tolerance (with the tolerance scaled by XCELL
), not an absolute one. Note that if XCELL
is 45.0D3
( for 45KM cell-size), then your 1e-5 represents a difference in the tenth significant digit – way within the realm of potential round-off error problems. Instead:
if( abs (XCELL-XCELL3D).gt.(1e-5*XCELL) ) ...
or
if ( ((XCELL-XCELL3D)**2 .gt. (1e-5*XCELL)**2 ) ...
which is slightly more efficient computationally.