initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / OpenFOAM / db / IOobject / IOobjectReadHeader.C
blob2816b40d59eb3b42800e10ea2bcdc21a32bf3a0c
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
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
19     for more details.
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 "IOobject.H"
28 #include "dictionary.H"
30 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
32 bool Foam::IOobject::readHeader(Istream& is)
34     if (IOobject::debug)
35     {
36         Info<< "IOobject::readHeader(Istream&) : reading header for file "
37             << is.name() << endl;
38     }
40     // Check Istream not already bad
41     if (!is.good())
42     {
43         if (rOpt_ == MUST_READ)
44         {
45             FatalIOErrorIn("IOobject::readHeader(Istream&)", is)
46                 << " stream not open for reading essential object from file "
47                 << is.name()
48                 << exit(FatalIOError);
49         }
51         if (IOobject::debug)
52         {
53             SeriousIOErrorIn("IOobject::readHeader(Istream&)", is)
54                 << " stream not open for reading from file "
55                 << is.name() << endl;
56         }
58         return false;
59     }
61     token firstToken(is);
63     if
64     (
65         is.good()
66      && firstToken.isWord()
67      && firstToken.wordToken() == "FoamFile"
68     )
69     {
70         dictionary headerDict(is);
72         is.version(headerDict.lookup("version"));
73         is.format(headerDict.lookup("format"));
74         headerClassName_ = word(headerDict.lookup("class"));
76         word headerObject(headerDict.lookup("object"));
77         if (IOobject::debug && headerObject != name())
78         {
79             IOWarningIn("IOobject::readHeader(Istream&)", is)
80                 << " object renamed from "
81                 << name() << " to " << headerObject
82                 << " for file " << is.name() << endl;
83         }
85         // The note entry is optional
86         headerDict.readIfPresent("note", note_);
87     }
88     else
89     {
90         SeriousIOErrorIn("IOobject::readHeader(Istream&)", is)
91             << "First token could not be read or is not the keyword 'FoamFile'"
92             << nl << nl << "Check header is of the form:" << nl << endl;
94         writeHeader(SeriousError);
96         return false;
97     }
99     // Check stream is still OK
100     if (is.good())
101     {
102         objState_ = GOOD;
103     }
104     else
105     {
106         if (rOpt_ == MUST_READ)
107         {
108             FatalIOErrorIn("IOobject::readHeader(Istream&)", is)
109                 << " stream failure while reading header"
110                 << " on line " << is.lineNumber()
111                 << " of file " << is.name()
112                 << " for essential object" << name()
113                 << exit(FatalIOError);
114         }
116         if (IOobject::debug)
117         {
118             Info<< "IOobject::readHeader(Istream&) :"
119                 << " stream failure while reading header"
120                 << " on line " << is.lineNumber()
121                 << " of file " << is.name() << endl;
122         }
124         objState_ = BAD;
126         return false;
127     }
129     if (IOobject::debug)
130     {
131         Info<< " .... read" << endl;
132     }
134     return true;
138 // ************************************************************************* //