mirror of
https://github.com/OpenFOAM/OpenFOAM-6.git
synced 2025-12-08 06:57:46 +00:00
foamDictionary: Added -expand and -includes options
Replaces expandDictionary utility
This commit is contained in:
@ -1,4 +0,0 @@
|
||||
|
||||
expandDictionary.C
|
||||
|
||||
EXE = $(FOAM_APPBIN)/expandDictionary
|
||||
@ -1,2 +0,0 @@
|
||||
/* EXE_INC = */
|
||||
/* EXE_LIBS = */
|
||||
@ -1,105 +0,0 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software: you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Application
|
||||
expandDictionary
|
||||
|
||||
Description
|
||||
Read the dictionary provided as an argument, expand the macros etc. and
|
||||
write the resulting dictionary to standard output.
|
||||
|
||||
Usage
|
||||
- expandDictionary inputDict [OPTION]
|
||||
|
||||
\param -list \n
|
||||
Report the #include/#includeIfPresent to stdout only.
|
||||
|
||||
Note
|
||||
The \c -list option can be useful when determining which files
|
||||
are actually included by a directory. It can also be used to
|
||||
determine which files may need to be copied when transferring
|
||||
simulation to another environment. The following code snippet
|
||||
could be a useful basis for such cases:
|
||||
|
||||
\verbatim
|
||||
for i in . 0 constant system
|
||||
do
|
||||
find $i -maxdepth 1 -type f -exec expandDictionary -list '{}' \;
|
||||
done | sed -ne '/^"\//!{ s/^"//; s/"$//; p }' | sort | uniq
|
||||
\endverbatim
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "argList.H"
|
||||
#include "IFstream.H"
|
||||
#include "IOobject.H"
|
||||
#include "dictionary.H"
|
||||
#include "includeEntry.H"
|
||||
|
||||
using namespace Foam;
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
argList::addNote
|
||||
(
|
||||
"Read the specified dictionary file, expand the macros etc. and write\n"
|
||||
"the resulting dictionary to standard output."
|
||||
);
|
||||
|
||||
argList::addBoolOption
|
||||
(
|
||||
"list",
|
||||
"Report the #include/#includeIfPresent to stdout only"
|
||||
);
|
||||
|
||||
argList::noBanner();
|
||||
argList::noParallel();
|
||||
argList::validArgs.append("inputDict");
|
||||
argList args(argc, argv);
|
||||
|
||||
const string dictName = args[1];
|
||||
|
||||
const bool listOpt = args.optionFound("list");
|
||||
|
||||
if (listOpt)
|
||||
{
|
||||
Foam::functionEntries::includeEntry::log = true;
|
||||
}
|
||||
|
||||
dictionary dict(IFstream(dictName)(), true);
|
||||
|
||||
if (!listOpt)
|
||||
{
|
||||
IOobject::writeBanner(Info)
|
||||
<<"//\n// " << dictName << "\n//\n";
|
||||
dict.write(Info, false);
|
||||
IOobject::writeDivider(Info);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -43,6 +43,13 @@ Usage
|
||||
\param -set \<value\> \n
|
||||
Adds or replaces the entry
|
||||
|
||||
\param -expand \n
|
||||
Read the specified dictionary file, expand the macros etc. and write
|
||||
the resulting dictionary to standard output.
|
||||
|
||||
\param -includes \n
|
||||
List the #include/#includeIfPresent files to standard output.
|
||||
|
||||
Typical usage:
|
||||
- change simulation to run for one timestep only:
|
||||
foamDictionary system/controlDict -entry stopAt -set writeNow;
|
||||
@ -67,6 +74,7 @@ Usage
|
||||
#include "Time.H"
|
||||
#include "IFstream.H"
|
||||
#include "OFstream.H"
|
||||
#include "includeEntry.H"
|
||||
|
||||
using namespace Foam;
|
||||
|
||||
@ -248,10 +256,28 @@ int main(int argc, char *argv[])
|
||||
"value",
|
||||
"adds a new entry"
|
||||
);
|
||||
argList::addBoolOption
|
||||
(
|
||||
"includes",
|
||||
"List the #include/#includeIfPresent files to standard output."
|
||||
);
|
||||
argList::addBoolOption
|
||||
(
|
||||
"expand",
|
||||
"Read the specified dictionary file, expand the macros etc. and write "
|
||||
"the resulting dictionary to standard output."
|
||||
);
|
||||
|
||||
#include "setRootCase.H"
|
||||
argList args(argc, argv);
|
||||
|
||||
fileName dictFileName(args.rootPath()/args.caseName()/args[1]);
|
||||
const bool listIncludes = args.optionFound("includes");
|
||||
|
||||
if (listIncludes)
|
||||
{
|
||||
Foam::functionEntries::includeEntry::log = true;
|
||||
}
|
||||
|
||||
fileName dictFileName(args[1]);
|
||||
|
||||
autoPtr<IFstream> dictFile(new IFstream(dictFileName));
|
||||
|
||||
@ -263,6 +289,20 @@ int main(int argc, char *argv[])
|
||||
dictionary dict;
|
||||
dict.read(dictFile(), true);
|
||||
|
||||
if (listIncludes)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
else if (args.optionFound("expand"))
|
||||
{
|
||||
IOobject::writeBanner(Info)
|
||||
<<"//\n// " << dictFileName << "\n//\n";
|
||||
dict.write(Info, false);
|
||||
IOobject::writeDivider(Info);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
word entryName;
|
||||
if (args.optionReadIfPresent("entry", entryName))
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user