OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

IOobjectReadHeader.C

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software; you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM; if not, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 \*---------------------------------------------------------------------------*/
00026 
00027 #include "IOobject.H"
00028 #include "dictionary.H"
00029 
00030 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00031 
00032 bool Foam::IOobject::readHeader(Istream& is)
00033 {
00034     if (IOobject::debug)
00035     {
00036         Info<< "IOobject::readHeader(Istream&) : reading header for file "
00037             << is.name() << endl;
00038     }
00039 
00040     // Check Istream not already bad
00041     if (!is.good())
00042     {
00043         if (rOpt_ == MUST_READ)
00044         {
00045             FatalIOErrorIn("IOobject::readHeader(Istream&)", is)
00046                 << " stream not open for reading essential object from file "
00047                 << is.name()
00048                 << exit(FatalIOError);
00049         }
00050 
00051         if (IOobject::debug)
00052         {
00053             SeriousIOErrorIn("IOobject::readHeader(Istream&)", is)
00054                 << " stream not open for reading from file "
00055                 << is.name() << endl;
00056         }
00057 
00058         return false;
00059     }
00060 
00061     token firstToken(is);
00062 
00063     if
00064     (
00065         is.good()
00066      && firstToken.isWord()
00067      && firstToken.wordToken() == "FoamFile"
00068     )
00069     {
00070         dictionary headerDict(is);
00071 
00072         is.version(headerDict.lookup("version"));
00073         is.format(headerDict.lookup("format"));
00074         headerClassName_ = word(headerDict.lookup("class"));
00075 
00076         word headerObject(headerDict.lookup("object"));
00077         if (IOobject::debug && headerObject != name())
00078         {
00079             IOWarningIn("IOobject::readHeader(Istream&)", is)
00080                 << " object renamed from "
00081                 << name() << " to " << headerObject
00082                 << " for file " << is.name() << endl;
00083         }
00084 
00085         // The note entry is optional
00086         headerDict.readIfPresent("note", note_);
00087     }
00088     else
00089     {
00090         SeriousIOErrorIn("IOobject::readHeader(Istream&)", is)
00091             << "First token could not be read or is not the keyword 'FoamFile'"
00092             << nl << nl << "Check header is of the form:" << nl << endl;
00093 
00094         writeHeader(SeriousError);
00095 
00096         return false;
00097     }
00098 
00099     // Check stream is still OK
00100     if (is.good())
00101     {
00102         objState_ = GOOD;
00103     }
00104     else
00105     {
00106         if (rOpt_ == MUST_READ)
00107         {
00108             FatalIOErrorIn("IOobject::readHeader(Istream&)", is)
00109                 << " stream failure while reading header"
00110                 << " on line " << is.lineNumber()
00111                 << " of file " << is.name()
00112                 << " for essential object" << name()
00113                 << exit(FatalIOError);
00114         }
00115 
00116         if (IOobject::debug)
00117         {
00118             Info<< "IOobject::readHeader(Istream&) :"
00119                 << " stream failure while reading header"
00120                 << " on line " << is.lineNumber()
00121                 << " of file " << is.name() << endl;
00122         }
00123 
00124         objState_ = BAD;
00125 
00126         return false;
00127     }
00128 
00129     if (IOobject::debug)
00130     {
00131         Info<< " .... read" << endl;
00132     }
00133 
00134     return true;
00135 }
00136 
00137 
00138 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd