From 19c03e4dd044ad47e2d03e45c4da74f889d556a3 Mon Sep 17 00:00:00 2001 From: Henry Weller Date: Tue, 5 Nov 2019 15:19:03 +0000 Subject: [PATCH] sampling::probes: Improved the output table format to be more consistent with logFiles Columns are now fixed width, left justified and the column headings are on one line. Resolves bug-report https://bugs.openfoam.org/view.php?id=3378#c10866 --- src/sampling/probes/probes.C | 22 +++++++++------------- src/sampling/probes/probesTemplates.C | 16 ++++++++++------ 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/sampling/probes/probes.C b/src/sampling/probes/probes.C index 589c3e8b4e..f69e4faae2 100644 --- a/src/sampling/probes/probes.C +++ b/src/sampling/probes/probes.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -239,35 +239,31 @@ Foam::label Foam::probes::prepare() mkDir(probeDir); OFstream* fPtr = new OFstream(probeDir/fieldName); - - OFstream& fout = *fPtr; + OFstream& os = *fPtr; if (debug) { - Info<< "open probe stream: " << fout.name() << endl; + Info<< "open probe stream: " << os.name() << endl; } probeFilePtrs_.insert(fieldName, fPtr); - unsigned int w = IOstream::defaultPrecision() + 7; + const unsigned int w = IOstream::defaultPrecision() + 7; + os << setf(ios_base::left); forAll(*this, probei) { - fout<< "# Probe " << probei << ' ' << operator[](probei) + os<< "# Probe " << probei << ' ' << operator[](probei) << endl; } - fout<< '#' << setw(IOstream::defaultPrecision() + 6) - << "Probe"; + os << setw(w) << "# Time"; forAll(*this, probei) { - fout<< ' ' << setw(w) << probei; + os<< ' ' << setw(w) << probei; } - fout<< endl; - - fout<< '#' << setw(IOstream::defaultPrecision() + 6) - << "Time" << endl; + os<< endl; } } diff --git a/src/sampling/probes/probesTemplates.C b/src/sampling/probes/probesTemplates.C index 5a9b289480..396a27a780 100644 --- a/src/sampling/probes/probesTemplates.C +++ b/src/sampling/probes/probesTemplates.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -73,14 +73,16 @@ void Foam::probes::sampleAndWrite if (Pstream::master()) { - unsigned int w = IOstream::defaultPrecision() + 7; + const unsigned int w = IOstream::defaultPrecision() + 7; OFstream& os = *probeFilePtrs_[vField.name()]; os << setw(w) << vField.time().timeToUserTime(vField.time().value()); forAll(values, probei) { - os << ' ' << setw(w) << values[probei]; + OStringStream buf; + buf << values[probei]; + os << ' ' << setw(w) << buf.str().c_str(); } os << endl; } @@ -97,14 +99,16 @@ void Foam::probes::sampleAndWrite if (Pstream::master()) { - unsigned int w = IOstream::defaultPrecision() + 7; + const unsigned int w = IOstream::defaultPrecision() + 7; OFstream& os = *probeFilePtrs_[sField.name()]; - os << setw(w) << sField.time().timeToUserTime(sField.time().value()); + os << sField.time().timeToUserTime(sField.time().value()); forAll(values, probei) { - os << ' ' << setw(w) << values[probei]; + OStringStream buf; + buf << values[probei]; + os << ' ' << setw(w) << buf.str().c_str(); } os << endl; }