1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
11 OpenFOAM is free software; you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by the
13 Free Software Foundation; either version 2 of the License, or (at your
14 option) any later version.
16 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM; if not, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
27 #include "regIOobject.H"
28 #include <OpenFOAM/IFstream.H>
29 #include <OpenFOAM/Time.H>
30 #include <OpenFOAM/PstreamReduceOps.H>
33 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
35 Foam::Istream& Foam::regIOobject::readStream()
39 Info<< "regIOobject::readStream() : "
40 << "reading object " << name()
41 << " from file " << objectPath()
45 if (readOpt() == NO_READ)
47 FatalErrorIn("regIOobject::readStream()")
48 << "NO_READ specified for read-constructor of object " << name()
49 << " of class " << headerClassName()
53 // Construct object stream and read header if not already constructed
56 if (!(isPtr_ = objectStream()))
60 "regIOobject::readStream()",
65 ) << "cannot open file"
66 << exit(FatalIOError);
68 else if (!readHeader(*isPtr_))
70 FatalIOErrorIn("regIOobject::readStream()", *isPtr_)
71 << "problem while reading header for object " << name()
72 << exit(FatalIOError);
78 lastModified_ = lastModified(filePath());
85 Foam::Istream& Foam::regIOobject::readStream(const word& expectName)
89 Info<< "regIOobject::readStream(const word&) : "
90 << "reading object " << name()
91 << " from file " << objectPath()
95 // Construct IFstream if not already constructed
100 // Check the className of the regIOobject
101 // dictionary is an allowable name in case the actual class
102 // instantiated is a dictionary
106 && headerClassName() != expectName
107 && headerClassName() != "dictionary"
110 FatalIOErrorIn("regIOobject::readStream(const word&)", *isPtr_)
111 << "unexpected class name " << headerClassName()
112 << " expected " << expectName << endl
113 << " while reading object " << name()
114 << exit(FatalIOError);
122 void Foam::regIOobject::close()
126 Info<< "regIOobject::close() : "
127 << "finished reading " << filePath()
139 bool Foam::regIOobject::readData(Istream&)
145 bool Foam::regIOobject::read()
147 bool ok = readData(readStream(type()));
153 bool Foam::regIOobject::modified() const
158 && lastModified(filePath()) > (lastModified_ + fileModificationSkew)
163 bool Foam::regIOobject::readIfModified()
167 time_t newTimeStamp = lastModified(filePath());
169 bool readFile = false;
171 if (newTimeStamp > (lastModified_ + fileModificationSkew))
176 if (Pstream::parRun())
178 bool readFileOnThisProc = readFile;
179 reduce(readFile, andOp<bool>());
181 if (readFileOnThisProc && !readFile)
183 WarningIn("regIOobject::readIfModified()")
184 << "Delaying reading " << name()
185 << " of class " << headerClassName()
186 << " due to inconsistent "
187 "file time-stamps between processors"
194 lastModified_ = newTimeStamp;
195 Info<< "regIOobject::readIfModified() : " << nl
196 << " Reading object " << name()
197 << " from file " << filePath() << endl;
212 // ************************ vim: set sw=4 sts=4 et: ************************ //