BUG: UListIO: byteSize overflowing on really big faceLists
[OpenFOAM-2.0.x.git] / applications / utilities / mesh / manipulation / setSet / writeFuns.C
blobeb974ab2a9b3564ab6ae053433bf1e08e881c651
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 "writeFuns.H"
28 #if defined(__mips) && !defined(__SICORTEX__)
29 #include <standards.h>
30 #include <sys/endian.h>
31 #endif
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)
38 #   undef LITTLEENDIAN
39 #else
40 #   error "Cannot find LITTLE_ENDIAN or BIG_ENDIAN symbol defined."
41 #   error "Please add to compilation options"
42 #endif
44 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
46 void Foam::writeFuns::swapWord(label& word32)
48     char* mem =  reinterpret_cast<char*>(&word32);
50     char a = mem[0];
51     mem[0] = mem[3];
52     mem[3] = a;
54     a = mem[1];
55     mem[1] = mem[2];
56     mem[2] = a;
60 void Foam::writeFuns::swapWords(const label nWords, label* words32)
62     for (label i = 0; i < nWords; i++)
63     {
64         swapWord(words32[i]);
65     }
69 void Foam::writeFuns::write
71     std::ostream& os,
72     const bool binary,
73     List<floatScalar>& fField
76     if (binary)
77     {
78 #       ifdef LITTLEENDIAN
79         swapWords(fField.size(),  reinterpret_cast<label*>(fField.begin()));
80 #       endif
82         os.write
83         (
84             reinterpret_cast<char*>(fField.begin()),
85             fField.size()*sizeof(float)
86         );
88         os  << std::endl;
89     }
90     else
91     {
92         forAll(fField, i)
93         {
94             os  << fField[i] << ' ';
96             if (i > 0 && (i % 10) == 0)
97             {
98                 os  << std::endl;
99             }
100         }
101         os  << std::endl;
102     }
106 void Foam::writeFuns::write
108     std::ostream& os,
109     const bool binary,
110     DynamicList<floatScalar>& fField
113     List<floatScalar>& fld = fField.shrink();
115     write(os, binary, fld);
119 void Foam::writeFuns::write
121     std::ostream& os,
122     const bool binary,
123     labelList& elems
126     if (binary)
127     {
128 #       ifdef LITTLEENDIAN
129         swapWords(elems.size(),  reinterpret_cast<label*>(elems.begin()));
130 #       endif
131         os.write
132         (
133             reinterpret_cast<char*>(elems.begin()),
134             elems.size()*sizeof(label)
135         );
137         os  << std::endl;
138     }
139     else
140     {
141         forAll(elems, i)
142         {
143             os  << elems[i] << ' ';
145             if (i > 0 && (i % 10) == 0)
146             {
147                 os  << std::endl;
148             }
149         }
150         os  << std::endl;
151     }
155 void Foam::writeFuns::write
157     std::ostream& os,
158     const bool binary,
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)
180     forAll(source, i)
181     {
182         dest.append(source[i]);
183     }
187 // Store scalarField in dest
188 void Foam::writeFuns::insert
190     const List<scalar>& source,
191     DynamicList<floatScalar>& dest
194     forAll(source, i)
195     {
196         dest.append(float(source[i]));
197     }
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
209     forAll(map, i)
210     {
211         dest.append(float(source[map[i]]));
212     }
216 void Foam::writeFuns::insert
218     const List<point>& source,
219     DynamicList<floatScalar>& dest
222     forAll(source, i)
223     {
224        insert(source[i], dest);
225     }
228 void Foam::writeFuns::insert
230     const labelList& map,
231     const List<point>& source,
232     DynamicList<floatScalar>& dest
235     forAll(map, i)
236     {
237        insert(source[map[i]], dest);
238     }
242 // ************************************************************************* //