FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

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-2010 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
00013     the Free Software Foundation, either version 3 of the License, or
00014     (at your 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, see <http://www.gnu.org/licenses/>.
00023 
00024 \*---------------------------------------------------------------------------*/
00025 
00026 #include "IOobject.H"
00027 #include <OpenFOAM/dictionary.H>
00028 
00029 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00030 
00031 bool Foam::IOobject::readHeader(Istream& is)
00032 {
00033     if (IOobject::debug)
00034     {
00035         Info<< "IOobject::readHeader(Istream&) : reading header for file "
00036             << is.name() << endl;
00037     }
00038 
00039     // Check Istream not already bad
00040     if (!is.good())
00041     {
00042         if (rOpt_ == MUST_READ)
00043         {
00044             FatalIOErrorIn("IOobject::readHeader(Istream&)", is)
00045                 << " stream not open for reading essential object from file "
00046                 << is.name()
00047                 << exit(FatalIOError);
00048         }
00049 
00050         if (IOobject::debug)
00051         {
00052             SeriousIOErrorIn("IOobject::readHeader(Istream&)", is)
00053                 << " stream not open for reading from file "
00054                 << is.name() << endl;
00055         }
00056 
00057         return false;
00058     }
00059 
00060     token firstToken(is);
00061 
00062     if
00063     (
00064         is.good()
00065      && firstToken.isWord()
00066      && firstToken.wordToken() == "FoamFile"
00067     )
00068     {
00069         dictionary headerDict(is);
00070 
00071         is.version(headerDict.lookup("version"));
00072         is.format(headerDict.lookup("format"));
00073         headerClassName_ = word(headerDict.lookup("class"));
00074 
00075         word headerObject(headerDict.lookup("object"));
00076         if (IOobject::debug && headerObject != name())
00077         {
00078             IOWarningIn("IOobject::readHeader(Istream&)", is)
00079                 << " object renamed from "
00080                 << name() << " to " << headerObject
00081                 << " for file " << is.name() << endl;
00082         }
00083 
00084         // The note entry is optional
00085         headerDict.readIfPresent("note", note_);
00086     }
00087     else
00088     {
00089         SeriousIOErrorIn("IOobject::readHeader(Istream&)", is)
00090             << "First token could not be read or is not the keyword 'FoamFile'"
00091             << nl << nl << "Check header is of the form:" << nl << endl;
00092 
00093         writeHeader(Info);
00094 
00095         return false;
00096     }
00097 
00098     // Check stream is still OK
00099     if (is.good())
00100     {
00101         objState_ = GOOD;
00102     }
00103     else
00104     {
00105         if (rOpt_ == MUST_READ)
00106         {
00107             FatalIOErrorIn("IOobject::readHeader(Istream&)", is)
00108                 << " stream failure while reading header"
00109                 << " on line " << is.lineNumber()
00110                 << " of file " << is.name()
00111                 << " for essential object" << name()
00112                 << exit(FatalIOError);
00113         }
00114 
00115         if (IOobject::debug)
00116         {
00117             Info<< "IOobject::readHeader(Istream&) :"
00118                 << " stream failure while reading header"
00119                 << " on line " << is.lineNumber()
00120                 << " of file " << is.name() << endl;
00121         }
00122 
00123         objState_ = BAD;
00124 
00125         return false;
00126     }
00127 
00128     if (IOobject::debug)
00129     {
00130         Info<< " .... read" << endl;
00131     }
00132 
00133     return true;
00134 }
00135 
00136 
00137 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines