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

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