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-2015 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  TableBase<Type>(entryName, dict.subDict(entryName + "Coeffs")),
34  fName_("none")
35 {
36  const dictionary coeffs(dict.subDict(entryName + "Coeffs"));
37  coeffs.lookup("fileName") >> fName_;
38 
39  if (coeffs.found("dimensions"))
40  {
41  coeffs.lookup("dimensions") >> this->dimensions_;
42  }
43 
44  fileName expandedFile(fName_);
45  IFstream is(expandedFile.expand());
46 
47  if (!is.good())
48  {
50  (
51  is
52  ) << "Cannot open file." << exit(FatalIOError);
53  }
54 
55  is >> this->table_;
56 
58 }
59 
60 
61 template<class Type>
63 :
64  TableBase<Type>(tbl),
65  fName_(tbl.fName_)
66 {}
67 
68 
69 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
70 
71 template<class Type>
73 {}
74 
75 
76 // * * * * * * * * * * * * * * IOStream operators * * * * * * * * * * * * * //
77 
78 #include "TableFileIO.C"
79 
80 
81 // ************************************************************************* //
Foam::TableFile
Templated table container data entry where data is read from file.
Definition: TableFile.H:68
TableFile.H
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
Foam::fileName
A class for handling file names.
Definition: fileName.H:69
Foam::TableFile::~TableFile
virtual ~TableFile()
Destructor.
Definition: TableFile.C:72
Foam::IFstream
Input from file stream.
Definition: IFstream.H:81
Foam::TableFile::fName_
fileName fName_
File name for csv table (optional)
Definition: TableFile.H:89
Foam::dictionary::lookup
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:449
Foam::FatalIOError
IOerror FatalIOError
Foam::TableFile::TableFile
TableFile(const word &entryName, const dictionary &dict)
Construct from entry name and Istream.
Definition: TableFile.C:31
Foam::dictionary::found
bool found(const word &, bool recursive=false, bool patternMatch=true) const
Search dictionary for given keyword.
Definition: dictionary.C:304
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::dictionary
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:137
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
Foam::string::expand
string & expand(const bool allowEmpty=false)
Expand initial tildes and all occurences of environment variables.
Definition: string.C:98
Foam::TableBase::check
void check() const
Check the table for size and consistency.
Definition: TableBase.C:186
FatalIOErrorInFunction
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:330
Foam::IOstream::good
bool good() const
Return true if next operation might succeed.
Definition: IOstream.H:333
Foam::TableBase
Base class for table with bounds handling, interpolation and integration.
Definition: TableBase.H:47
TableFileIO.C