5 #include <boost/regex.hpp>
19 #define erfinv_a3 -0.140543331
20 #define erfinv_a2 0.914624893
21 #define erfinv_a1 -1.645349621
22 #define erfinv_a0 0.886226899
24 #define erfinv_b4 0.012229801
25 #define erfinv_b3 -0.329097515
26 #define erfinv_b2 1.442710462
27 #define erfinv_b1 -2.118377725
30 #define erfinv_c3 1.641345311
31 #define erfinv_c2 3.429567803
32 #define erfinv_c1 -1.62490649
33 #define erfinv_c0 -1.970840454
35 #define erfinv_d2 1.637067800
36 #define erfinv_d1 3.543889200
74 r -= (
erf (r) - x) / (2 /
sqrt (M_PI) *
exp (-r * r));
75 r -= (
erf (r) - x) / (2 /
sqrt (M_PI) *
exp (-r * r));
110 rotation = rotTheta.
conjugate() * rotation;
119 rotation = rotPhi.
conjugate() * rotation;
131 std::string output = str;
132 std::transform(output.begin(), output.end(), output.begin(), [](
const char c) {
return toupper(
c);});
145 long double t = this->
sum + y;
146 this->correction = (t - this->
sum) - y;
154 unsigned int rewindLinesSDDS(
const std::string &fileName,
double maxSPos,
bool checkForTime) {
157 std::fstream
fs(fileName.c_str(), std::fstream::in);
158 if (!
fs.is_open())
return 0;
161 std::queue<std::string> allLines;
162 unsigned int numParameters = 0;
163 unsigned int numColumns = 0;
164 unsigned int sposColumnNr = 0;
165 unsigned int timeColumnNr = 0;
166 double spos, time = 0.0;
167 double lastTime = -1.0;
169 boost::regex parameters(
"¶meter");
170 boost::regex column(
"&column");
171 boost::regex data(
"&data");
172 boost::regex end(
"&end");
173 boost::regex
name(
"name=([a-zA-Z0-9\\$_]+)");
176 std::istringstream linestream;
178 while (getline(
fs, line)) {
184 fs.open (fileName.c_str(), std::fstream::out);
186 if (!
fs.is_open())
return 0;
189 line = allLines.front();
192 if (boost::regex_search(line, match, parameters)) {
194 while (!boost::regex_search(line, match, end)) {
195 line = allLines.front();
199 }
else if (boost::regex_search(line, match, column)) {
201 while (!boost::regex_search(line, match, name)) {
202 line = allLines.front();
206 if (match[1] ==
"s") {
207 sposColumnNr = numColumns;
209 if (match[1] ==
"t") {
210 timeColumnNr = numColumns;
212 while (!boost::regex_search(line, match, end)) {
213 line = allLines.front();
218 }
while (!boost::regex_search(line, match, data));
220 while (!boost::regex_search(line, match, end)) {
221 line = allLines.front();
226 for (
unsigned int i = 0; i < numParameters; ++ i) {
227 fs << allLines.front() <<
"\n";
231 while (allLines.size() > 0) {
232 line = allLines.front();
234 linestream.str(line);
236 for (
unsigned int i = 0; i < timeColumnNr; ++ i) {
241 linestream.str(line);
242 for (
unsigned int i = 0; i < sposColumnNr; ++ i) {
250 if (!checkForTime || (time - lastTime) > 1
e-20)
258 if (allLines.size() > 0)
259 INFOMSG(
level2 <<
"rewind " + fileName +
" to " + std::to_string(maxSPos) <<
" m" <<
endl);
261 return allLines.size();
291 static const std::string base64_chars =
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
292 "abcdefghijklmnopqrstuvwxyz"
296 static inline bool is_base64(
unsigned char c) {
297 return (isalnum(c) || (c ==
'+') || (c ==
'/'));
301 const char* bytes_to_encode = string_to_encode.c_str();
302 unsigned int in_len = string_to_encode.size();
306 unsigned char char_array_3[3];
307 unsigned char char_array_4[4];
310 char_array_3[i++] = *(bytes_to_encode++);
312 char_array_4[0] = (char_array_3[0] & 0xfc) >> 2;
313 char_array_4[1] = ((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4);
314 char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6);
315 char_array_4[3] = char_array_3[2] & 0x3f;
317 for(i = 0; (i <4) ; i++)
318 ret += base64_chars[char_array_4[i]];
325 for(j = i; j < 3; j++)
326 char_array_3[j] =
'\0';
328 char_array_4[0] = (char_array_3[0] & 0xfc) >> 2;
329 char_array_4[1] = ((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4);
330 char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6);
331 char_array_4[3] = char_array_3[2] & 0x3f;
333 for (j = 0; (j < i + 1); j++)
334 ret += base64_chars[char_array_4[j]];
345 int in_len = encoded_string.size();
349 unsigned char char_array_4[4], char_array_3[3];
352 while (in_len-- && ( encoded_string[in_] !=
'=') && is_base64(encoded_string[in_])) {
353 char_array_4[i++] = encoded_string[in_]; in_++;
355 for (i = 0; i <4; i++)
356 char_array_4[i] = base64_chars.find(char_array_4[i]);
358 char_array_3[0] = (char_array_4[0] << 2) + ((char_array_4[1] & 0x30) >> 4);
359 char_array_3[1] = ((char_array_4[1] & 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2);
360 char_array_3[2] = ((char_array_4[2] & 0x3) << 6) + char_array_4[3];
362 for (i = 0; (i < 3); i++)
363 ret += char_array_3[i];
369 for (j = i; j <4; j++)
372 for (j = 0; j <4; j++)
373 char_array_4[j] = base64_chars.find(char_array_4[j]);
375 char_array_3[0] = (char_array_4[0] << 2) + ((char_array_4[1] & 0x30) >> 4);
376 char_array_3[1] = ((char_array_4[1] & 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2);
377 char_array_3[2] = ((char_array_4[2] & 0x3) << 6) + char_array_4[3];
379 for (j = 0; (j < i - 1); j++) ret += char_array_3[j];
constexpr double e
The value of .
Vector_t getTaitBryantAngles(Quaternion rotation, const std::string &elementName)
FTps< T, N > erf(const FTps< T, N > &x, int trunc=(FTps< T, N >::EXACT))
Error function.
Tps< T > sin(const Tps< T > &x)
Sine.
constexpr double two_pi
The value of .
Tps< T > exp(const Tps< T > &x)
Exponential.
std::string toUpper(const std::string &str)
T::PETE_Expr_t::PETE_Return_t sum(const PETE_Expr< T > &expr)
Tps< T > log(const Tps< T > &x)
Natural logarithm.
Inform & level2(Inform &inf)
KahanAccumulation & operator+=(double value)
constexpr double c
The velocity of light in m/s.
std::string base64_encode(const std::string &string_to_encode)
PETE_TBTree< FnArcTan2, PETE_Scalar< Vektor< T1, Dim > >, typename T2::PETE_Expr_t > atan2(const Vektor< T1, Dim > &l, const PETE_Expr< T2 > &r)
Vektor< double, 3 > Vector_t
PETE_TBTree< FnFmod, PETE_Scalar< Vektor< T1, Dim > >, typename T2::PETE_Expr_t > fmod(const Vektor< T1, Dim > &l, const PETE_Expr< T2 > &r)
Tps< T > sqrt(const Tps< T > &x)
Square root.
Tps< T > cos(const Tps< T > &x)
Cosine.
T euclidean_norm(const Vector< T > &)
Euclidean norm.
Vector_t rotate(const Vector_t &) const
std::string getGitRevision()
Quaternion conjugate() const
unsigned int rewindLinesSDDS(const std::string &fileName, double maxSPos, bool checkForTime)
rewind the SDDS file such that the spos of the last step is less or equal to maxSPos ...
std::string base64_decode(std::string const &encoded_string)
Inform & endl(Inform &inf)