FreeFOAM The Cross-Platform CFD Toolkit
regIOobjectWrite.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 Description
25  write function for regIOobjects
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "regIOobject.H"
30 #include <OpenFOAM/Time.H>
31 #include <OpenFOAM/OSspecific.H>
32 #include <OpenFOAM/OFstream.H>
33 
34 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
35 
37 (
41 ) const
42 {
43  if (!good())
44  {
45  SeriousErrorIn("regIOobject::write()")
46  << "bad object " << name()
47  << endl;
48 
49  return false;
50  }
51 
52  if (instance().empty())
53  {
54  SeriousErrorIn("regIOobject::write()")
55  << "instance undefined for object " << name()
56  << endl;
57 
58  return false;
59  }
60 
61  if
62  (
63  instance() != time().timeName()
64  && instance() != time().system()
65  && instance() != time().caseSystem()
66  && instance() != time().constant()
67  && instance() != time().caseConstant()
68  )
69  {
70  const_cast<regIOobject&>(*this).instance() = time().timeName();
71  }
72 
73  mkDir(path());
74 
75  if (OFstream::debug)
76  {
77  Info<< "regIOobject::write() : "
78  << "writing file " << objectPath();
79  }
80 
81 
82  bool osGood = false;
83 
84  {
85  // Try opening an OFstream for object
86  OFstream os(objectPath(), fmt, ver, cmp);
87 
88  // If any of these fail, return (leave error handling to Ostream class)
89  if (!os.good())
90  {
91  return false;
92  }
93 
94  if (!writeHeader(os))
95  {
96  return false;
97  }
98 
99  // Write the data to the Ostream
100  if (!writeData(os))
101  {
102  return false;
103  }
104 
105  writeEndDivider(os);
106 
107  osGood = os.good();
108  }
109 
110  if (OFstream::debug)
111  {
112  Info<< " .... written" << endl;
113  }
114 
115  // Only update the lastModified_ time if this object is re-readable,
116  // i.e. lastModified_ is already set
117  if (lastModified_)
118  {
119  lastModified_ = lastModified(objectPath());
120  }
121 
122  return osGood;
123 }
124 
125 
127 {
128  return writeObject
129  (
130  time().writeFormat(),
132  time().writeCompression()
133  );
134 }
135 
136 // ************************ vim: set sw=4 sts=4 et: ************************ //