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

regIOobjectWrite.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 Description
00026     write function for regIOobjects
00027 
00028 \*---------------------------------------------------------------------------*/
00029 
00030 #include "regIOobject.H"
00031 #include "Time.H"
00032 #include "OSspecific.H"
00033 #include "OFstream.H"
00034 
00035 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00036 
00037 bool Foam::regIOobject::writeObject
00038 (
00039     IOstream::streamFormat fmt,
00040     IOstream::versionNumber ver,
00041     IOstream::compressionType cmp
00042 ) const
00043 {
00044     if (!good())
00045     {
00046         SeriousErrorIn("regIOobject::write()")
00047             << "bad object " << name()
00048             << endl;
00049 
00050         return false;
00051     }
00052 
00053     if (instance().empty())
00054     {
00055         SeriousErrorIn("regIOobject::write()")
00056             << "instance undefined for object " << name()
00057             << endl;
00058 
00059         return false;
00060     }
00061 
00062     if
00063     (
00064         instance() != time().timeName()
00065      && instance() != time().system()
00066      && instance() != time().caseSystem()
00067      && instance() != time().constant()
00068      && instance() != time().caseConstant()
00069     )
00070     {
00071         const_cast<regIOobject&>(*this).instance() = time().timeName();
00072     }
00073 
00074     mkDir(path());
00075 
00076     if (OFstream::debug)
00077     {
00078         Info<< "regIOobject::write() : "
00079             << "writing file " << objectPath();
00080     }
00081 
00082 
00083     bool osGood = false;
00084 
00085     {
00086         // Try opening an OFstream for object
00087         OFstream os(objectPath(), fmt, ver, cmp);
00088 
00089         // If any of these fail, return (leave error handling to Ostream class)
00090         if (!os.good())
00091         {
00092             return false;
00093         }
00094 
00095         if (!writeHeader(os))
00096         {
00097             return false;
00098         }
00099 
00100         // Write the data to the Ostream
00101         if (!writeData(os))
00102         {
00103             return false;
00104         }
00105 
00106         writeEndDivider(os);
00107 
00108         osGood = os.good();
00109     }
00110 
00111     if (OFstream::debug)
00112     {
00113         Info<< " .... written" << endl;
00114     }
00115 
00116     // Only update the lastModified_ time if this object is re-readable,
00117     // i.e. lastModified_ is already set
00118     if (lastModified_)
00119     {
00120         lastModified_ = lastModified(objectPath());
00121     }
00122 
00123     return osGood;
00124 }
00125 
00126 
00127 bool Foam::regIOobject::write() const
00128 {
00129     return writeObject
00130     (
00131         time().writeFormat(),
00132         IOstream::currentVersion,
00133         time().writeCompression()
00134     );
00135 }
00136 
00137 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd