foamDictionary: Added -output option

to specify the path name of the output dictionary to which the expanded and/or
changed dictionary is written.

Usage: foamDictionary [OPTIONS] <dictionary file>
options:
  -add <value>      Add a new entry
  -case <dir>       specify alternate case directory, default is the cwd
  -dict             Set, add or merge entry from a dictionary.
  -diff <dict>      Write differences with respect to the specified dictionary
  -entry <name>     report/select the named entry
  -expand           Read the specified dictionary file and expand the macros
                    etc.
  -fileHandler <handler>
                    override the fileHandler
  -hostRoots <((host1 dir1) .. (hostN dirN))>
                    slave root directories (per host) for distributed running
  -includes         List the #include/#includeIfPresent files to standard output
  -keywords         list keywords
  -libs '("lib1.so" ... "libN.so")'
                    pre-load libraries
  -merge <value>    Merge entry
  -noFunctionObjects
                    do not execute functionObjects
  -output <path name>
                    Path name of the output dictionary
  -parallel         run in parallel
  -remove           Remove the entry.
  -roots <(dir1 .. dirN)>
                    slave root directories for distributed running
  -set <value>      Set entry value, add new entry or apply list of
                    substitutions
  -value            Print entry value
  -writePrecision <label>
                    Write with the specified precision
  -srcDoc           display source code in browser
  -doc              display application documentation in browser
  -help             print the usage

manipulates dictionaries
This commit is contained in:
Henry Weller
2023-08-10 21:24:44 +01:00
parent 89db32a3a7
commit 6d9bc62fa9

View File

@ -79,12 +79,16 @@ Usage
(or sub entry if -entry specified) (or sub entry if -entry specified)
- \par -expand - \par -expand
Read the specified dictionary file, expand the macros etc. and write Read the specified dictionary file, expand the macros etc.
the resulting dictionary to standard output. Writes the expanded dictionary to the output dictionary if specified
otherwise to standard output
- \par -includes - \par -includes
List the \c #include and \c #includeIfPresent files to standard output List the \c #include and \c #includeIfPresent files to standard output
- \par -output
Path name of the output dictionary, defaults to the input dictionary
Example usage: Example usage:
- Change simulation to run for one timestep only: - Change simulation to run for one timestep only:
\verbatim \verbatim
@ -327,8 +331,7 @@ int main(int argc, char *argv[])
argList::addBoolOption argList::addBoolOption
( (
"expand", "expand",
"Read the specified dictionary file, expand the macros etc. and write " "Read the specified dictionary file and expand the macros etc."
"the resulting dictionary to standard output"
); );
argList::addOption argList::addOption
( (
@ -336,6 +339,12 @@ int main(int argc, char *argv[])
"label", "label",
"Write with the specified precision" "Write with the specified precision"
); );
argList::addOption
(
"output",
"path name",
"Path name of the output dictionary"
);
argList args(argc, argv); argList args(argc, argv);
@ -432,24 +441,31 @@ int main(int argc, char *argv[])
} }
else if (args.optionFound("expand") && !args.optionFound("entry")) else if (args.optionFound("expand") && !args.optionFound("entry"))
{ {
IOobject::writeBanner(Info) if (!args.optionFound("output"))
<<"//\n// " << dictPath << "\n//\n";
// Change the format to ASCII
if (dict.found(IOobject::foamFile))
{ {
dict.subDict(IOobject::foamFile).add IOobject::writeBanner(Info)
( <<"//\n// " << dictPath << "\n//\n";
"format",
IOstream::ASCII, // Change the format to ASCII
true if (dict.found(IOobject::foamFile))
); {
dict.subDict(IOobject::foamFile).add
(
"format",
IOstream::ASCII,
true
);
}
dict.dictionary::write(Info, false);
IOobject::writeEndDivider(Info);
return 0;
}
else
{
changed = true;
} }
dict.dictionary::write(Info, false);
IOobject::writeEndDivider(Info);
return 0;
} }
@ -635,7 +651,7 @@ int main(int argc, char *argv[])
remove(dict, diffDict); remove(dict, diffDict);
dict.dictionary::write(Info, false); dict.dictionary::write(Info, false);
} }
else else if (!args.optionFound("output"))
{ {
dict.dictionary::write(Info, false); dict.dictionary::write(Info, false);
} }
@ -648,7 +664,13 @@ int main(int argc, char *argv[])
} }
else if (dictPtr) else if (dictPtr)
{ {
OFstream os(args.path()/dictPath, dictFormat); // Set output dict name, defaults to the name of the input dict
const fileName outputDictPath
(
args.optionLookupOrDefault<fileName>("output", dictPath)
);
OFstream os(args.path()/outputDictPath, dictFormat);
IOobject::writeBanner(os); IOobject::writeBanner(os);
if (dictPtr->found(IOobject::foamFile)) if (dictPtr->found(IOobject::foamFile))
{ {