From 7acef189cf21b09f379d93d45198a417b4def74d Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Sun, 18 Dec 2016 01:43:58 +0100 Subject: [PATCH] ENH: provide machine/OpenFOAM architecture hint in output files (issue #271) FoamFile { version 2.0; format binary; arch "LSB;label=32;scalar=64"; class vectorField; object points; } There is otherwise no simple indication in any of the files as to the sizes used (Int32 vs Int64, SP vs DP). This makes it difficult for the end-user and also for any third-party consumers. -- The architecture information contains three items in the following format: (LSB|MSB);label=(32|64);scalar=(32|64) - The endian value always appears first, without any leading space. This make it trivial to check later. Either the first 3 letters (LSB vs MSB) or even just the first letter ('L' vs 'M'). - Subsequent key=value pairs for 'label' and 'scalar' are separated by semicolons. The ordering of label vs scalar is not specified. Note that this 'arch' information is purely informational. It is currently not used by the OpenFOAM input mechanism itself. --- .../db/IOobject/IOobjectWriteHeader.C | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/OpenFOAM/db/IOobject/IOobjectWriteHeader.C b/src/OpenFOAM/db/IOobject/IOobjectWriteHeader.C index bb19caf668..82de72d3d2 100644 --- a/src/OpenFOAM/db/IOobject/IOobjectWriteHeader.C +++ b/src/OpenFOAM/db/IOobject/IOobjectWriteHeader.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -29,11 +29,30 @@ Description #include "IOobject.H" #include "objectRegistry.H" +#include "endian.H" +#include "label.H" +#include "scalar.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 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 @@ -47,6 +66,7 @@ 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())