ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
ERF_SBMCanonicalIdentity.H
Go to the documentation of this file.
1 #ifndef ERF_SBM_CANONICAL_IDENTITY_H_
2 #define ERF_SBM_CANONICAL_IDENTITY_H_
3 
4 #include <AMReX_REAL.H>
5 
6 #include <cmath>
7 #include <iomanip>
8 #include <limits>
9 #include <locale>
10 #include <sstream>
11 #include <string>
12 
13 namespace erf_sbm {
14 
15 // Scientific metadata is part of the restart/schema identity. Keep this
16 // policy in one place so grids and layouts cannot silently serialize the same
17 // value with different precision or locale rules.
18 template <typename T>
19 std::string canonical_decimal (const T value)
20 {
21  std::ostringstream out;
22  out.imbue(std::locale::classic());
23  out.setf(std::ios_base::scientific, std::ios_base::floatfield);
24  out << std::setprecision(std::numeric_limits<T>::max_digits10) << value;
25  return out.str();
26 }
27 
28 inline std::string canonical_real (const amrex::Real value,
29  const bool allow_unbounded_nan = false)
30 {
31  if (allow_unbounded_nan && std::isnan(value)) return "unbounded";
32  return canonical_decimal(value);
33 }
34 
35 } // namespace erf_sbm
36 
37 #endif
@ T
Definition: ERF_IndexDefines.H:180
Definition: ERF.H:128
std::string canonical_real(const amrex::Real value, const bool allow_unbounded_nan=false)
Definition: ERF_SBMCanonicalIdentity.H:28
std::string canonical_decimal(const T value)
Definition: ERF_SBMCanonicalIdentity.H:19