Commit 303a6372 authored by Alexander Lapshin's avatar Alexander Lapshin

.

parent 7d654472
#pragma once #pragma once
#include <charconv>
#include <array>
#include <iostream> #include <iostream>
#include <sstream> #include <sstream>
#include <fstream> #include <fstream>
...@@ -15,7 +17,7 @@ ...@@ -15,7 +17,7 @@
#define SPACES " \t\r\n" #define SPACES " \t\r\n"
static std::string ToStr(const int arg, const int leading_zeros = 0) static std::string ToStr(const int arg, const int leading_zeros)
{ {
std::ostringstream ss; std::ostringstream ss;
if(leading_zeros) { if(leading_zeros) {
...@@ -25,7 +27,7 @@ static std::string ToStr(const int arg, const int leading_zeros = 0) ...@@ -25,7 +27,7 @@ static std::string ToStr(const int arg, const int leading_zeros = 0)
return ss.str(); return ss.str();
} }
static std::string ToStr(const size_t arg, const int leading_zeros = 0) static std::string ToStr(const size_t arg, const int leading_zeros)
{ {
std::ostringstream ss; std::ostringstream ss;
if (leading_zeros) { if (leading_zeros) {
...@@ -35,13 +37,64 @@ static std::string ToStr(const size_t arg, const int leading_zeros = 0) ...@@ -35,13 +37,64 @@ static std::string ToStr(const size_t arg, const int leading_zeros = 0)
return ss.str(); return ss.str();
} }
static std::string ToStr(const double arg) template <typename T>
void hangle_to_chars_error(const std::to_chars_result& res, const T& arg)
{ {
std::ostringstream ss; if (res.ec == std::errc::invalid_argument) {
ss << arg; throw Exp() << "failed to convert value [" << arg << "] to string, invalid argument";
return ss.str(); }
if (res.ec == std::errc::result_out_of_range) {
throw Exp() << "failed to convert value [" << arg << "] to string, out of range";
}
throw Exp() << "failed to convert value [" << arg << "] to string";
}
static std::string ToStr(const int arg)
{
std::array<char, 32> buf;
const auto res = std::to_chars(buf.data(), buf.data() + buf.size(), arg);
if (res.ec == std::errc()) {
return std::string(buf.data(), res.ptr - buf.data());
}
hangle_to_chars_error(res, arg);
return "";
} }
static std::string ToStr(const size_t arg)
{
std::array<char, 32> buf;
const auto res = std::to_chars(buf.data(), buf.data() + buf.size(), arg);
if (res.ec == std::errc()) {
return std::string(buf.data(), res.ptr - buf.data());
}
hangle_to_chars_error(res, arg);
return "";
}
static std::string ToStr(const double arg)
{
std::array<char, 32> buf;
const auto res = std::to_chars(buf.data(), buf.data() + buf.size(), arg);
if (res.ec == std::errc()) {
return std::string(buf.data(), res.ptr - buf.data());
}
hangle_to_chars_error(res, arg);
return "";
}
static std::string ToStr(const double value, const int precision) static std::string ToStr(const double value, const int precision)
{ {
......
...@@ -86,7 +86,7 @@ int cinterp_pvac( ...@@ -86,7 +86,7 @@ int cinterp_pvac(
/* Position */ /* Position */
if (j < 3) { if (j < 3) {
if (fabs(ephi.outv[j + 3][0]) > 1.e-10) { if (fabs(ephi.outv[j + 3][0]) > 1.e-10) {
/* Use velocities if they exist (hermite) */ /* Use velocities if they exists (hermite) */
hermite(pindex, 2, ephi.jds, &ephi.outv[j][0], &ephi.outv[j + 3][0], ephi.nv, 10, itime, &outvec[j], &vz, ircode); hermite(pindex, 2, ephi.jds, &ephi.outv[j][0], &ephi.outv[j + 3][0], ephi.nv, 10, itime, &outvec[j], &vz, ircode);
} }
else { else {
...@@ -95,7 +95,7 @@ int cinterp_pvac( ...@@ -95,7 +95,7 @@ int cinterp_pvac(
} }
} }
/* Velocity */ /* Velocity */
/* Interpolate if they exist */ /* Interpolate if they exists */
else if (fabs(ephi.outv[j][0]) > 1.e-10) { else if (fabs(ephi.outv[j][0]) > 1.e-10) {
hermite(pindex, 1, ephi.jds, &ephi.outv[j][0], &z, ephi.nv, 10, itime, &outvec[j], &vz, ircode); hermite(pindex, 1, ephi.jds, &ephi.outv[j][0], &z, ephi.nv, 10, itime, &outvec[j], &vz, ircode);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment