From 39f2e4786aa10a0fd1203e53aa556004706e488c Mon Sep 17 00:00:00 2001 From: Harry Moffat Date: Wed, 8 Feb 2012 16:00:55 +0000 Subject: [PATCH] Changed the default number of digits that are saved to an xml file. This crucial change is needed if xml files are to be used as restart files, where we will need close to machine precision. --- Cantera/src/base/ctml.cpp | 17 ++++++++--------- Cantera/src/base/ctml.h | 4 ++++ Cantera/src/base/xml.cpp | 2 +- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/Cantera/src/base/ctml.cpp b/Cantera/src/base/ctml.cpp index 2305aa6a7..ca4185b91 100644 --- a/Cantera/src/base/ctml.cpp +++ b/Cantera/src/base/ctml.cpp @@ -37,6 +37,9 @@ using namespace Cantera; namespace ctml { + std::string FP_Format = "%23.15E"; + std::string INT_Format = "%8d"; + //==================================================================================================================== //! Convert a floating point value from a string to a double /*! @@ -191,11 +194,10 @@ namespace ctml { void addIntegerArray(Cantera::XML_Node& node, const std::string &title, const int n, const int* const vals, const std::string units, const std::string type, const doublereal minval, const doublereal maxval) { - std::string fmt = "%8d"; int i; std::string v = ""; for (i = 0; i < n; i++) { - v += int2str(vals[i],fmt); + v += int2str(vals[i],INT_Format); if (i == n-1) v += "\n"; else if (i > 0 && (i+1) % 3 == 0) v += ",\n"; else v += ", "; @@ -262,12 +264,11 @@ namespace ctml { const doublereal val, const std::string units, const std::string type, const doublereal minval, const doublereal maxval) { - string fmt = "%17.9E"; #ifdef CTML_VERSION_1_4 - XML_Node& f = node.addChild("float", val, fmt); + XML_Node& f = node.addChild("float", val, ctml::FP_Format); f.addAttribute("title", title); #else - XML_Node& f = node.addChild(title, val, fmt); + XML_Node& f = node.addChild(title, val, ctml::FP_Format); #endif if (type != "") f.addAttribute("type",type); if (units != "") f.addAttribute("units",units); @@ -332,11 +333,10 @@ namespace ctml { const doublereal* const vals, const std::string units, const std::string type, const doublereal minval, const doublereal maxval) { - std::string fmt = "%17.9E"; int i; std::string v = ""; for (i = 0; i < n; i++) { - v += fp2str(vals[i],fmt); + v += fp2str(vals[i],FP_Format); if (i == n-1) v += "\n"; else if (i > 0 && (i+1) % 3 == 0) v += ",\n"; else v += ", "; @@ -406,11 +406,10 @@ namespace ctml { const doublereal* const vals, const std::string units, const std::string type, const doublereal minval, const doublereal maxval) { - std::string fmt = "%17.9E"; int i; std::string v = ""; for (i = 0; i < n; i++) { - v += fp2str(vals[i],fmt); + v += fp2str(vals[i],FP_Format); if (i == n-1) v += "\n"; else if (i > 0 && (i+1) % 3 == 0) v += ",\n"; else v += ", "; diff --git a/Cantera/src/base/ctml.h b/Cantera/src/base/ctml.h index 434e5fa02..6199a3e3d 100644 --- a/Cantera/src/base/ctml.h +++ b/Cantera/src/base/ctml.h @@ -33,6 +33,10 @@ namespace ctml { */ const std::string CTML_Version = "1.4.1"; + extern std::string FP_Format; + + extern std::string INT_Format; + //! This function adds a child node with the name, "bool", with a value //! consisting of a single bool /*! diff --git a/Cantera/src/base/xml.cpp b/Cantera/src/base/xml.cpp index 0db1dc8f3..2fd3ea015 100644 --- a/Cantera/src/base/xml.cpp +++ b/Cantera/src/base/xml.cpp @@ -1437,7 +1437,7 @@ namespace Cantera { bool doSpace = true; bool doNewLine = false; int ll = static_cast(m_value.size()) - 1; - if (ll > 15) { + if (ll > 25) { doNewLine = true; } if (m_name == "floatArray") {