1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
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
27 \*---------------------------------------------------------------------------*/
29 #include "writeFuns.H"
31 #if defined(__mips) && !defined(__SICORTEX__)
32 #include <standards.h>
33 #include <sys/endian.h>
36 #if defined(LITTLE_ENDIAN) \
37 || defined(_LITTLE_ENDIAN) \
38 || defined(__LITTLE_ENDIAN)
39 # define LITTLEENDIAN 1
40 #elif defined(BIG_ENDIAN) || defined(_BIG_ENDIAN) || defined(__BIG_ENDIAN)
43 # error "Cannot find LITTLE_ENDIAN or BIG_ENDIAN symbol defined."
44 # error "Please add to compilation options"
47 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
49 void Foam::writeFuns::swapWord(label& word32)
51 char* mem = reinterpret_cast<char*>(&word32);
63 void Foam::writeFuns::swapWords(const label nWords, label* words32)
65 for (label i = 0; i < nWords; i++)
72 void Foam::writeFuns::write
76 List<floatScalar>& fField
82 swapWords(fField.size(), reinterpret_cast<label*>(fField.begin()));
87 reinterpret_cast<char*>(fField.begin()),
88 fField.size()*sizeof(float)
97 os << fField[i] << ' ';
99 if (i > 0 && (i % 10) == 0)
109 void Foam::writeFuns::write
113 DynamicList<floatScalar>& fField
116 List<floatScalar>& fld = fField.shrink();
118 write(os, binary, fld);
122 void Foam::writeFuns::write
132 swapWords(elems.size(), reinterpret_cast<label*>(elems.begin()));
136 reinterpret_cast<char*>(elems.begin()),
137 elems.size()*sizeof(label)
146 os << elems[i] << ' ';
148 if (i > 0 && (i % 10) == 0)
158 void Foam::writeFuns::write
162 DynamicList<label>& elems
165 labelList& fld = elems.shrink();
167 write(os, binary, fld);
171 // Store vector in dest.
172 void Foam::writeFuns::insert(const point& pt, DynamicList<floatScalar>& dest)
174 dest.append(float(pt.x()));
175 dest.append(float(pt.y()));
176 dest.append(float(pt.z()));
180 // Store labelList in dest.
181 void Foam::writeFuns::insert(const labelList& source, DynamicList<label>& dest)
185 dest.append(source[i]);
190 // Store scalarField in dest
191 void Foam::writeFuns::insert
193 const List<scalar>& source,
194 DynamicList<floatScalar>& dest
199 dest.append(float(source[i]));
204 // Store scalarField (indexed through map) in dest
205 void Foam::writeFuns::insert
207 const labelList& map,
208 const List<scalar>& source,
209 DynamicList<floatScalar>& dest
214 dest.append(float(source[map[i]]));
219 void Foam::writeFuns::insert
221 const List<point>& source,
222 DynamicList<floatScalar>& dest
227 insert(source[i], dest);
231 void Foam::writeFuns::insert
233 const labelList& map,
234 const List<point>& source,
235 DynamicList<floatScalar>& dest
240 insert(source[map[i]], dest);
245 // ************************************************************************* //