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 \*---------------------------------------------------------------------------*/
30 #include <OpenFOAM/OFstream.H>
31 #include <OpenFOAM/IOmanip.H>
32 #include <OpenFOAM/Pair.H>
34 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
39 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
41 defineTypeNameAndDebug(graph::writer, 0);
42 defineRunTimeSelectionTable(graph::writer, word);
44 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
46 void graph::readCurves(Istream& is)
50 x_.setSize(xyData.size());
51 scalarField y(xyData.size());
59 insert(yName_, new curve(yName_, curve::curveStyle::CONTINUOUS, y));
63 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
94 insert(yName, new curve(yName, curve::curveStyle::CONTINUOUS, y));
114 graph::graph(Istream& is)
124 const scalarField& graph::y() const
128 FatalErrorIn("const scalarField& graph::y() const")
129 << "y field requested for graph containing " << size()
130 << "ys" << exit(FatalError);
136 scalarField& graph::y()
140 FatalErrorIn("scalarField& graph::y()")
141 << "y field requested for graph containing " << size()
142 << "ys" << exit(FatalError);
149 autoPtr<graph::writer> graph::writer::New(const word& graphFormat)
151 if (!wordConstructorTablePtr_)
155 "graph::writer::New(const word&)"
156 ) << "Graph writer table is empty"
160 wordConstructorTable::iterator cstrIter =
161 wordConstructorTablePtr_->find(graphFormat);
163 if (cstrIter == wordConstructorTablePtr_->end())
167 "graph::writer::New(const word&)"
168 ) << "Unknown graph format " << graphFormat
170 << "Valid graph formats are : " << endl
171 << wordConstructorTablePtr_->toc()
175 return autoPtr<graph::writer>(cstrIter()());
179 void graph::writer::writeXY
181 const scalarField& x,
182 const scalarField& y,
188 os << setw(10) << x[xi] << token::SPACE << setw(10) << y[xi]<< endl;
193 void graph::writeTable(Ostream& os) const
197 os << setw(10) << x_[xi];
201 graph::const_iterator iter = begin();
206 os << token::SPACE << setw(10) << (*iter())[xi];
213 void graph::write(Ostream& os, const word& format) const
215 writer::New(format)().write(*this, os);
219 void graph::write(const fileName& fName, const word& format) const
221 autoPtr<writer> graphWriter(writer::New(format));
223 OFstream graphFile(fName + '.' + graphWriter().ext());
225 if (graphFile.good())
227 write(graphFile, format);
231 WarningIn("graph::write(const word& format, const fileName& dir)")
232 << "Could not open graph file " << graphFile.name()
238 Ostream& operator<<(Ostream& os, const graph& g)
241 os.check("Ostream& operator<<(Ostream&, const graph&)");
246 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
248 } // End namespace Foam
250 // ************************ vim: set sw=4 sts=4 et: ************************ //