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