BUGFIX: Illegal use of uninitialised value (backport)
[foam-extend-3.2.git] / applications / utilities / postProcessing / dataConversion / foamToEnsight / ensightCloudField.C
blobc9a662c6fce801bad775fc668871c2fc86407599
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright held by original author
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 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
19     for more details.
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 "ensightCloudField.H"
28 #include "Time.H"
29 #include "IOField.H"
30 #include "OFstream.H"
31 #include "IOmanip.H"
33 using namespace Foam;
35 // * * * * * * * * * * * * * * * Global Functions  * * * * * * * * * * * * * //
37 template<class Type>
38 void ensightCloudField
40     const Foam::IOobject& fieldObject,
41     const Foam::fileName& postProcPath,
42     const Foam::word& prepend,
43     const Foam::label timeIndex,
44     const Foam::word& cloudName,
45     Foam::Ostream& ensightCaseFile,
46     const bool dataExists
49     if (dataExists)
50     {
51         Info<< "Converting cloud " << cloudName
52             << " field " << fieldObject.name() << endl;
53     }
54     else
55     {
56         Info<< "Creating empty cloud " << cloudName
57             << " field "  << fieldObject.name() << endl;
58     }
60     word timeFile = prepend + itoa(timeIndex);
62     const Time& runTime = fieldObject.time();
64     if (timeIndex == 0 && Pstream::master())
65     {
66         ensightCaseFile
67             << pTraits<Type>::typeName << " per measured node:      1       ";
68         ensightCaseFile.width(15);
69         ensightCaseFile.setf(ios_base::left);
70         ensightCaseFile
71             << ("c" + fieldObject.name()).c_str()
72             << (' ' + prepend + "***." + cloudName
73               + "." + fieldObject.name()).c_str()
74             << nl;
75     }
77     fileName ensightFileName
78     (
79         timeFile + "." + cloudName +"." + fieldObject.name()
80     );
82     OFstream ensightFile
83     (
84         postProcPath/ensightFileName,
85         ios_base::out|ios_base::trunc,
86         runTime.writeFormat(),
87         runTime.writeVersion(),
88         runTime.writeCompression()
89     );
91     ensightFile<< pTraits<Type>::typeName << " values" << nl;
93     if (dataExists)
94     {
95         IOField<Type> vf(fieldObject);
97         ensightFile.setf(ios_base::scientific, ios_base::floatfield);
98         ensightFile.precision(5);
100         label count = 0;
101         forAll(vf, i)
102         {
103             Type v = vf[i];
105             if (mag(v) < 1.0e-90)
106             {
107                 v = pTraits<Type>::zero;
108             }
110             for (direction cmpt=0; cmpt<pTraits<Type>::nComponents; cmpt++)
111             {
112                 ensightFile << setw(12) << component(v, cmpt);
113                 if (++count % 6 == 0)
114                 {
115                     ensightFile << nl;
116                 }
117             }
118         }
120         if ((count % 6 != 0) || (count==0))
121         {
122             ensightFile << nl;
123         }
124     }
128 // ************************************************************************* //