ENH: autoLayerDriver: better layering information message
[OpenFOAM-2.0.x.git] / src / conversion / ensight / file / ensightFile.C
blob7748a236f26234af01cec5b604a39f279f25cda7
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
11     OpenFOAM is free software: you can redistribute it and/or modify it
12     under the terms of the GNU General Public License as published by
13     the Free Software Foundation, either version 3 of the License, or
14     (at your option) any later version.
16     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
19     for more details.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "ensightFile.H"
28 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
30 bool Foam::ensightFile::allowUndef_ = false;
32 Foam::scalar Foam::ensightFile::undefValue_ = Foam::floatScalarVGREAT;
34 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
36 Foam::ensightFile::ensightFile
38     const fileName& pathname,
39     IOstream::streamFormat format
42     OFstream(pathname, format)
44     // ascii formatting specs
45     setf
46     (
47         ios_base::scientific,
48         ios_base::floatfield
49     );
50     precision(5);
54 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
56 Foam::ensightFile::~ensightFile()
60 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
62 bool Foam::ensightFile::allowUndef()
64     return allowUndef_;
68 bool Foam::ensightFile::allowUndef(bool value)
70     bool old = allowUndef_;
71     allowUndef_ = value;
72     return old;
76 Foam::scalar Foam::ensightFile::undefValue(const scalar value)
78     // enable its use too
79     allowUndef_ = true;
81     scalar old = undefValue_;
82     undefValue_ = value;
83     return old;
87 Foam::Ostream& Foam::ensightFile::write
89     const char* buf,
90     std::streamsize count
93     stdStream().write(buf, count);
94     return *this;
98 Foam::Ostream& Foam::ensightFile::write(const string& value)
100     char buf[80];
102     for (string::size_type i = 0; i < 80; ++i)
103     {
104         buf[i] = 0;
105     }
107     string::size_type n = value.size();
108     if (n >= 80)
109     {
110         n = 79;
111     }
113     for (string::size_type i = 0; i < n; ++i)
114     {
115         buf[i] = value[i];
116     }
118     if (format() == IOstream::BINARY)
119     {
120         write
121         (
122             reinterpret_cast<char const *>(buf),
123             sizeof(buf)
124         );
125     }
126     else
127     {
128         stdStream() << buf;
129     }
131     return *this;
135 Foam::Ostream& Foam::ensightFile::write(const label value)
137     if (format() == IOstream::BINARY)
138     {
139         unsigned int ivalue(value);
141         write
142         (
143             reinterpret_cast<char const *>(&ivalue),
144             sizeof(ivalue)
145         );
146     }
147     else
148     {
149         stdStream().width(10);
150         stdStream() << value;
151     }
153     return *this;
157 Foam::Ostream& Foam::ensightFile::write
159     const label value,
160     const label fieldWidth
163     if (format() == IOstream::BINARY)
164     {
165         unsigned int ivalue(value);
167         write
168         (
169             reinterpret_cast<char const *>(&ivalue),
170             sizeof(ivalue)
171         );
172     }
173     else
174     {
175         stdStream().width(fieldWidth);
176         stdStream() << value;
177     }
179     return *this;
183 Foam::Ostream& Foam::ensightFile::write(const scalar value)
185     if (format() == IOstream::BINARY)
186     {
187         float fvalue(value);
189         write
190         (
191             reinterpret_cast<char const *>(&fvalue),
192             sizeof(fvalue)
193         );
194     }
195     else
196     {
197         stdStream().width(12);
198         stdStream() << value;
199     }
201     return *this;
205 void Foam::ensightFile::newline()
207     if (format() == IOstream::ASCII)
208     {
209         stdStream() << nl;
210     }
214 Foam::Ostream& Foam::ensightFile::writeUndef()
216     write(undefValue_);
217     return *this;
221 Foam::Ostream& Foam::ensightFile::writeKeyword(const string& key)
223     if (allowUndef_)
224     {
225         write(key + " undef");
226         newline();
227         write(undefValue_);
228         newline();
229     }
230     else
231     {
232         write(key);
233         newline();
234     }
235     return *this;
239 Foam::Ostream& Foam::ensightFile::writeBinaryHeader()
241     if (format() == IOstream::BINARY)
242     {
243         write("C Binary");
244     }
246     return *this;
250 // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
252 Foam::string Foam::ensightFile::mask()
254     char buf[16] = "********";
255     return buf;
259 Foam::string Foam::ensightFile::subDir(const label n)
261     char buf[16];
263     sprintf(buf, "%08d", n);
264     return buf;
268 // ************************************************************************* //