1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
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
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
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 "writeFuns.H"
28 #if defined(__mips) && !defined(__SICORTEX__)
29 #include <standards.h>
30 #include <sys/endian.h>
33 #if defined(LITTLE_ENDIAN) \
34 || defined(_LITTLE_ENDIAN) \
35 || defined(__LITTLE_ENDIAN)
36 # define LITTLEENDIAN 1
37 #elif defined(BIG_ENDIAN) || defined(_BIG_ENDIAN) || defined(__BIG_ENDIAN)
40 # error "Cannot find LITTLE_ENDIAN or BIG_ENDIAN symbol defined."
41 # error "Please add to compilation options"
44 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
46 void Foam::writeFuns::swapWord(label& word32)
48 char* mem = reinterpret_cast<char*>(&word32);
60 void Foam::writeFuns::swapWords(const label nWords, label* words32)
62 for (label i = 0; i < nWords; i++)
69 void Foam::writeFuns::write
73 List<floatScalar>& fField
79 swapWords(fField.size(), reinterpret_cast<label*>(fField.begin()));
84 reinterpret_cast<char*>(fField.begin()),
85 fField.size()*sizeof(float)
94 os << fField[i] << ' ';
96 if (i > 0 && (i % 10) == 0)
106 void Foam::writeFuns::write
110 DynamicList<floatScalar>& fField
113 List<floatScalar>& fld = fField.shrink();
115 write(os, binary, fld);
119 void Foam::writeFuns::write
129 swapWords(elems.size(), reinterpret_cast<label*>(elems.begin()));
133 reinterpret_cast<char*>(elems.begin()),
134 elems.size()*sizeof(label)
143 os << elems[i] << ' ';
145 if (i > 0 && (i % 10) == 0)
155 void Foam::writeFuns::write
159 DynamicList<label>& elems
162 labelList& fld = elems.shrink();
164 write(os, binary, fld);
168 // Store vector in dest.
169 void Foam::writeFuns::insert(const point& pt, DynamicList<floatScalar>& dest)
171 dest.append(float(pt.x()));
172 dest.append(float(pt.y()));
173 dest.append(float(pt.z()));
177 // Store labelList in dest.
178 void Foam::writeFuns::insert(const labelList& source, DynamicList<label>& dest)
182 dest.append(source[i]);
187 // Store scalarField in dest
188 void Foam::writeFuns::insert
190 const List<scalar>& source,
191 DynamicList<floatScalar>& dest
196 dest.append(float(source[i]));
201 // Store scalarField (indexed through map) in dest
202 void Foam::writeFuns::insert
204 const labelList& map,
205 const List<scalar>& source,
206 DynamicList<floatScalar>& dest
211 dest.append(float(source[map[i]]));
216 void Foam::writeFuns::insert
218 const List<point>& source,
219 DynamicList<floatScalar>& dest
224 insert(source[i], dest);
228 void Foam::writeFuns::insert
230 const labelList& map,
231 const List<point>& source,
232 DynamicList<floatScalar>& dest
237 insert(source[map[i]], dest);
242 // ************************************************************************* //