NADCON5-ng  0.0.2
NADCON5 Next Generation Documentation
onzd2.f
Go to the documentation of this file.
1 c> \ingroup core
2 c> \if MANPAGE
3 c> \page onzd2
4 c> \endif
5 c>
6 c> Function to round a digit to one significant figure (one non zero digit), double precision
7 c>
8 c> Function "onzd" stands for "One Non Zero Digit"
9 c>
10 c> Version 2 operates just like version 1 (onzd()), only the input
11 c> and output will be real*8 values, not real*4.
12 c>
13 c> It takes a Real*8 number as input, and rounds that
14 c> number to the closest number containing only 1 non-zero digit.
15 c> The list of such numbers is infifinite, but contain
16 c> these, in order:
17 c>
18 c> 0.7 , 0.8 , 0.9 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9, 10 , 20 , 30 , etc etc
19 c>
20 c> \param[in] x input value
21 c> \return `real*8` rounded value of x to one non zero digit
22 c>
23 c> Examples of input/output are:
24 c>
25 c> 0.000019 => 0.000020
26 c> 0.007432 => 0.007000
27 c> 1.7 => 2.000000
28 c> 9.143 => 9.000000
29 c> 17.4 => 20.000000
30 c> 947.3 => 900.000000
31 c> 987.432 => 1000.000000
32 c> 1014.8 => 1000.000000
33 c> 1502.7 => 2000.000000
34 c>
35  function onzd2(x)
36  implicit none
37  real*8 onzd2,x,y
38  real*8 q,qten
39  integer*4 imag,iq,isign
40 
41 c - Function "onzd2" stands for "One Non Zero Digit, version 2"
42 
43 c - Version 2 operates just like version 1 (onzd.f), only the input
44 c - and output will be real*8 values, not real*4.
45 
46 c - It takes a Real*8 number as input, and rounds that
47 c - number to the closest number containing only 1 non-zero digit.
48 c - The list of such numbers is infifinite, but contain
49 c - these, in order:
50 c - 0.7 , 0.8 , 0.9 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9, 10 , 20 , 30 , etc etc
51 c -
52 c - Examples of input/output are:
53 c - 0.000019 => 0.000020
54 c - 0.007432 => 0.007000
55 c - 1.7 => 2.000000
56 c - 9.143 => 9.000000
57 c - 17.4 => 20.000000
58 c - 947.3 => 900.000000
59 c - 987.432 => 1000.000000
60 c - 1014.8 => 1000.000000
61 c - 1502.7 => 2000.000000
62 
63  y = x
64  isign = +1
65  if(x.lt.0)then
66  isign = -1
67  y = -x
68  endif
69 
70 c - 1) Determine magnitude of x, in terms of integer exponent of ten
71  imag = floor(dlog10(y))
72 
73 c - 1a) Get the multiplier
74  qten = (10.d0**imag)
75 
76 c - 2) Get into a range between 0.0 and 10.0
77  q = dble(y) / qten
78 
79 c - 3) Round to the closest integer (0 through 10)
80  iq = nint(q)
81 
82 c - 4) Scale back to the original size
83  onzd2 = isign * dble(iq) * qten
84 
85 c write(6,100)x,imag,qten,q,iq,onzd2
86 c 100 format(f30.15,1x,i10,1x,f30.15,1x,f30.15,1x,i10,1x,f30.15)
87 
88  return
89  end
90 
real *8 function onzd2(x)
Function to round a digit to one significant figure (one non zero digit), double precision.
Definition: onzd2.f:36