From c2b0531081c86472f8c405910f9371083f3f91c2 Mon Sep 17 00:00:00 2001 From: Mark Olesen <Mark.Olesen@Germany> Date: Mon, 19 Dec 2016 00:24:54 +0100 Subject: [PATCH] ENH: only report the architecture information for binary output files - not required for ASCII, and makes normal dictionaries too noisy. STYLE: move archHint to be a file-scope static --- .../db/IOobject/IOobjectWriteHeader.C | 42 +++++++++++-------- 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/src/OpenFOAM/db/IOobject/IOobjectWriteHeader.C b/src/OpenFOAM/db/IOobject/IOobjectWriteHeader.C index 82de72d3d20..51d6f7d853d 100644 --- a/src/OpenFOAM/db/IOobject/IOobjectWriteHeader.C +++ b/src/OpenFOAM/db/IOobject/IOobjectWriteHeader.C @@ -33,26 +33,28 @@ Description #include "label.H" #include "scalar.H" +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +// file-scope +// Hint about machine endian, OpenFOAM label and scalar sizes +static const std::string archHint = +( +#ifdef WM_LITTLE_ENDIAN + "LSB" +#elif defined (WM_BIG_ENDIAN) + "MSB" +#else + "???" +#endif + ";label=" + std::to_string(8*sizeof(Foam::label)) + + ";scalar=" + std::to_string(8*sizeof(Foam::scalar)) +); + + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // bool Foam::IOobject::writeHeader(Ostream& os, const word& type) const { - static std::string archHint; - - // Hint about machine endian, OpenFOAM label and scalar sizes - if (archHint.empty()) - { - #ifdef WM_LITTLE_ENDIAN - archHint.append("LSB;"); - #elif defined (WM_BIG_ENDIAN) - archHint.append("MSB;"); - #endif - archHint.append("label="); - archHint.append(std::to_string(8*sizeof(label))); - archHint.append(";scalar="); - archHint.append(std::to_string(8*sizeof(scalar))); - } - if (!os.good()) { InfoInFunction @@ -66,10 +68,14 @@ bool Foam::IOobject::writeHeader(Ostream& os, const word& type) const << "FoamFile\n{\n" << " version " << os.version() << ";\n" << " format " << os.format() << ";\n" - << " arch " << archHint << ";\n" << " class " << type << ";\n"; - if (note().size()) + if (os.format() == IOstream::BINARY) + { + os << " arch " << archHint << ";\n"; + } + + if (!note().empty()) { os << " note " << note() << ";\n"; } -- GitLab