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 
00044 class ColumnDataWriter : public AbstractDataWriter
00045 {
00046 protected:
00047 
00048     OutputFileHandler mOutputFileHandler; 
00050     std::string mDirectory; 
00051     std::string mBaseName; 
00052     bool mIsInDefineMode; 
00053     bool mIsFixedDimensionSet; 
00054     bool mIsUnlimitedDimensionSet; 
00055     long mUnlimitedDimensionPosition; 
00056     long mFixedDimensionSize; 
00057     out_stream mpCurrentOutputFile; 
00058     out_stream mpCurrentAncillaryFile; 
00059     DataWriterVariable* mpUnlimitedDimensionVariable; 
00060     DataWriterVariable* mpFixedDimensionVariable; 
00062     std::string mUnlimitedDimensionName; 
00063     std::string mUnlimitedDimensionUnits; 
00065     std::string mFixedDimensionName; 
00066     std::string mFixedDimensionUnits; 
00068     std::vector<DataWriterVariable> mVariables; 
00070     const unsigned mFieldWidth; 
00071     const unsigned mPrecision; 
00072     static const int SPACING = 2; 
00073     static const int FIXED_DIMENSION_VAR_ID = -1; 
00074     static const int UNLIMITED_DIMENSION_VAR_ID = -2; 
00076     std::string mFileExtension; 
00078     int mRowStartPosition; 
00079     int mRowWidth; 
00081     int mAncillaryRowStartPosition; 
00082     int mAncillaryRowWidth; 
00084     bool mHasPutVariable; 
00085     bool mNeedAdvanceAlongUnlimitedDimension; 
00091     std::string mCommentForInfoFile;
00092 
00098     void CreateFixedDimensionFile(const std::string& rFileName);
00099 
00105     void CreateInfoFile(const std::string& rFileName);
00106 
00112     void CheckVariableName(const std::string& rName);
00113 
00119     void CheckUnitsName(const std::string& rName);
00120 
00125     void DoAdvanceAlongUnlimitedDimension();
00126 
00127 public:
00128 
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 
00190     void SetCommentForInfoFile(std::string comment)
00191     {
00192         mCommentForInfoFile = comment;
00193     }
00194 
00198     virtual void EndDefineMode();
00199 
00203     virtual void AdvanceAlongUnlimitedDimension();
00204 
00213     virtual void PutVariable(int variableID, double variableValue, long dimensionPosition = -1);
00214 
00218     virtual void Close();
00219 
00223     std::string GetOutputDirectory();
00224 };
00225 
00226 #endif //COLUMNDATAWRITER_HPP_
Generated on Thu Dec 22 13:00:07 2011 for Chaste by  doxygen 1.6.3