From d7b321bf864eb8ac0b771c4a5d94121470d46f9f Mon Sep 17 00:00:00 2001 From: mattijs <mattijs@hunt.opencfd.co.uk> Date: Fri, 6 Feb 2009 13:11:30 +0000 Subject: [PATCH] findInstance for directories --- src/OpenFOAM/db/Time/Time.H | 3 +- src/OpenFOAM/db/Time/findInstance.C | 55 +++++++++++++++++++---------- 2 files changed, 38 insertions(+), 20 deletions(-) diff --git a/src/OpenFOAM/db/Time/Time.H b/src/OpenFOAM/db/Time/Time.H index 2d5391990e6..4d3268423de 100644 --- a/src/OpenFOAM/db/Time/Time.H +++ b/src/OpenFOAM/db/Time/Time.H @@ -283,10 +283,11 @@ public: //- Return the location of "dir" containing the file "name". // (Used in reading mesh data) + // If name is null search for a directory "dir" word findInstance ( const fileName& dir, - const word& name, + const word& name = word::null, const IOobject::readOption rOpt = IOobject::MUST_READ ) const; diff --git a/src/OpenFOAM/db/Time/findInstance.C b/src/OpenFOAM/db/Time/findInstance.C index 348ad4ebe55..7b8bddd1202 100644 --- a/src/OpenFOAM/db/Time/findInstance.C +++ b/src/OpenFOAM/db/Time/findInstance.C @@ -23,7 +23,9 @@ License Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA Description - Return the location of "directory" containing the file "name". + If "name" is empty: return the location of "directory" + If "name" is not empty: return the location of "directory" containing the + file "name". Used in reading mesh data. \*---------------------------------------------------------------------------*/ @@ -43,15 +45,20 @@ Foam::word Foam::Time::findInstance // Is the mesh data in the current time directory ? if ( - file(path()/timeName()/dir/name) - && IOobject(name, timeName(), dir, *this).headerOk() + (name.empty() && Foam::dir(path()/timeName()/dir)) + || + ( + !name.empty() + && file(path()/timeName()/dir/name) + && IOobject(name, timeName(), dir, *this).headerOk() + ) ) { if (debug) { - Info<< "Time::findInstance(const word& dir, const word& name) : " - << "reading " << name - << " from " << timeName()/dir + Info<< "Time::findInstance(const word&, const word&) : " + << "found " << name + << " in " << timeName()/dir << endl; } @@ -81,16 +88,21 @@ Foam::word Foam::Time::findInstance { if ( - file(path()/ts[j].name()/dir/name) - && IOobject(name, ts[j].name(), dir, *this).headerOk() + (name.empty() && Foam::dir(path()/ts[j].name()/dir)) + || + ( + !name.empty() + && file(path()/ts[j].name()/dir/name) + && IOobject(name, ts[j].name(), dir, *this).headerOk() + ) ) { if (debug) { - Info<< "Time::findInstance(const word& dir, " - << "const word& name) : " - << "reading " << name - << " from " << ts[j].name()/dir + Info<< "Time::findInstance(const word&, " + << "const word&) : " + << "found " << name + << " in " << ts[j].name()/dir << endl; } @@ -109,16 +121,20 @@ Foam::word Foam::Time::findInstance if ( - file(path()/constant()/dir/name) - && IOobject(name, constant(), dir, *this).headerOk() + (name.empty() && Foam::dir(path()/constant()/dir)) + || ( + !name.empty() + && file(path()/constant()/dir/name) + && IOobject(name, constant(), dir, *this).headerOk() + ) ) { if (debug) { - Info<< "Time::findInstance(const word& dir, " - << "const word& name) : " - << "reading " << name - << " from " << constant()/dir + Info<< "Time::findInstance(const word&, " + << "const word&) : " + << "found " << name + << " in " << constant()/dir << endl; } @@ -127,7 +143,7 @@ Foam::word Foam::Time::findInstance if (rOpt == IOobject::MUST_READ) { - FatalErrorIn("Time::findInstance(const word& dir, const word& name)") + FatalErrorIn("Time::findInstance(const word&, const word&)") << "Cannot find file \"" << name << "\" in directory " << constant()/dir << exit(FatalError); @@ -136,4 +152,5 @@ Foam::word Foam::Time::findInstance return constant(); } + // ************************************************************************* // -- GitLab