Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #include "Time.H"
00033 #include <OpenFOAM/IOobject.H>
00034
00035
00036
00037 Foam::word Foam::Time::findInstance
00038 (
00039 const fileName& dir,
00040 const word& name,
00041 const IOobject::readOption rOpt,
00042 const word& stopInstance
00043 ) const
00044 {
00045
00046
00047
00048 if
00049 (
00050 name.empty()
00051 ? isDir(path()/timeName()/dir)
00052 :
00053 (
00054 isFile(path()/timeName()/dir/name)
00055 && IOobject(name, timeName(), dir, *this).headerOk()
00056 )
00057 )
00058 {
00059 if (debug)
00060 {
00061 Info<< "Time::findInstance"
00062 "(const fileName&, const word&, const IOobject::readOption)"
00063 << " : found \"" << name
00064 << "\" in " << timeName()/dir
00065 << endl;
00066 }
00067
00068 return timeName();
00069 }
00070
00071
00072
00073
00074 instantList ts = times();
00075 label instanceI;
00076
00077 for (instanceI = ts.size()-1; instanceI >= 0; --instanceI)
00078 {
00079 if (ts[instanceI].value() <= timeOutputValue())
00080 {
00081 break;
00082 }
00083 }
00084
00085
00086 for (; instanceI >= 0; --instanceI)
00087 {
00088 if
00089 (
00090 name.empty()
00091 ? isDir(path()/ts[instanceI].name()/dir)
00092 :
00093 (
00094 isFile(path()/ts[instanceI].name()/dir/name)
00095 && IOobject(name, ts[instanceI].name(), dir, *this).headerOk()
00096 )
00097 )
00098 {
00099 if (debug)
00100 {
00101 Info<< "Time::findInstance"
00102 "(const fileName&, const word&, const IOobject::readOption)"
00103 << " : found \"" << name
00104 << "\" in " << ts[instanceI].name()/dir
00105 << endl;
00106 }
00107
00108 return ts[instanceI].name();
00109 }
00110
00111
00112 if (ts[instanceI].name() == stopInstance)
00113 {
00114 if (debug)
00115 {
00116 Info<< "Time::findInstance"
00117 "(const fileName&, const word&"
00118 ", const IOobject::readOption, const word&)"
00119 << " : hit stopInstance " << stopInstance
00120 << endl;
00121 }
00122
00123 if (rOpt == IOobject::MUST_READ)
00124 {
00125 FatalErrorIn
00126 (
00127 "Time::findInstance"
00128 "(const fileName&, const word&"
00129 ", const IOobject::readOption, const word&)"
00130 ) << "Cannot find file \"" << name << "\" in directory "
00131 << dir << " in times " << timeName()
00132 << " down to " << stopInstance
00133 << exit(FatalError);
00134 }
00135
00136 return ts[instanceI].name();
00137 }
00138 }
00139
00140
00141
00142
00143
00144
00145
00146 if
00147 (
00148 name.empty()
00149 ? isDir(path()/constant()/dir)
00150 :
00151 (
00152 isFile(path()/constant()/dir/name)
00153 && IOobject(name, constant(), dir, *this).headerOk()
00154 )
00155 )
00156 {
00157 if (debug)
00158 {
00159 Info<< "Time::findInstance"
00160 "(const fileName&, const word&, const IOobject::readOption)"
00161 << " : found \"" << name
00162 << "\" in " << constant()/dir
00163 << endl;
00164 }
00165
00166 return constant();
00167 }
00168
00169 if (rOpt == IOobject::MUST_READ)
00170 {
00171 FatalErrorIn
00172 (
00173 "Time::findInstance"
00174 "(const fileName&, const word&, const IOobject::readOption)"
00175 ) << "Cannot find file \"" << name << "\" in directory "
00176 << dir << " in times " << timeName()
00177 << " down to " << constant()
00178 << exit(FatalError);
00179 }
00180
00181 return constant();
00182 }
00183
00184
00185