xmgraceSetWriter.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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.
15 
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.
20 
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/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "xmgraceSetWriter.H"
27 #include "coordSet.H"
28 #include "fileName.H"
29 #include "OFstream.H"
30 
31 
32 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
33 
34 template<class Type>
36 :
37  writer<Type>()
38 {}
39 
40 
41 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
42 
43 template<class Type>
45 {}
46 
47 
48 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
49 
50 template<class Type>
52 (
53  const coordSet& points,
54  const wordList& valueSetNames
55 ) const
56 {
57  return this->getBaseName(points, valueSetNames) + ".agr";
58 }
59 
60 
61 template<class Type>
63 (
64  const coordSet& points,
65  const wordList& valueSetNames,
66  const List<const Field<Type>*>& valueSets,
67  Ostream& os
68 ) const
69 {
70  os << "@g0 on" << nl
71  << "@with g0" << nl
72  << "@ title \"" << points.name() << '"' << nl
73  << "@ xaxis label " << '"' << points.axis() << '"' << nl;
74 
75  forAll(valueSets, i)
76  {
77  os << "@ s" << i << " legend " << '"'
78  << valueSetNames[i] << '"' << nl
79  << "@target G0.S" << i << nl;
80 
81  this->writeTable(points, *valueSets[i], os);
82 
83  os << '&' << nl;
84  }
85 }
86 
87 
88 template<class Type>
90 (
91  const bool writeTracks,
92  const PtrList<coordSet>& trackPoints,
93  const wordList& valueSetNames,
94  const List<List<Field<Type> > >& valueSets,
95  Ostream& os
96 ) const
97 {
98  if (valueSets.size() != valueSetNames.size())
99  {
100  FatalErrorIn("gnuplotSetWriter<Type>::write(..)")
101  << "Number of variables:" << valueSetNames.size() << endl
102  << "Number of valueSets:" << valueSets.size()
103  << exit(FatalError);
104  }
105  if (trackPoints.size() > 0)
106  {
107  os << "@g0 on" << nl
108  << "@with g0" << nl
109  << "@ title \"" << trackPoints[0].name() << '"' << nl
110  << "@ xaxis label " << '"' << trackPoints[0].axis() << '"' << nl;
111 
112  // Data index.
113  label sI = 0;
114 
115  forAll(trackPoints, trackI)
116  {
117  forAll(valueSets, i)
118  {
119  os << "@ s" << sI << " legend " << '"'
120  << valueSetNames[i] << "_track" << i << '"' << nl
121  << "@target G0.S" << sI << nl;
122  this->writeTable(trackPoints[trackI], valueSets[i][trackI], os);
123  os << '&' << nl;
124 
125  sI++;
126  }
127  }
128  }
129 }
130 
131 // ************************************************************************* //
label size() const
Return the number of elements in the PtrList.
Definition: PtrListI.H:32
A templated 1D list of pointers to objects of type <T>, where the size of the array is known and used...
Definition: List.H:61
xmgraceSetWriter()
Construct null.
Holds list of sampling positions.
Definition: coordSet.H:49
const word & name() const
Definition: coordSet.H:111
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:76
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
virtual ~xmgraceSetWriter()
Destructor.
fileName getBaseName(const coordSet &, const wordList &) const
Generates filename from coordSet and sampled fields.
Definition: writer.C:62
static const char nl
Definition: Ostream.H:260
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
word axis() const
Definition: coordSet.H:116
#define forAll(list, i)
Definition: UList.H:421
Base class for graphics format writing. Entry points are.
Definition: writer.H:78
Pre-declare SubField and related Field type.
Definition: Field.H:57
#define FatalErrorIn(functionName)
Report an error message using Foam::FatalError.
Definition: error.H:314
error FatalError
virtual fileName getFileName(const coordSet &, const wordList &) const
Generate file name with correct extension.
A class for handling file names.
Definition: fileName.H:69
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
virtual void write(const coordSet &, const wordList &, const List< const Field< Type > * > &, Ostream &) const
General entry point for writing.
void writeTable(const coordSet &, const List< Type > &, Ostream &) const
Writes single-column ascii write. Column 1 is coordSet coordinate,.
Definition: writer.C:99