ColumnDataWriter.hpp

00001 /*
00002 
00003 Copyright (C) University of Oxford, 2005-2011
00004 
00005 University of Oxford means the Chancellor, Masters and Scholars of the
00006 University of Oxford, having an administrative office at Wellington
00007 Square, Oxford OX1 2JD, UK.
00008 
00009 This file is part of Chaste.
00010 
00011 Chaste is free software: you can redistribute it and/or modify it
00012 under the terms of the GNU Lesser General Public License as published
00013 by the Free Software Foundation, either version 2.1 of the License, or
00014 (at your option) any later version.
00015 
00016 Chaste 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 Lesser General Public
00019 License for more details. The offer of Chaste under the terms of the
00020 License is subject to the License being interpreted in accordance with
00021 English Law and subject to any action against the University of Oxford
00022 being under the jurisdiction of the English Courts.
00023 
00024 You should have received a copy of the GNU Lesser General Public License
00025 along with Chaste. If not, see <http://www.gnu.org/licenses/>.
00026 
00027 */
00028 
00029 #ifndef COLUMNDATAWRITER_HPP_
00030 #define COLUMNDATAWRITER_HPP_
00031 
00032 #include <string>
00033 #include <vector>
00034 
00035 #include "AbstractDataWriter.hpp"
00036 #include "DataWriterVariable.hpp"
00037 #include "OutputFileHandler.hpp"
00038 
00039 
00045 class ColumnDataWriter : public AbstractDataWriter
00046 {
00047 protected:
00048 
00049     OutputFileHandler mOutputFileHandler; 
00051     std::string mDirectory; 
00052     std::string mBaseName; 
00053     bool mIsInDefineMode; 
00054     bool mIsFixedDimensionSet; 
00055     bool mIsUnlimitedDimensionSet; 
00056     long mUnlimitedDimensionPosition; 
00057     long mFixedDimensionSize; 
00058     out_stream mpCurrentOutputFile; 
00059     out_stream mpCurrentAncillaryFile; 
00060     DataWriterVariable* mpUnlimitedDimensionVariable; 
00061     DataWriterVariable* mpFixedDimensionVariable; 
00063     std::string mUnlimitedDimensionName; 
00064     std::string mUnlimitedDimensionUnits; 
00066     std::string mFixedDimensionName; 
00067     std::string mFixedDimensionUnits; 
00069     std::vector<DataWriterVariable> mVariables; 
00071     const unsigned mFieldWidth; 
00072     const unsigned mPrecision; 
00073     static const int SPACING = 2; 
00074     static const int FIXED_DIMENSION_VAR_ID = -1; 
00075     static const int UNLIMITED_DIMENSION_VAR_ID = -2; 
00077     std::string mFileExtension; 
00079     int mRowStartPosition; 
00080     int mRowWidth; 
00082     int mAncillaryRowStartPosition; 
00083     int mAncillaryRowWidth; 
00085     bool mHasPutVariable; 
00086     bool mNeedAdvanceAlongUnlimitedDimension; 
00092     std::string mCommentForInfoFile;
00093 
00099     void CreateFixedDimensionFile(const std::string& rFileName);
00100 
00106     void CreateInfoFile(const std::string& rFileName);
00107 
00113     void CheckVariableName(const std::string& rName);
00114 
00120     void CheckUnitsName(const std::string& rName);
00121 
00126     void DoAdvanceAlongUnlimitedDimension();
00127 
00128 public:
00139     ColumnDataWriter(const std::string& rDirectory,
00140                      const std::string& rBaseName,
00141                      bool cleanDirectory=true,
00142                      unsigned precision=8);
00143 
00147     virtual ~ColumnDataWriter();
00148 
00157     int DefineUnlimitedDimension(const std::string& rDimensionName,
00158                                  const std::string& rDimensionUnits);
00159 
00169     int DefineFixedDimension(const std::string& rDimensionName,
00170                              const std::string& rDimensionUnits,
00171                              long dimensionSize);
00172 
00181     int DefineVariable(const std::string& rVariableName,
00182                        const std::string& rVariableUnits);
00183 
00184 
00190     void SetCommentForInfoFile(std::string comment)
00191     {
00192         mCommentForInfoFile = comment;
00193     }
00194 
00195 
00199     virtual void EndDefineMode();
00200 
00204     virtual void AdvanceAlongUnlimitedDimension();
00205 
00214     virtual void PutVariable(int variableID, double variableValue, long dimensionPosition = -1);
00215 
00219     virtual void Close();
00220 
00224     std::string GetOutputDirectory();
00225 };
00226 
00227 #endif //COLUMNDATAWRITER_HPP_

Generated on Tue May 31 14:31:42 2011 for Chaste by  doxygen 1.5.5