regIOobjectRead.C
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 #include "regIOobject.H"
00028 #include "IFstream.H"
00029 #include "Time.H"
00030 #include "PstreamReduceOps.H"
00031
00032
00033
00034
00035 Foam::Istream& Foam::regIOobject::readStream()
00036 {
00037 if (IFstream::debug)
00038 {
00039 Info<< "regIOobject::readStream() : "
00040 << "reading object " << name()
00041 << " from file " << objectPath()
00042 << endl;
00043 }
00044
00045 if (readOpt() == NO_READ)
00046 {
00047 FatalErrorIn("regIOobject::readStream()")
00048 << "NO_READ specified for read-constructor of object " << name()
00049 << " of class " << headerClassName()
00050 << abort(FatalError);
00051 }
00052
00053
00054 if (!isPtr_)
00055 {
00056 if (!(isPtr_ = objectStream()))
00057 {
00058 FatalIOError
00059 (
00060 "regIOobject::readStream()",
00061 __FILE__,
00062 __LINE__,
00063 objectPath(),
00064 0
00065 ) << "cannot open file"
00066 << exit(FatalIOError);
00067 }
00068 else if (!readHeader(*isPtr_))
00069 {
00070 FatalIOErrorIn("regIOobject::readStream()", *isPtr_)
00071 << "problem while reading header for object " << name()
00072 << exit(FatalIOError);
00073 }
00074 }
00075
00076 if (!lastModified_)
00077 {
00078 lastModified_ = lastModified(filePath());
00079 }
00080
00081 return *isPtr_;
00082 }
00083
00084
00085 Foam::Istream& Foam::regIOobject::readStream(const word& expectName)
00086 {
00087 if (IFstream::debug)
00088 {
00089 Info<< "regIOobject::readStream(const word&) : "
00090 << "reading object " << name()
00091 << " from file " << objectPath()
00092 << endl;
00093 }
00094
00095
00096 if (!isPtr_)
00097 {
00098 readStream();
00099
00100
00101
00102
00103 if
00104 (
00105 expectName.size()
00106 && headerClassName() != expectName
00107 && headerClassName() != "dictionary"
00108 )
00109 {
00110 FatalIOErrorIn("regIOobject::readStream(const word&)", *isPtr_)
00111 << "unexpected class name " << headerClassName()
00112 << " expected " << expectName << endl
00113 << " while reading object " << name()
00114 << exit(FatalIOError);
00115 }
00116 }
00117
00118 return *isPtr_;
00119 }
00120
00121
00122 void Foam::regIOobject::close()
00123 {
00124 if (IFstream::debug)
00125 {
00126 Info<< "regIOobject::close() : "
00127 << "finished reading " << filePath()
00128 << endl;
00129 }
00130
00131 if (isPtr_)
00132 {
00133 delete isPtr_;
00134 isPtr_ = NULL;
00135 }
00136 }
00137
00138
00139 bool Foam::regIOobject::readData(Istream&)
00140 {
00141 return false;
00142 }
00143
00144
00145 bool Foam::regIOobject::read()
00146 {
00147 bool ok = readData(readStream(type()));
00148 close();
00149 return ok;
00150 }
00151
00152
00153 bool Foam::regIOobject::modified() const
00154 {
00155 return
00156 (
00157 lastModified_
00158 && lastModified(filePath()) > (lastModified_ + fileModificationSkew)
00159 );
00160 }
00161
00162
00163 bool Foam::regIOobject::readIfModified()
00164 {
00165 if (lastModified_)
00166 {
00167 time_t newTimeStamp = lastModified(filePath());
00168
00169 bool readFile = false;
00170
00171 if (newTimeStamp > (lastModified_ + fileModificationSkew))
00172 {
00173 readFile = true;
00174 }
00175
00176 if (Pstream::parRun())
00177 {
00178 bool readFileOnThisProc = readFile;
00179 reduce(readFile, andOp<bool>());
00180
00181 if (readFileOnThisProc && !readFile)
00182 {
00183 WarningIn("regIOobject::readIfModified()")
00184 << "Delaying reading " << name()
00185 << " of class " << headerClassName()
00186 << " due to inconsistent "
00187 "file time-stamps between processors"
00188 << endl;
00189 }
00190 }
00191
00192 if (readFile)
00193 {
00194 lastModified_ = newTimeStamp;
00195 Info<< "regIOobject::readIfModified() : " << nl
00196 << " Reading object " << name()
00197 << " from file " << filePath() << endl;
00198 return read();
00199 }
00200 else
00201 {
00202 return false;
00203 }
00204 }
00205 else
00206 {
00207 return false;
00208 }
00209 }
00210
00211
00212
Copyright © 2000-2009 OpenCFD Ltd