openfoam/applications/utilities/postProcessing/dataConversion/foamToEnsightParts/getTimeIndex.H
Mark Olesen 784461b2fa ENH: make search of instances in IOobject::typeHeaderOk optional (issue #245)
- in specific cases it can be useful to suppress searching the instances.
  For example, if one only wishes to check if a "points" is available at
  the given time instance, without searching backwards through all
  times.
2016-11-21 14:28:40 +01:00

44 lines
1.0 KiB
C

// Read time index from */uniform/time, but treat 0 and constant specially
// or simply increment from the '-index' option if it was supplied
label timeIndex = 0;
if (optIndex)
{
timeIndex = indexingNumber++;
}
else if
(
runTime.timeName() != runTime.constant()
&& runTime.timeName() != "0"
)
{
IOobject io
(
"time",
runTime.timeName(),
"uniform",
runTime,
IOobject::READ_IF_PRESENT,
IOobject::NO_WRITE,
false // no register
);
if (io.typeHeaderOk<IOdictionary>(true, false))
{
io.readOpt() = IOobject::MUST_READ_IF_MODIFIED;
IOdictionary timeObject(io);
timeObject.lookup("index") >> timeIndex;
}
else
{
Info<< "skip ... missing entry " << io.objectPath() << endl;
continue;
}
}
Info<< nl << "Time [" << timeIndex << "] = " << runTime.timeName() << nl;
// end-of-file