mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: provide FOAM_EXECUTABLE as environment variable in argList
- can be used directly from within an application or function-object. Makes it available for dictionaries.
This commit is contained in:
@ -288,6 +288,9 @@ Foam::vtkPVFoam::vtkPVFoam
|
||||
fullCasePath = cwd();
|
||||
}
|
||||
|
||||
// The name of the executable, unless already present in the environment
|
||||
setEnv("FOAM_EXECUTABLE", "paraview", false);
|
||||
|
||||
// Set the case as an environment variable - some BCs might use this
|
||||
if (fullCasePath.name().find("processor", 0) == 0)
|
||||
{
|
||||
|
||||
@ -206,6 +206,9 @@ Foam::vtkPVblockMesh::vtkPVblockMesh
|
||||
fullCasePath = cwd();
|
||||
}
|
||||
|
||||
// The name of the executable, unless already present in the environment
|
||||
setEnv("FOAM_EXECUTABLE", "paraview", false);
|
||||
|
||||
// Set the case as an environment variable - some BCs might use this
|
||||
if (fullCasePath.name().find("processor", 0) == 0)
|
||||
{
|
||||
|
||||
@ -310,17 +310,17 @@ bool Foam::argList::postProcess(int argc, char *argv[])
|
||||
|
||||
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
||||
|
||||
// Convert argv -> args_
|
||||
// Transform sequences with "(" ... ")" into string lists in the process
|
||||
bool Foam::argList::regroupArgv(int& argc, char**& argv)
|
||||
{
|
||||
int nArgs = 0;
|
||||
int listDepth = 0;
|
||||
int nArgs = 1;
|
||||
unsigned listDepth = 0;
|
||||
string tmpString;
|
||||
|
||||
// Note: we also re-write directly into args_
|
||||
// Note: we rewrite directly into args_
|
||||
// and use a second pass to sort out args/options
|
||||
for (int argI = 0; argI < argc; ++argI)
|
||||
|
||||
args_[0] = fileName(argv[0]);
|
||||
for (int argI = 1; argI < argc; ++argI)
|
||||
{
|
||||
if (strcmp(argv[argI], "(") == 0)
|
||||
{
|
||||
@ -333,7 +333,7 @@ bool Foam::argList::regroupArgv(int& argc, char**& argv)
|
||||
{
|
||||
--listDepth;
|
||||
tmpString += ")";
|
||||
if (listDepth == 0)
|
||||
if (!listDepth)
|
||||
{
|
||||
args_[nArgs++] = tmpString;
|
||||
tmpString.clear();
|
||||
@ -359,11 +359,21 @@ bool Foam::argList::regroupArgv(int& argc, char**& argv)
|
||||
|
||||
if (tmpString.size())
|
||||
{
|
||||
// Group(s) not closed, but flush anything still pending
|
||||
args_[nArgs++] = tmpString;
|
||||
}
|
||||
|
||||
args_.setSize(nArgs);
|
||||
|
||||
std::string::size_type len = (nArgs-1); // Spaces between args
|
||||
forAll(args_, argi)
|
||||
{
|
||||
len += args_[argi].size();
|
||||
}
|
||||
|
||||
// Length needed for regrouped command-line
|
||||
argListStr_.reserve(len);
|
||||
|
||||
return nArgs < argc;
|
||||
}
|
||||
|
||||
@ -403,6 +413,8 @@ void Foam::argList::getRootCase()
|
||||
globalCase_ = casePath.name();
|
||||
case_ = globalCase_;
|
||||
|
||||
// The name of the executable, unless already present in the environment
|
||||
setEnv("FOAM_EXECUTABLE", executable_, false);
|
||||
|
||||
// Set the case and case-name as an environment variable
|
||||
if (rootPath_.isAbsolute())
|
||||
@ -440,7 +452,7 @@ Foam::argList::argList
|
||||
{
|
||||
// Check if this run is a parallel run by searching for any parallel option
|
||||
// If found call runPar which might filter argv
|
||||
for (int argI = 0; argI < argc; ++argI)
|
||||
for (int argI = 1; argI < argc; ++argI)
|
||||
{
|
||||
if (argv[argI][0] == '-')
|
||||
{
|
||||
@ -455,17 +467,11 @@ Foam::argList::argList
|
||||
}
|
||||
|
||||
// Convert argv -> args_ and capture ( ... ) lists
|
||||
// for normal arguments and for options
|
||||
regroupArgv(argc, argv);
|
||||
argListStr_ += args_[0];
|
||||
|
||||
// Get executable name
|
||||
args_[0] = fileName(argv[0]);
|
||||
executable_ = fileName(argv[0]).name();
|
||||
|
||||
// Check arguments and options, we already have argv[0]
|
||||
// Check arguments and options, argv[0] was already handled
|
||||
int nArgs = 1;
|
||||
argListStr_ = args_[0];
|
||||
|
||||
for (int argI = 1; argI < args_.size(); ++argI)
|
||||
{
|
||||
argListStr_ += ' ';
|
||||
@ -525,6 +531,9 @@ Foam::argList::argList
|
||||
|
||||
args_.setSize(nArgs);
|
||||
|
||||
// Set executable name
|
||||
executable_ = fileName(args_[0]).name();
|
||||
|
||||
parse(checkArgs, checkOpts, initialise);
|
||||
}
|
||||
|
||||
@ -769,7 +778,7 @@ void Foam::argList::parse
|
||||
}
|
||||
|
||||
// Distribute the master's argument list (with new root)
|
||||
bool hadCaseOpt = options_.found("case");
|
||||
const bool hadCaseOpt = options_.found("case");
|
||||
for
|
||||
(
|
||||
int slave = Pstream::firstSlave();
|
||||
|
||||
@ -42,6 +42,8 @@ Description
|
||||
Default command-line options:
|
||||
- \par -case \<dir\>
|
||||
Select a case directory instead of the current working directory
|
||||
- \par -decomposeParDict \<file\>
|
||||
Read decomposePar dictionary from specified location
|
||||
- \par -parallel
|
||||
Specify case as a parallel job
|
||||
- \par -doc
|
||||
@ -51,10 +53,25 @@ Description
|
||||
- \par -help
|
||||
Print the usage
|
||||
|
||||
The environment variable \b FOAM_CASE is set to the path of the
|
||||
global case (same for serial and parallel jobs).
|
||||
The environment variable \b FOAM_CASENAME is set to the name of the
|
||||
global case.
|
||||
Additionally, the \b -noFunctionObjects and \b -postProcess options
|
||||
may be present for some solvers or utilities.
|
||||
|
||||
Environment variables set by argList or by Time:
|
||||
- \par FOAM_CASE
|
||||
The path of the global case.
|
||||
It is the same for serial and parallel jobs.
|
||||
- \par FOAM_CASENAME
|
||||
The name of the global case.
|
||||
- \par FOAM_EXECUTABLE
|
||||
If not already present in the calling environment,
|
||||
it is set to the \a name portion of the calling executable.
|
||||
- \par FOAM_APPLICATION
|
||||
If not already present in the calling environment,
|
||||
it is set to the value of the \c application entry
|
||||
(from \c controlDict) if that entry is present.
|
||||
|
||||
The value of the \b FOAM_APPLICATION may be inconsistent if the value of
|
||||
the \c application entry is adjusted during runtime.
|
||||
|
||||
Note
|
||||
- The document browser used is defined by the \b FOAM_DOC_BROWSER
|
||||
@ -131,10 +148,12 @@ class argList
|
||||
// * cwd
|
||||
//
|
||||
// Also export FOAM_CASE and FOAM_CASENAME environment variables
|
||||
// so they can be used immediately (eg, in decomposeParDict)
|
||||
// so they can be used immediately (eg, in decomposeParDict), as well
|
||||
// as the FOAM_EXECUTABLE environment.
|
||||
void getRootCase();
|
||||
|
||||
//- Transcribe argv into internal args_
|
||||
//- Transcribe argv into internal args_.
|
||||
// Transform sequences with "(" ... ")" into string lists
|
||||
// return true if any "(" ... ")" sequences were captured
|
||||
bool regroupArgv(int& argc, char**& argv);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user