1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | foam-extend: Open Source CFD
4 \\ / O peration | Version: 3.2
5 \\ / A nd | Web: http://www.foam-extend.org
6 \\/ M anipulation | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
9 This file is part of foam-extend.
11 foam-extend is free software: you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by the
13 Free Software Foundation, either version 3 of the License, or (at your
14 option) any later version.
16 foam-extend is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "writeFuns.H"
29 #if defined(__mips) && !defined(__SICORTEX__)
30 #include <standards.h>
31 #include <sys/endian.h>
35 #ifdef __DARWIN_BYTE_ORDER
36 #if __DARWIN_BYTE_ORDER==__DARWIN_BIG_ENDIAN
43 #if defined(LITTLE_ENDIAN) \
44 || defined(_LITTLE_ENDIAN) \
45 || defined(__LITTLE_ENDIAN)
46 # define LITTLEENDIAN 1
47 #elif defined(BIG_ENDIAN) || defined(_BIG_ENDIAN) || defined(__BIG_ENDIAN)
50 # error "Cannot find LITTLE_ENDIAN or BIG_ENDIAN symbol defined."
51 # error "Please add to compilation options"
54 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
56 void Foam::writeFuns::swapWord(label& word32)
58 char* mem = reinterpret_cast<char*>(&word32);
70 void Foam::writeFuns::swapWords(const label nWords, label* words32)
72 for (label i = 0; i < nWords; i++)
79 void Foam::writeFuns::write
83 List<floatScalar>& fField
89 swapWords(fField.size(), reinterpret_cast<label*>(fField.begin()));
93 reinterpret_cast<char*>(fField.begin()),
94 fField.size()*sizeof(float)
103 os << fField[i] << ' ';
105 if (i > 0 && (i % 10) == 0)
115 void Foam::writeFuns::write
119 DynamicList<floatScalar>& fField
122 List<floatScalar>& fld = fField.shrink();
124 write(os, binary, fld);
128 void Foam::writeFuns::write
138 swapWords(elems.size(), reinterpret_cast<label*>(elems.begin()));
142 reinterpret_cast<char*>(elems.begin()),
143 elems.size()*sizeof(label)
152 os << elems[i] << ' ';
154 if (i > 0 && (i % 10) == 0)
164 void Foam::writeFuns::write
168 DynamicList<label>& elems
171 labelList& fld = elems.shrink();
173 write(os, binary, fld);
177 void Foam::writeFuns::writeHeader
184 os << "# vtk DataFile Version 2.0" << std::endl
185 << name << std::endl;
189 os << "BINARY" << std::endl;
193 os << "ASCII" << std::endl;
198 void Foam::writeFuns::writeCellDataHeader
205 os << "CELL_DATA " << nCells << std::endl
206 << "FIELD attributes " << nFields << std::endl;
210 void Foam::writeFuns::writePointDataHeader
217 os << "POINT_DATA " << nPoints << std::endl
218 << "FIELD attributes " << nFields << std::endl;
222 void Foam::writeFuns::insert(const scalar& pt, DynamicList<floatScalar>& dest)
224 dest.append(float(pt));
228 void Foam::writeFuns::insert(const vector& pt, DynamicList<floatScalar>& dest)
230 for (direction cmpt = 0; cmpt < vector::nComponents; cmpt++)
232 dest.append(float(pt[cmpt]));
237 void Foam::writeFuns::insert
239 const sphericalTensor& pt,
240 DynamicList<floatScalar>& dest
243 for (direction cmpt = 0; cmpt < sphericalTensor::nComponents; cmpt++)
245 dest.append(float(pt[cmpt]));
250 void Foam::writeFuns::insert
252 const symmTensor& pt,
253 DynamicList<floatScalar>& dest
256 for (direction cmpt = 0; cmpt < symmTensor::nComponents; cmpt++)
258 dest.append(float(pt[cmpt]));
263 void Foam::writeFuns::insert(const tensor& pt, DynamicList<floatScalar>& dest)
265 for (direction cmpt = 0; cmpt < tensor::nComponents; cmpt++)
267 dest.append(float(pt[cmpt]));
272 void Foam::writeFuns::insert(const labelList& source, DynamicList<label>& dest)
276 dest.append(source[i]);
281 // ************************************************************************* //