From dbcb0553b51b6ccdc0672cfcff687619930ab2e0 Mon Sep 17 00:00:00 2001 From: Henry Weller <http://cfd.direct> Date: Fri, 10 Jun 2016 17:39:16 +0100 Subject: [PATCH] foamDictionary: Added -expand and -includes options Replaces expandDictionary utility --- .../miscellaneous/expandDictionary/Make/files | 4 - .../expandDictionary/Make/options | 2 - .../expandDictionary/expandDictionary.C | 105 ------------------ .../foamDictionary/foamDictionary.C | 44 +++++++- 4 files changed, 42 insertions(+), 113 deletions(-) delete mode 100644 applications/utilities/miscellaneous/expandDictionary/Make/files delete mode 100644 applications/utilities/miscellaneous/expandDictionary/Make/options delete mode 100644 applications/utilities/miscellaneous/expandDictionary/expandDictionary.C diff --git a/applications/utilities/miscellaneous/expandDictionary/Make/files b/applications/utilities/miscellaneous/expandDictionary/Make/files deleted file mode 100644 index 9693938e70..0000000000 --- a/applications/utilities/miscellaneous/expandDictionary/Make/files +++ /dev/null @@ -1,4 +0,0 @@ - -expandDictionary.C - -EXE = $(FOAM_APPBIN)/expandDictionary diff --git a/applications/utilities/miscellaneous/expandDictionary/Make/options b/applications/utilities/miscellaneous/expandDictionary/Make/options deleted file mode 100644 index 18e6fe47af..0000000000 --- a/applications/utilities/miscellaneous/expandDictionary/Make/options +++ /dev/null @@ -1,2 +0,0 @@ -/* EXE_INC = */ -/* EXE_LIBS = */ diff --git a/applications/utilities/miscellaneous/expandDictionary/expandDictionary.C b/applications/utilities/miscellaneous/expandDictionary/expandDictionary.C deleted file mode 100644 index bdcea1fd93..0000000000 --- a/applications/utilities/miscellaneous/expandDictionary/expandDictionary.C +++ /dev/null @@ -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; -} - - -// ************************************************************************* // diff --git a/applications/utilities/miscellaneous/foamDictionary/foamDictionary.C b/applications/utilities/miscellaneous/foamDictionary/foamDictionary.C index e00cb2518c..64b1743f85 100644 --- a/applications/utilities/miscellaneous/foamDictionary/foamDictionary.C +++ b/applications/utilities/miscellaneous/foamDictionary/foamDictionary.C @@ -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." + ); + + argList args(argc, argv); + + const bool listIncludes = args.optionFound("includes"); - #include "setRootCase.H" + if (listIncludes) + { + Foam::functionEntries::includeEntry::log = true; + } - fileName dictFileName(args.rootPath()/args.caseName()/args[1]); + 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)) { -- GitLab