FreeFOAM The Cross-Platform CFD Toolkit
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) 1991-2010 OpenCFD Ltd.
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 screen
29 
30 Usage
31 
32  - foamInfoExec [OPTIONS]
33 
34  @param -dictionary <dictionary name>\n
35  Use specified dictionary.
36 
37  @param -entry <entry name>\n
38  Use specified entry from dictionary (parent:child notation)
39 
40  @param -keywords \n
41  List keywords in the dictionary.
42 
43  @param -times \n
44  List all time steps.
45 
46  @param -case <dir>\n
47  Case directory.
48 
49  @param -help \n
50  Display help message.
51 
52  @param -doc \n
53  Display Doxygen API documentation page for this application.
54 
55  @param -srcDoc \n
56  Display Doxygen source documentation page for this application.
57 
58 \*---------------------------------------------------------------------------*/
59 
60 #include <OpenFOAM/argList.H>
61 #include <OpenFOAM/Time.H>
62 #include <OpenFOAM/dictionary.H>
63 #include <OpenFOAM/IFstream.H>
64 
65 using namespace Foam;
66 
67 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
68 // Main program:
69 
70 int main(int argc, char *argv[])
71 {
73  argList::validOptions.insert("times", "");
74  argList::validOptions.insert("dictionary", "dictionary name");
75  argList::validOptions.insert("keywords", "");
76  argList::validOptions.insert("entry", "entry name");
77 
78 # include <OpenFOAM/setRootCase.H>
79 
80  Info<< endl;
81 
82  if (args.optionFound("times"))
83  {
84  instantList times
85  (
87  );
88 
89  forAll (times, i)
90  {
91  Info<< times[i].name() << endl;
92  }
93  }
94 
95  if (args.optionFound("dictionary"))
96  {
97  fileName dictFileName
98  (
99  args.rootPath()/args.caseName()/args.option("dictionary")
100  );
101 
102  IFstream dictFile(dictFileName);
103 
104  if (dictFile.good())
105  {
106  dictionary dict(dictFile);
107 
108  if (args.optionFound("keywords") && !args.optionFound("entry"))
109  {
110  for
111  (
112  IDLList<entry>::iterator iter = dict.begin();
113  iter != dict.end();
114  ++iter
115  )
116  {
117  Info<< iter().keyword() << endl;
118  }
119  }
120  else if (args.optionFound("entry"))
121  {
122  wordList entryNames
123  (
124  fileName(args.option("entry")).components(':')
125  );
126 
127  if (dict.found(entryNames[0]))
128  {
129  const entry* entPtr = &dict.lookupEntry
130  (
131  entryNames[0],
132  false,
133  true // wildcards
134  );
135 
136  for (int i=1; i<entryNames.size(); i++)
137  {
138  if (entPtr->dict().found(entryNames[i]))
139  {
140  entPtr = &entPtr->dict().lookupEntry
141  (
142  entryNames[i],
143  false,
144  true // wildcards
145  );
146  }
147  else
148  {
150  << "Cannot find sub-entry " << entryNames[i]
151  << " in entry " << args.option("entry")
152  << " in dictionary " << dictFileName;
153  FatalError.exit(3);
154  }
155  }
156 
157  if (args.optionFound("keywords"))
158  {
159  /*
160  if (ent[1] != token::BEGIN_BLOCK)
161  {
162  FatalErrorIn(args.executable())
163  << "Cannot find entry "
164  << args.option("entry")
165  << " in dictionary " << dictFileName
166  << " is not a sub-dictionary";
167  FatalError.exit(4);
168  }
169  */
170 
171  const dictionary& dict(entPtr->dict());
172  for
173  (
175  iter != dict.end();
176  ++iter
177  )
178  {
179  Info<< iter().keyword() << endl;
180  }
181  }
182  else
183  {
184  Info<< *entPtr << endl;
185  }
186  }
187  else
188  {
190  << "Cannot find entry "
191  << entryNames[0]
192  << " in dictionary " << dictFileName;
193  FatalError.exit(2);
194  }
195  }
196  else
197  {
198  Info<< dict;
199  }
200  }
201  else
202  {
204  << "Cannot open file " << dictFileName;
205  FatalError.exit(1);
206  }
207  }
208 
209  return 0;
210 }
211 
212 
213 // ************************ vim: set sw=4 sts=4 et: ************************ //