ensightReadFile.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-2022 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 "ensightReadFile.H"
29
30// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
31
33(
34 const fileName& pathname,
36)
37:
38 IFstream(pathname, fmt)
39{}
40
41
42// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
43
45(
46 char* buf,
47 std::streamsize count
48)
49{
50 stdStream().read(buf, count);
51 return *this;
52}
53
54
56{
58 {
59 auto& iss = stdStream();
60
61 // Binary string is *exactly* 80 characters
62 value.resize(80, '\0');
63 iss.read(&value[0], 80);
64
65 if (!iss)
66 {
67 // Truncated - could also exit here, but no real advantage
68 value.erase(iss.gcount());
69 }
70
71 // Truncate at the first embedded '\0'
72 auto endp = value.find('\0');
73
74 if (endp != std::string::npos)
75 {
76 value.erase(endp);
77 }
78
79 // May have been padded with trailing spaces - remove those
80 endp = value.find_last_not_of(" \t\f\v\n\r");
81
82 if (endp != std::string::npos)
83 {
84 value.erase(endp + 1);
85 }
86 }
87 else
88 {
89 value.clear();
90 while (value.empty() && !eof())
91 {
92 getLine(value);
93 }
94 }
95
96 return *this;
97}
98
99
101{
102 int ivalue;
103
105 {
106 read
107 (
108 reinterpret_cast<char*>(&ivalue),
109 sizeof(ivalue)
110 );
111 }
112 else
113 {
114 stdStream() >> ivalue;
115 }
116
117 value = ivalue;
118 return *this;
119}
120
121
123{
124 float fvalue;
125
127 {
128 read
129 (
130 reinterpret_cast<char*>(&fvalue),
131 sizeof(fvalue)
132 );
133
134 value = fvalue;
135 }
136 else
137 {
138 stdStream() >> value;
139 }
140
141 return *this;
142}
143
144
146{
147 read(key);
148 return *this;
149}
150
151
153{
155 {
156 string buffer;
157 read(buffer);
158 }
159
160 return *this;
161}
162
163
164// ************************************************************************* //
Input from file stream, using an ISstream.
Definition: IFstream.H:57
streamFormat
Data format (ascii | binary)
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:64
virtual bool read()
Re-read model coefficients if they have changed.
Ensight output with specialized read() for strings, integers and floats. Correctly handles binary rea...
Istream & readBinaryHeader()
Read "C Binary" for binary files (eg, geometry/measured)
virtual Istream & readKeyword(string &key)
Read element keyword.
A class for handling file names.
Definition: fileName.H:76
bool read(const char *buf, int32_t &val)
Same as readInt32.
Definition: int32.H:108
word format(conversionProperties.get< word >("format"))