From 321f95726d4e199c4098cc18477e6a55ccf21d1b Mon Sep 17 00:00:00 2001 From: Martin Beaudoin Date: Sun, 29 May 2011 19:59:53 -0400 Subject: [PATCH] Allow overriding the location of the global controlDict file using an environment variable --- src/OSspecific/POSIX/signals/sigFpe.C | 2 +- .../primitiveEntry/primitiveEntryIO.C | 15 +++++++++++++ src/OpenFOAM/global/argList/argList.C | 22 +++++++++++-------- src/OpenFOAM/global/debug/debug.C | 12 +++++++++- 4 files changed, 40 insertions(+), 11 deletions(-) diff --git a/src/OSspecific/POSIX/signals/sigFpe.C b/src/OSspecific/POSIX/signals/sigFpe.C index b5c79af19..8c1a20eb4 100644 --- a/src/OSspecific/POSIX/signals/sigFpe.C +++ b/src/OSspecific/POSIX/signals/sigFpe.C @@ -192,7 +192,7 @@ void Foam::sigFpe::set(const bool verbose) { if (verbose) { - Info<< "SigFpe : Enabling floating point exception trapping" + Info<< "SigFpe : Enabling floating point exception trapping" << " (FOAM_SIGFPE)." << endl; } diff --git a/src/OpenFOAM/db/dictionary/primitiveEntry/primitiveEntryIO.C b/src/OpenFOAM/db/dictionary/primitiveEntry/primitiveEntryIO.C index 2a8452794..127feea37 100644 --- a/src/OpenFOAM/db/dictionary/primitiveEntry/primitiveEntryIO.C +++ b/src/OpenFOAM/db/dictionary/primitiveEntry/primitiveEntryIO.C @@ -208,6 +208,21 @@ void Foam::primitiveEntry::readEntry(const dictionary& dict, Istream& is) } else { + // When reading an invalid global controlDict file, the following call + // to FatalIOErrorIn will crash with a "Segmentation Fault", and will + // fail to generate any useful error message to the console. + // This additional error message will at least leave a minimal trace. + // + // The cause of the Seg. fault is still unknown, but seems to be related + // to the initialization of the string member attributes of the global + // object FatalIOError. (MB 05/2011) + // + std::cerr << "--> Error from: " + << "primitiveEntry::readEntry(const dictionary&, Istream&)" + << std::endl; + std::cerr << "--> Fatal error reading input from: " + << is.name() << std::endl; + FatalIOErrorIn ( "primitiveEntry::readEntry(const dictionary&, Istream&)", diff --git a/src/OpenFOAM/global/argList/argList.C b/src/OpenFOAM/global/argList/argList.C index 9d59823e3..26ed4b7a9 100644 --- a/src/OpenFOAM/global/argList/argList.C +++ b/src/OpenFOAM/global/argList/argList.C @@ -311,17 +311,21 @@ Foam::argList::argList string dateString = clock::date(); string timeString = clock::clockTime(); - + fileName ctrlDict = debug::controlDict().name(); + string ctrlDictString = ctrlDict.path()/ctrlDict.name(); + // Print the banner once only for parallel runs if (Pstream::master() && bannerEnabled) { IOobject::writeBanner(Info, true) - << "Build : " << Foam::FOAMbuild << nl - << "Exec : " << argListString.c_str() << nl - << "Date : " << dateString.c_str() << nl - << "Time : " << timeString.c_str() << nl - << "Host : " << hostName() << nl - << "PID : " << pid() << endl; + << "Build : " << Foam::FOAMbuild << nl + << "Exec : " << argListString.c_str() << nl + << "Date : " << dateString.c_str() << nl + << "Time : " << timeString.c_str() << nl + << "Host : " << hostName() << nl + << "PID : " << pid() << nl + << "CtrlDict : " << ctrlDictString.c_str() + << endl; } jobInfo.add("startDate", dateString); @@ -528,8 +532,8 @@ Foam::argList::argList if (Pstream::master() && bannerEnabled) { - Info<< "Case : " << (rootPath_/globalCase_).c_str() << nl - << "nProcs : " << nProcs << endl; + Info<< "Case : " << (rootPath_/globalCase_).c_str() << nl + << "nProcs : " << nProcs << endl; if (parRunControl_.parRun()) { diff --git a/src/OpenFOAM/global/debug/debug.C b/src/OpenFOAM/global/debug/debug.C index 3e4345bcc..bf2e35486 100644 --- a/src/OpenFOAM/global/debug/debug.C +++ b/src/OpenFOAM/global/debug/debug.C @@ -77,9 +77,19 @@ Foam::dictionary& Foam::debug::controlDict() { if (!controlDictPtr_) { + // Allow users to override the location of the global controlDict + // dictionary using an environment variable. Using this environment + // variable, one can assign a different global controlDict for each + // case, without having to modify the "default" ones. + fileName globControlDictFileName = getEnv("FOAM_GLOBAL_CONTROLDICT"); + + // Fallback to default locations if filename is empty or not valid + if( ! isFile(globControlDictFileName) ) + globControlDictFileName = findEtcFile("controlDict", true); + controlDictPtr_ = new dictionary ( - IFstream(findEtcFile("controlDict", true))() + IFstream(globControlDictFileName)() ); }