foamDebugSwitches.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-2014 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  foamDebugSwitches
26 
27 Description
28  Write out all library debug switches.
29 
30 \*---------------------------------------------------------------------------*/
31 
32 #include "argList.H"
33 #include "dictionary.H"
34 #include "IFstream.H"
35 #include "IOobject.H"
36 #include "HashSet.H"
37 
38 using namespace Foam;
39 
40 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
41 
42 int main(int argc, char *argv[])
43 {
46  (
47  "new",
48  "output switches that are known from the libraries "
49  "but that do not seem to be known in the current etc/controlDict"
50  );
52  (
53  "old",
54  "output switches that appear to be unknown in "
55  "the current etc/controlDict"
56  );
57 
58  argList args(argc, argv);
59 
60  wordList currDebug(debug::debugSwitches().toc());
61  wordList currInfo(debug::infoSwitches().toc());
62  wordList currOpt(debug::optimisationSwitches().toc());
63 
64  if (args.optionFound("old") || args.optionFound("new"))
65  {
66  fileNameList controlDictFiles = findEtcFiles("controlDict", true);
68  forAllReverse(controlDictFiles, cdfi)
69  {
70  controlDict.merge(dictionary(IFstream(controlDictFiles[cdfi])()));
71  }
72 
73  wordHashSet oldDebug
74  (
75  controlDict.subDict("DebugSwitches").toc()
76  );
77 
78  wordHashSet oldInfo
79  (
80  controlDict.subDict("InfoSwitches").toc()
81  );
82 
83  wordHashSet oldOpt
84  (
85  controlDict.subDict("OptimisationSwitches").toc()
86  );
87 
88 
89  wordHashSet hashset;
90  wordList listing;
91 
92 
93  // list old switches - but this can't work since the (old) inserted
94  // switches are in both sets
95  // Workaround:
96  // 1. run without any options (get complete list)
97  // 2. comment out DebugSwitches, run again with -new to find new ones
98  // and do a diff
99  if (args.optionFound("old"))
100  {
102 
103  hashset = oldDebug;
104  hashset -= currDebug;
105  listing = hashset.toc();
106  sort(listing);
107  Info<< "old DebugSwitches: " << listing << endl;
108 
109  hashset = oldInfo;
110  hashset -= currInfo;
111  listing = hashset.toc();
112  sort(listing);
113  Info<< "old InfoSwitches: " << listing << endl;
114 
115  hashset = oldOpt;
116  hashset -= currOpt;
117  listing = hashset.toc();
118  sort(listing);
119  Info<< "old OptimisationSwitches: " << listing << endl;
120  }
121 
122  // list new switches
123  if (args.optionFound("new"))
124  {
126 
127  hashset = currDebug;
128  hashset -= oldDebug;
129 
130  listing = hashset.toc();
131  sort(listing);
132  Info<< "new DebugSwitches: " << listing << endl;
133 
134  hashset = currInfo;
135  hashset -= oldInfo;
136  listing = hashset.toc();
137  sort(listing);
138  Info<< "new InfoSwitches: " << listing << endl;
139 
140  hashset = currOpt;
141  hashset -= oldOpt;
142  listing = hashset.toc();
143  sort(listing);
144  Info<< "new OptimisationSwitches: " << listing << endl;
145  }
146  }
147  else
148  {
150 
151  sort(currDebug);
152  Info<< "DebugSwitches: " << currDebug << endl;
153 
154  sort(currInfo);
155  Info<< "InfoSwitches: " << currInfo << endl;
156 
157  sort(currOpt);
158  Info<< "OptimisationSwitches: " << currOpt << endl;
159  }
160 
161  Info<< nl << "End" << nl << endl;
162 
163  return 0;
164 }
165 
166 
167 // ************************************************************************* //
Foam::debug::debugSwitches
dictionary & debugSwitches()
The DebugSwitches sub-dictionary in the central controlDict.
Definition: debug.C:146
Foam::HashTable::toc
List< Key > toc() const
Return the table of contents.
Definition: HashTable.C:201
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::argList
Extract command arguments and options from the supplied argc and argv parameters.
Definition: argList.H:97
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::HashSet
A HashTable with keys but without contents.
Definition: HashSet.H:59
controlDict
runTime controlDict().lookup("adjustTimeStep") >> adjustTimeStep
Foam::nl
static const char nl
Definition: Ostream.H:260
Foam::Info
messageStream Info
argList.H
main
int main(int argc, char *argv[])
Definition: postCalc.C:54
IFstream.H
HashSet.H
IOobject.H
Foam::dictionary
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:137
forAllReverse
#define forAllReverse(list, i)
Reverse loop across all elements in list.
Definition: UList.H:418
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::debug::infoSwitches
dictionary & infoSwitches()
The InfoSwitches sub-dictionary in the central controlDict.
Definition: debug.C:152
Foam::IOobject::writeDivider
static Stream & writeDivider(Stream &os)
Write the standard file section divider.
Definition: IOobjectI.H:108
Foam::findEtcFiles
fileNameList findEtcFiles(const fileName &, bool mandatory=false, bool findFirst=false)
Search for files from user/group/shipped directories.
Definition: POSIX.C:271
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
dictionary.H
Foam::argList::optionFound
bool optionFound(const word &opt) const
Return true if the named option is found.
Definition: argListI.H:108
Foam::sort
void sort(UList< T > &)
Definition: UList.C:107
Foam::argList::noParallel
static void noParallel()
Remove the parallel options.
Definition: argList.C:161
args
Foam::argList args(argc, argv)
Foam::debug::optimisationSwitches
dictionary & optimisationSwitches()
The OptimisationSwitches sub-dictionary in the central controlDict.
Definition: debug.C:158