1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright held by original author
7 -------------------------------------------------------------------------------
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 the
13 Free Software Foundation; either version 2 of the License, or (at your
14 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
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM; if not, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
27 #include "writeFuns.H"
30 #if defined(__mips) && !defined(__SICORTEX__)
31 #include <standards.h>
32 #include <sys/endian.h>
36 #ifdef __DARWIN_BYTE_ORDER
37 #if __DARWIN_BYTE_ORDER==__DARWIN_BIG_ENDIAN
44 #if defined(LITTLE_ENDIAN) \
45 || defined(_LITTLE_ENDIAN) \
46 || defined(__LITTLE_ENDIAN)
47 # define LITTLEENDIAN 1
48 #elif defined(BIG_ENDIAN) || defined(_BIG_ENDIAN) || defined(__BIG_ENDIAN)
51 # error "Cannot find LITTLE_ENDIAN or BIG_ENDIAN symbol defined."
52 # error "Please add to compilation options"
55 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
57 void Foam::writeFuns::swapWord(label& word32)
59 char* mem = reinterpret_cast<char*>(&word32);
71 void Foam::writeFuns::swapWords(const label nWords, label* words32)
73 for (label i = 0; i < nWords; i++)
80 void Foam::writeFuns::write
84 List<floatScalar>& fField
90 swapWords(fField.size(), reinterpret_cast<label*>(fField.begin()));
94 reinterpret_cast<char*>(fField.begin()),
95 fField.size()*sizeof(float)
104 os << fField[i] << ' ';
106 if (i > 0 && (i % 10) == 0)
116 void Foam::writeFuns::write
120 DynamicList<floatScalar>& fField
123 List<floatScalar>& fld = fField.shrink();
125 write(os, binary, fld);
129 void Foam::writeFuns::write
139 swapWords(elems.size(), reinterpret_cast<label*>(elems.begin()));
143 reinterpret_cast<char*>(elems.begin()),
144 elems.size()*sizeof(label)
153 os << elems[i] << ' ';
155 if (i > 0 && (i % 10) == 0)
165 void Foam::writeFuns::write
169 DynamicList<label>& elems
172 labelList& fld = elems.shrink();
174 write(os, binary, fld);
178 void Foam::writeFuns::writeHeader
185 os << "# vtk DataFile Version 2.0" << std::endl
186 << name << std::endl;
190 os << "BINARY" << std::endl;
194 os << "ASCII" << std::endl;
199 void Foam::writeFuns::writeCellDataHeader
206 os << "CELL_DATA " << nCells << std::endl
207 << "FIELD attributes " << nFields << std::endl;
211 void Foam::writeFuns::writePointDataHeader
218 os << "POINT_DATA " << nPoints << std::endl
219 << "FIELD attributes " << nFields << std::endl;
223 void Foam::writeFuns::insert(const scalar& pt, DynamicList<floatScalar>& dest)
225 dest.append(float(pt));
229 void Foam::writeFuns::insert(const vector& pt, DynamicList<floatScalar>& dest)
231 for (direction cmpt = 0; cmpt < vector::nComponents; cmpt++)
233 dest.append(float(pt[cmpt]));
238 void Foam::writeFuns::insert
240 const sphericalTensor& pt,
241 DynamicList<floatScalar>& dest
244 for (direction cmpt = 0; cmpt < sphericalTensor::nComponents; cmpt++)
246 dest.append(float(pt[cmpt]));
251 void Foam::writeFuns::insert
253 const symmTensor& pt,
254 DynamicList<floatScalar>& dest
257 for (direction cmpt = 0; cmpt < symmTensor::nComponents; cmpt++)
259 dest.append(float(pt[cmpt]));
264 void Foam::writeFuns::insert(const tensor& pt, DynamicList<floatScalar>& dest)
266 for (direction cmpt = 0; cmpt < tensor::nComponents; cmpt++)
268 dest.append(float(pt[cmpt]));
273 void Foam::writeFuns::insert(const labelList& source, DynamicList<label>& dest)
277 dest.append(source[i]);
282 // ************************************************************************* //