foamInfoExec.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 Application
25  foamInfoExec
26 
27 Description
28  Interrogates a case and prints information to stdout.
29 
30 \*---------------------------------------------------------------------------*/
31 
32 #include "argList.H"
33 #include "Time.H"
34 #include "dictionary.H"
35 #include "IFstream.H"
36 
37 using namespace Foam;
38 
39 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
40 
41 int main(int argc, char *argv[])
42 {
44  (
45  "interrogates a case and prints information to stdout"
46  );
47 
49  argList::addBoolOption("times", "list available times");
50  argList::addBoolOption("latestTime", "list last time");
52  (
53  "keywords",
54  "report keywords for the specified dictionary"
55  );
56  #include "addDictOption.H"
58  (
59  "entry",
60  "name",
61  "report the named entry for the specified dictionary"
62  );
63 
64  #include "setRootCase.H"
65 
66  if (args.optionFound("times"))
67  {
68  instantList times
69  (
71  );
72 
73  forAll(times, i)
74  {
75  Info<< times[i].name() << endl;
76  }
77  }
78  else if (args.optionFound("latestTime"))
79  {
80  instantList times
81  (
83  );
84 
85  Info<< times.last().name() << endl;
86  }
87 
88  if (args.optionFound("dict"))
89  {
90  fileName dictPath = args["dict"];
91  const fileName dictFileName
92  (
94  ? dictPath
95  : args.rootPath()/args.caseName()/args["dict"]
96  );
97 
98  IFstream dictFile(dictFileName);
99 
100  if (dictFile.good())
101  {
102  dictionary dict(dictFile);
103 
104  if (args.optionFound("entry"))
105  {
106  fileName entryName(args.option("entry"));
107 
108  const entry* entPtr = NULL;
109 
110  if (entryName.find('.') != string::npos)
111  {
112  // New syntax
113  entPtr = dict.lookupScopedEntryPtr
114  (
115  entryName,
116  false,
117  true // wildcards
118  );
119  }
120  else
121  {
122  // Old syntax
123  wordList entryNames(entryName.components(':'));
124  if (dict.found(entryNames[0]))
125  {
126  entPtr = &dict.lookupEntry
127  (
128  entryNames[0],
129  false,
130  true // wildcards
131  );
132 
133  for (int i=1; i<entryNames.size(); ++i)
134  {
135  if (entPtr->dict().found(entryNames[i]))
136  {
137  entPtr = &entPtr->dict().lookupEntry
138  (
139  entryNames[i],
140  false,
141  true // wildcards
142  );
143  }
144  else
145  {
147  << "Cannot find sub-entry " << entryNames[i]
148  << " in entry " << args["entry"]
149  << " in dictionary " << dictFileName;
150  FatalError.exit(3);
151  }
152  }
153  }
154  }
155 
156 
157  if (entPtr)
158  {
159  if (args.optionFound("keywords"))
160  {
161  /*
162  if (ent[1] != token::BEGIN_BLOCK)
163  {
164  FatalErrorInFunction
165  << "Cannot find entry "
166  << args["entry"]
167  << " in dictionary " << dictFileName
168  << " is not a sub-dictionary";
169  FatalError.exit(4);
170  }
171  */
172 
173  const dictionary& dict = entPtr->dict();
175  {
176  Info<< iter().keyword() << endl;
177  }
178  }
179  else
180  {
181  Info<< *entPtr << endl;
182  }
183  }
184  else
185  {
187  << "Cannot find entry "
188  << entryName
189  << " in dictionary " << dictFileName;
190  FatalError.exit(2);
191  }
192  }
193  else if (args.optionFound("keywords"))
194  {
196  {
197  Info<< iter().keyword() << endl;
198  }
199  }
200  else
201  {
202  Info<< dict;
203  }
204  }
205  else
206  {
208  << "Cannot open file " << dictFileName;
209  FatalError.exit(1);
210  }
211  }
212 
213  return 0;
214 }
215 
216 
217 // ************************************************************************* //
Foam::argList::noBanner
static void noBanner()
Disable emitting the banner information.
Definition: argList.C:155
Foam::entry
A keyword and a list of tokens is an 'entry'.
Definition: entry.H:65
Foam::dictionary::lookupEntry
const entry & lookupEntry(const word &, bool recursive, bool patternMatch) const
Find and return an entry data stream if present otherwise error.
Definition: dictionary.C:426
Foam::fileName
A class for handling file names.
Definition: fileName.H:69
Foam::argList::addOption
static void addOption(const word &opt, const string &param="", const string &usage="")
Add to an option to validOptions with usage information.
Definition: argList.C:108
Foam::argList::addNote
static void addNote(const string &)
Add extra notes for the usage information.
Definition: argList.C:139
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::IFstream
Input from file stream.
Definition: IFstream.H:81
Foam::argList::addBoolOption
static void addBoolOption(const word &opt, const string &usage="")
Add to a bool option to validOptions with usage information.
Definition: argList.C:98
Foam::fileName::isAbsolute
bool isAbsolute() const
Return true if file name is absolute.
Definition: fileName.C:57
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::argList::rootPath
const fileName & rootPath() const
Return root path.
Definition: argListI.H:36
forAllConstIter
forAllConstIter(PtrDictionary< phaseModel >, mixture.phases(), phase)
Definition: pEqn.H:39
addDictOption.H
Foam::dictionary::found
bool found(const word &, bool recursive=false, bool patternMatch=true) const
Search dictionary for given keyword.
Definition: dictionary.C:304
Foam::Info
messageStream Info
argList.H
main
int main(int argc, char *argv[])
Definition: postCalc.C:54
IFstream.H
Foam::argList::option
const string & option(const word &opt) const
Return the argument string associated with the named option.
Definition: argListI.H:102
Foam::dictionary::lookupScopedEntryPtr
const entry * lookupScopedEntryPtr(const word &, bool recursive, bool patternMatch) const
Find and return an entry data stream pointer if present.
Definition: dictionary.C:460
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::FatalError
error FatalError
Foam::dictionary
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:137
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::error::exit
void exit(const int errNo=1)
Exit : can be called for any error to exit program.
Definition: error.C:165
Foam::entry::dict
virtual const dictionary & dict() const =0
Return dictionary if this entry is a dictionary.
setRootCase.H
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:318
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
Foam::Time::findTimes
static instantList findTimes(const fileName &, const word &constantName="constant")
Search a given directory for valid time directories.
Definition: findTimes.C:38
dictionary.H
Foam::argList::optionFound
bool optionFound(const word &opt) const
Return true if the named option is found.
Definition: argListI.H:108
Foam::argList::caseName
const fileName & caseName() const
Return case name (parallel run) or global case (serial run)
Definition: argListI.H:42
args
Foam::argList args(argc, argv)
dictPath
fileName dictPath
Definition: setConstantMeshDictionaryIO.H:5