NAPISD
PAHdb website C++ backend
Loading...
Searching...
No Matches
MinMax.cpp
1#include "MinMax.h"
2
3std::array<double, 2> MinMax::min_max(const std::vector<double> &values,
4 int flags) {
5
6 std::array<double, 2> min_max({0.0, 0.0});
7
8 for (const auto &v : values) {
9
10 if (v < min_max[0]) {
11
12 min_max[0] = v;
13 }
14
15 if (v > min_max[1]) {
16
17 min_max[1] = v;
18 }
19 }
20
21 if (flags != None) {
22
23 MinMax::nice(min_max, flags);
24 }
25
26 return (min_max);
27}
28
29std::array<double, 2>
30MinMax::min_max(const std::vector<std::vector<double>> &values, int flags) {
31
32 std::array<double, 2> min_max({0.0, 0.0});
33
34 for (const auto &vals : values) {
35
36 for (const auto v : vals) {
37
38 if (v < min_max[0]) {
39
40 min_max[0] = v;
41 }
42
43 if (v > min_max[1]) {
44
45 min_max[1] = v;
46 }
47 }
48 }
49
50 if (flags != None) {
51
52 MinMax::nice(min_max, flags);
53 }
54
55 return (min_max);
56}
57
58std::array<double, 2> MinMax::min_max(
59 const std::vector<std::vector<std::pair<double, double>>> &values,
60 int flags) {
61
62 std::array<double, 2> min_max({0.0, 0.0});
63
64 for (const auto &vals : values) {
65
66 for (const auto &v : vals) {
67
68 if (v.second < min_max[0]) {
69
70 min_max[0] = v.second;
71 }
72
73 if (v.second > min_max[1]) {
74
75 min_max[1] = v.second;
76 }
77 }
78 }
79
80 if (flags != None) {
81
82 MinMax::nice(min_max, flags);
83 }
84
85 return (min_max);
86}
87
88void MinMax::nice(std::array<double, 2> &min_max, int flags) {
89
90 double range = min_max[1] - min_max[0];
91
92 double expt = floor(log10(range));
93
94 double f = range / pow(10.0, expt);
95
96 if (f <= 1.0) {
97
98 f = 1.0;
99 } else if (f <= 2.0) {
100
101 f = 2.0;
102 } else if (f <= 5.0) {
103
104 f = 5.0;
105 } else {
106
107 f = 10.0;
108 }
109
110 range = f * pow(10.0, expt);
111
112 double d = range / 4.0;
113
114 expt = floor(log10(d));
115
116 f = d / pow(10.0, expt);
117
118 if (f < 1.5) {
119
120 f = 1.0;
121 } else if (f < 3.0) {
122
123 f = 2.0;
124 } else if (f < 7.0) {
125
126 f = 5.0;
127 } else {
128
129 f = 10.0;
130 }
131
132 d = f * pow(10.0, expt);
133
134 min_max[0] = floor(min_max[0] / d) * d;
135
136 if (flags & MinExtraRoom) {
137
138 min_max[0] *= 0.90;
139 }
140
141 min_max[1] = ceil(min_max[1] / d) * d;
142
143 if (flags & MaxExtraRoom) {
144
145 min_max[1] = 1.10 * ceil(min_max[1] / d) * d;
146 }
147}

Since FY2019 the NASA Ames PAH IR Spectroscopic Database is being supported through a directed Work Package at NASA Ames titled: "Laboratory Astrophysics - The NASA Ames PAH IR Spectroscopic Database".
Since FY2023 the NASA Ames PAH IR Spectroscopic Database is being supported through the Laboratory Astrophysics Rd 2 directed Work Package at NASA Ames.
© Copyright 2021-2025, Christiaan Boersma