ENH: RASModel.C: clipping input to log
[OpenFOAM-1.7.x.git] / src / sampling / sampledSet / writers / csv / csvSetWriter.C
blobc0b0b694ed7d94a9788f9c71c366b176e461a319
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2011 OpenCFD Ltd.
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 "csvSetWriter.H"
27 #include "coordSet.H"
28 #include "fileName.H"
29 #include "OFstream.H"
31 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
33 template<class Type>
34 Foam::csvSetWriter<Type>::csvSetWriter()
36     writer<Type>()
40 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
42 template<class Type>
43 Foam::csvSetWriter<Type>::~csvSetWriter()
47 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
49 template<class Type>
50 Foam::fileName Foam::csvSetWriter<Type>::getFileName
52     const coordSet& points,
53     const wordList& valueSetNames
54 ) const
56     return this->getBaseName(points, valueSetNames) + ".csv";
60 template<class Type>
61 void Foam::csvSetWriter<Type>::write
63     const coordSet& points,
64     const wordList& valueSetNames,
65     const List<const Field<Type>*>& valueSets,
66     Ostream& os
67 ) const
69     writeHeader(points,valueSetNames,os);
71     // Collect sets into columns
72     List<const List<Type>*> columns(valueSets.size());
74     forAll(valueSets, i)
75     {
76         columns[i] = valueSets[i];
77     }
79     writeTable(points, columns, os);
83 template<class Type>
84 void Foam::csvSetWriter<Type>::write
86     const bool writeTracks,
87     const PtrList<coordSet>& points,
88     const wordList& valueSetNames,
89     const List<List<Field<Type> > >& valueSets,
90     Ostream& os
91 ) const
93     writeHeader(points[0],valueSetNames,os);
95     if (valueSets.size() != valueSetNames.size())
96     {
97         FatalErrorIn("csvSetWriter<Type>::write(..)")
98             << "Number of variables:" << valueSetNames.size() << endl
99             << "Number of valueSets:" << valueSets.size()
100             << exit(FatalError);
101     }
103     List<const List<Type>*> columns(valueSets.size());
105     forAll(points, trackI)
106     {
107         // Collect sets into columns
108         forAll(valueSets, i)
109         {
110             columns[i] = &valueSets[i][trackI];
111         }
113         writeTable(points[trackI], columns, os);
114         os  << nl << nl;
115     }
119 template<class Type>
120 void Foam::csvSetWriter<Type>::writeSeparator(Ostream& os) const
122     os << token::COMMA;
126 namespace Foam
128     // otherwise compiler complains about specialization
129     template<>
130     void csvSetWriter<scalar>::writeHeader
131     (
132         const coordSet& points,
133         const wordList& valueSetNames,
134         Ostream& os
135     ) const
136     {
137         writeCoordHeader(points, os);
139         forAll(valueSetNames, i)
140         {
141             if (i > 0)
142             {
143                 writeSeparator(os);
144             }
145             os << valueSetNames[i];
146         }
148         os << nl;
149     }
150 } // end namespace
153 template<class Type>
154 void Foam::csvSetWriter<Type>::writeHeader
156     const coordSet& points,
157     const wordList& valueSetNames,
158     Ostream& os
159 ) const
161     writeCoordHeader(points, os);
163     forAll(valueSetNames, i)
164     {
165         for (label j=0; j<Type::nComponents; j++)
166         {
167             if (i>0 || j>0)
168             {
169                 writeSeparator(os);
170             }
171             os << valueSetNames[i] << "_" << j;
172         }
173     }
175     os << nl;
179 template<class Type>
180 void Foam::csvSetWriter<Type>::writeCoordHeader
182     const coordSet& points,
183     Ostream& os
184 ) const
186     if (points.hasVectorAxis())
187     {
188         forAll(points, i)
189         {
190             os << points.axis()[i];
191             writeSeparator(os);
192         }
193     }
194     else
195     {
196         os << points.axis();
197         writeSeparator(os);
198     }
202 // ************************************************************************* //