Loading...
Searching...
No Matches
ensightCaseOptions.C
Go to the documentation of this file.
1/*---------------------------------------------------------------------------*\
2 ========= |
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4 \\ / O peration |
5 \\ / A nd | www.openfoam.com
6 \\/ M anipulation |
7-------------------------------------------------------------------------------
8 Copyright (C) 2016-2023 OpenCFD Ltd.
9-------------------------------------------------------------------------------
10License
11 This file is part of OpenFOAM.
12
13 OpenFOAM is free software: you can redistribute it and/or modify it
14 under the terms of the GNU General Public License as published by
15 the Free Software Foundation, either version 3 of the License, or
16 (at your option) any later version.
17
18 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25
26\*---------------------------------------------------------------------------*/
27
28#include "ensightCase.H"
29#include "dictionary.H"
30
31// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
32
34:
35 format_
36 (
37 // Can only be ASCII or BINARY
38 (fmt == IOstreamOption::streamFormat::ASCII)
39 ? IOstreamOption::streamFormat::ASCII
40 : IOstreamOption::streamFormat::BINARY
41 ),
42 overwrite_(false),
43 nodeValues_(false),
44 separateCloud_(false),
45 timeFormat_(IOstreamOption::floatFormat::scientific),
46 timePrecision_(5),
47 width_(0),
48 mask_(),
49 printf_()
50{
51 width(8); // Fill mask and setup printf-format
52}
53
54
56(
57 const word& formatKeyword,
58 const dictionary& dict,
60)
62 options(IOstreamOption::formatEnum(formatKeyword, dict, fmt))
63{}
64
65
66// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
67
69{
70 // As per word::printf(), but with fixed length
71 char buf[32];
72
73 ::snprintf(buf, 32, printf_.c_str(), static_cast<int>(i));
74 buf[31] = 0;
75
76 // No stripping required
77 return word(buf, false);
78}
79
80
82{
83 // Enforce min/max sanity limits
84 if (n < 1 || n > 31)
85 {
86 return;
87 }
88
89 // Set mask accordingly
90 mask_.resize(n, '*');
91
92 // Appropriate printf format
93 printf_ = "%0" + std::to_string(n) + "d";
94}
95
96
98(
99 const word& key,
101)
102{
103 timeFormat_ = IOstreamOption::floatFormatEnum(key, dict, timeFormat_);
104}
105
106
108(
109 const word& key,
110 const dictionary& dict
111)
112{
113 if (!key.empty())
114 {
115 dict.readIfPresent(key, timePrecision_, keyType::LITERAL);
116 }
117}
118
119
120// ************************************************************************* //
label n
A simple container for options an IOstream can normally have.
static floatFormat floatFormatEnum(const word &fmtName, const floatFormat deflt=floatFormat::general)
Lookup floatFormat enum corresponding to the string (general | fixed | scientific).
streamFormat
Data format (ascii | binary | coherent).
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition dictionary.H:133
IOstreamOption::floatFormat timeFormat() const noexcept
Time format for case file (general/fixed/scientific).
int timePrecision() const noexcept
Time precision for case file.
options(IOstreamOption::streamFormat fmt=IOstreamOption::BINARY)
Construct with the specified format (default is binary).
word padded(const label i) const
Consistent zero-padded integer value.
int width() const noexcept
Return current width of mask and padded.
@ LITERAL
String literal.
Definition keyType.H:82
A class for handling words, derived from Foam::string.
Definition word.H:66
IOstream & scientific(IOstream &io)
Definition IOstream.H:597
dictionary dict