TableFile.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-2016 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 "TableFile.H"
27 
28 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
29 
30 template<class Type>
32 (
33  const word& entryName,
34  const dictionary& dict
35 )
36 :
37  TableBase<Type>(entryName, dict.subDict(entryName + "Coeffs")),
38  fName_("none")
39 {
40  const dictionary coeffs(dict.subDict(entryName + "Coeffs"));
41  coeffs.lookup("fileName") >> fName_;
42 
43  fileName expandedFile(fName_);
44  IFstream is(expandedFile.expand());
45 
46  if (!is.good())
47  {
49  (
50  is
51  ) << "Cannot open file." << exit(FatalIOError);
52  }
53 
54  is >> this->table_;
55 
57 }
58 
59 
60 template<class Type>
62 :
63  TableBase<Type>(tbl),
64  fName_(tbl.fName_)
65 {}
66 
67 
68 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
69 
70 template<class Type>
72 {}
73 
74 
75 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
76 
77 template<class Type>
79 {
81 
82  os << token::END_STATEMENT << nl
83  << indent << word(this->name() + "Coeffs") << nl
85 
86  // Note: for TableBase write the dictionary entries it needs but not
87  // the values themselves
89 
90  os.writeKeyword("fileName")<< fName_ << token::END_STATEMENT << nl;
91  os << decrIndent << indent << token::END_BLOCK << endl;
92 }
93 
94 
95 // ************************************************************************* //
virtual ~TableFile()
Destructor.
Definition: TableFile.C:71
A class for handling file names.
Definition: fileName.H:69
const word & name() const
Return the name of the entry.
Definition: Function1.C:56
Ostream & indent(Ostream &os)
Indent stream.
Definition: Ostream.H:223
Templated table container data entry where data is read from file.
Definition: TableFile.H:73
virtual void writeEntries(Ostream &os) const
Write keywords only in dictionary format. Used for non-inline.
Definition: TableBase.C:410
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
virtual void writeData(Ostream &os) const
Write in dictionary format.
Definition: TableFile.C:78
const dictionary & subDict(const word &) const
Find and return a sub-dictionary.
Definition: dictionary.C:633
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:253
TableFile(const word &entryName, const dictionary &dict)
Construct from entry name and Istream.
Definition: TableFile.C:32
virtual void writeData(Ostream &os) const
Write in dictionary format.
Definition: Function1.C:121
Base class for table with bounds handling, interpolation and integration.
Definition: TableBase.H:55
A class for handling words, derived from string.
Definition: word.H:59
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
static const char nl
Definition: Ostream.H:262
Input from file stream.
Definition: IFstream.H:81
Ostream & decrIndent(Ostream &os)
Decrement the indent level.
Definition: Ostream.H:237
Ostream & writeKeyword(const keyType &)
Write the keyword followed by an appropriate indentation.
Definition: Ostream.C:54
string & expand(const bool allowEmpty=false)
Expand initial tildes and all occurences of environment variables.
Definition: string.C:95
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:331
Ostream & incrIndent(Ostream &os)
Increment the indent level.
Definition: Ostream.H:230
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:451
IOerror FatalIOError