Merge branch 'master' of ssh://git.code.sf.net/p/foam-extend/foam-extend-3.2
[foam-extend-3.2.git] / applications / utilities / miscellaneous / foamInfoExec / foamInfoExec.C
blob7f069db582a88e84b1f833c2fbe7f7e57765831d
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | foam-extend: Open Source CFD
4    \\    /   O peration     | Version:     3.2
5     \\  /    A nd           | Web:         http://www.foam-extend.org
6      \\/     M anipulation  | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
8 License
9     This file is part of foam-extend.
11     foam-extend 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 3 of the License, or (at your
14     option) any later version.
16     foam-extend is distributed in the hope that it will be useful, but
17     WITHOUT ANY WARRANTY; without even the implied warranty of
18     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19     General Public License for more details.
21     You should have received a copy of the GNU General Public License
22     along with foam-extend.  If not, see <http://www.gnu.org/licenses/>.
24 Description
25     Interrogates a case and prints information to screen
27 \*---------------------------------------------------------------------------*/
29 #include "argList.H"
30 #include "objectRegistry.H"
31 #include "foamTime.H"
32 #include "dictionary.H"
33 #include "IFstream.H"
35 using namespace Foam;
37 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
38 // Main program:
40 int main(int argc, char *argv[])
42     argList::noParallel();
43     argList::validOptions.insert("times", "");
44     argList::validOptions.insert("dictionary", "dictionary name");
45     argList::validOptions.insert("keywords", "");
46     argList::validOptions.insert("entry", "entry name");
48 #   include "setRootCase.H"
50     Info<< endl;
52     if (args.optionFound("times"))
53     {
54         instantList times
55         (
56             Foam::Time::findTimes(args.rootPath()/args.caseName())
57         );
59         forAll (times, i)
60         {
61             Info<< times[i].name() << endl;
62         }
63     }
65     if (args.optionFound("dictionary"))
66     {
67         fileName dictFileName
68         (
69             args.rootPath()/args.caseName()/args.option("dictionary")
70         );
72         IFstream dictFile(dictFileName);
74         if (dictFile.good())
75         {
76             dictionary dict(dictFile);
78             if (args.optionFound("keywords") && !args.optionFound("entry"))
79             {
80                 for
81                 (
82                     IDLList<entry>::iterator iter = dict.begin();
83                     iter != dict.end();
84                     ++iter
85                 )
86                 {
87                     Info<< iter().keyword() << endl;
88                 }
89             }
90             else if (args.optionFound("entry"))
91             {
92                 wordList entryNames
93                 (
94                     fileName(args.option("entry")).components(':')
95                 );
97                 if (dict.found(entryNames[0]))
98                 {
99                     const entry* entPtr = &dict.lookupEntry
100                     (
101                         entryNames[0],
102                         false,
103                         true            // wildcards
104                     );
106                     for (int i=1; i<entryNames.size(); i++)
107                     {
108                         if (entPtr->dict().found(entryNames[i]))
109                         {
110                             entPtr = &entPtr->dict().lookupEntry
111                             (
112                                 entryNames[i],
113                                 false,
114                                 true    // wildcards
115                             );
116                         }
117                         else
118                         {
119                             FatalErrorIn(args.executable())
120                                 << "Cannot find sub-entry " << entryNames[i]
121                                 << " in entry " << args.option("entry")
122                                 << " in dictionary " << dictFileName;
123                             FatalError.exit(3);
124                         }
125                     }
127                     if (args.optionFound("keywords"))
128                     {
129                         /*
130                         if (ent[1] != token::BEGIN_BLOCK)
131                         {
132                             FatalErrorIn(args.executable())
133                                 << "Cannot find entry "
134                                 << args.option("entry")
135                                 << " in dictionary " << dictFileName
136                                 << " is not a sub-dictionary";
137                             FatalError.exit(4);
138                         }
139                         */
141                         const dictionary& dict(entPtr->dict());
142                         for
143                         (
144                             IDLList<entry>::const_iterator iter = dict.begin();
145                             iter != dict.end();
146                             ++iter
147                         )
148                         {
149                             Info<< iter().keyword() << endl;
150                         }
151                     }
152                     else
153                     {
154                         Info<< *entPtr << endl;
155                     }
156                 }
157                 else
158                 {
159                     FatalErrorIn(args.executable())
160                         << "Cannot find entry "
161                         << entryNames[0]
162                         << " in dictionary " << dictFileName;
163                     FatalError.exit(2);
164                 }
165             }
166             else
167             {
168                 Info<< dict;
169             }
170         }
171         else
172         {
173             FatalErrorIn(args.executable())
174                 << "Cannot open file " << dictFileName;
175             FatalError.exit(1);
176         }
177     }
179     return 0;
183 // ************************************************************************* //