Home
Downloads
Documentation
Installation
User Guide
man-pages
API Documentation
README
Release Notes
Changes
License
Support
SourceForge Project
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Pages
src
OpenFOAM
db
IOobject
IOobjectReadHeader.C
Go to the documentation of this file.
1
/*---------------------------------------------------------------------------*\
2
========= |
3
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4
\\ / O peration |
5
\\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
6
\\/ M anipulation |
7
-------------------------------------------------------------------------------
8
License
9
This file is part of OpenFOAM.
10
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
13
the Free Software Foundation, either version 3 of the License, or
14
(at your option) any later version.
15
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.
20
21
You should have received a copy of the GNU General Public License
22
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23
24
\*---------------------------------------------------------------------------*/
25
26
#include "
IOobject.H
"
27
#include <
OpenFOAM/dictionary.H
>
28
29
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
30
31
bool
Foam::IOobject::readHeader
(
Istream
& is)
32
{
33
if
(IOobject::debug)
34
{
35
Info
<<
"IOobject::readHeader(Istream&) : reading header for file "
36
<< is.
name
() <<
endl
;
37
}
38
39
// Check Istream not already bad
40
if
(!is.
good
())
41
{
42
if
(rOpt_ ==
MUST_READ
)
43
{
44
FatalIOErrorIn
(
"IOobject::readHeader(Istream&)"
, is)
45
<<
" stream not open for reading essential object from file "
46
<< is.
name
()
47
<<
exit
(
FatalIOError
);
48
}
49
50
if
(IOobject::debug)
51
{
52
SeriousIOErrorIn
(
"IOobject::readHeader(Istream&)"
, is)
53
<<
" stream not open for reading from file "
54
<< is.
name
() <<
endl
;
55
}
56
57
return
false
;
58
}
59
60
token
firstToken(is);
61
62
if
63
(
64
is.
good
()
65
&& firstToken.
isWord
()
66
&& firstToken.
wordToken
() ==
"FoamFile"
67
)
68
{
69
dictionary
headerDict(is);
70
71
is.
version
(headerDict.
lookup
(
"version"
));
72
is.
format
(headerDict.
lookup
(
"format"
));
73
headerClassName_ =
word
(headerDict.
lookup
(
"class"
));
74
75
word
headerObject(headerDict.
lookup
(
"object"
));
76
if
(IOobject::debug && headerObject !=
name
())
77
{
78
IOWarningIn
(
"IOobject::readHeader(Istream&)"
, is)
79
<<
" object renamed from "
80
<<
name
() <<
" to "
<< headerObject
81
<<
" for file "
<< is.
name
() <<
endl
;
82
}
83
84
// The note entry is optional
85
headerDict.
readIfPresent
(
"note"
, note_);
86
}
87
else
88
{
89
SeriousIOErrorIn
(
"IOobject::readHeader(Istream&)"
, is)
90
<<
"First token could not be read or is not the keyword 'FoamFile'"
91
<<
nl
<<
nl
<<
"Check header is of the form:"
<<
nl
<<
endl
;
92
93
writeHeader
(
Info
);
94
95
return
false
;
96
}
97
98
// Check stream is still OK
99
if
(is.
good
())
100
{
101
objState_ =
GOOD
;
102
}
103
else
104
{
105
if
(rOpt_ ==
MUST_READ
)
106
{
107
FatalIOErrorIn
(
"IOobject::readHeader(Istream&)"
, is)
108
<<
" stream failure while reading header"
109
<<
" on line "
<< is.
lineNumber
()
110
<<
" of file "
<< is.
name
()
111
<<
" for essential object"
<<
name
()
112
<<
exit
(
FatalIOError
);
113
}
114
115
if
(IOobject::debug)
116
{
117
Info
<<
"IOobject::readHeader(Istream&) :"
118
<<
" stream failure while reading header"
119
<<
" on line "
<< is.
lineNumber
()
120
<<
" of file "
<< is.
name
() <<
endl
;
121
}
122
123
objState_ =
BAD
;
124
125
return
false
;
126
}
127
128
if
(IOobject::debug)
129
{
130
Info
<<
" .... read"
<<
endl
;
131
}
132
133
return
true
;
134
}
135
136
137
// ************************ vim: set sw=4 sts=4 et: ************************ //