Chaste Release::3.1
ColumnDataWriter.hpp
00001 /*
00002 
00003 Copyright (c) 2005-2012, University of Oxford.
00004 All rights reserved.
00005 
00006 University of Oxford means the Chancellor, Masters and Scholars of the
00007 University of Oxford, having an administrative office at Wellington
00008 Square, Oxford OX1 2JD, UK.
00009 
00010 This file is part of Chaste.
00011 
00012 Redistribution and use in source and binary forms, with or without
00013 modification, are permitted provided that the following conditions are met:
00014  * Redistributions of source code must retain the above copyright notice,
00015    this list of conditions and the following disclaimer.
00016  * Redistributions in binary form must reproduce the above copyright notice,
00017    this list of conditions and the following disclaimer in the documentation
00018    and/or other materials provided with the distribution.
00019  * Neither the name of the University of Oxford nor the names of its
00020    contributors may be used to endorse or promote products derived from this
00021    software without specific prior written permission.
00022 
00023 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00024 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00025 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00026 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
00027 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00028 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
00029 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00030 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00031 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
00032 OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00033 
00034 */
00035 
00036 #ifndef COLUMNDATAWRITER_HPP_
00037 #define COLUMNDATAWRITER_HPP_
00038 
00039 #include <string>
00040 #include <vector>
00041 
00042 #include "AbstractDataWriter.hpp"
00043 #include "DataWriterVariable.hpp"
00044 #include "OutputFileHandler.hpp"
00045 
00051 class ColumnDataWriter : public AbstractDataWriter
00052 {
00053 protected:
00054 
00055     OutputFileHandler mOutputFileHandler; 
00057     std::string mDirectory; 
00058     std::string mBaseName; 
00059     bool mIsInDefineMode; 
00060     bool mIsFixedDimensionSet; 
00061     bool mIsUnlimitedDimensionSet; 
00062     long mUnlimitedDimensionPosition; 
00063     long mFixedDimensionSize; 
00064     out_stream mpCurrentOutputFile; 
00065     out_stream mpCurrentAncillaryFile; 
00066     DataWriterVariable* mpUnlimitedDimensionVariable; 
00067     DataWriterVariable* mpFixedDimensionVariable; 
00069     std::string mUnlimitedDimensionName; 
00070     std::string mUnlimitedDimensionUnits; 
00072     std::string mFixedDimensionName; 
00073     std::string mFixedDimensionUnits; 
00075     std::vector<DataWriterVariable> mVariables; 
00077     const unsigned mFieldWidth; 
00078     const unsigned mPrecision; 
00079     static const int SPACING = 2; 
00080     static const int FIXED_DIMENSION_VAR_ID = -1; 
00081     static const int UNLIMITED_DIMENSION_VAR_ID = -2; 
00083     std::string mFileExtension; 
00085     int mRowStartPosition; 
00086     int mRowWidth; 
00088     int mAncillaryRowStartPosition; 
00089     int mAncillaryRowWidth; 
00091     bool mHasPutVariable; 
00092     bool mNeedAdvanceAlongUnlimitedDimension; 
00098     std::string mCommentForInfoFile;
00099 
00105     void CreateFixedDimensionFile(const std::string& rFileName);
00106 
00112     void CreateInfoFile(const std::string& rFileName);
00113 
00119     void CheckVariableName(const std::string& rName);
00120 
00126     void CheckUnitsName(const std::string& rName);
00127 
00132     void DoAdvanceAlongUnlimitedDimension();
00133 
00134 public:
00135 
00146     ColumnDataWriter(const std::string& rDirectory,
00147                      const std::string& rBaseName,
00148                      bool cleanDirectory=true,
00149                      unsigned precision=8);
00150 
00154     virtual ~ColumnDataWriter();
00155 
00164     int DefineUnlimitedDimension(const std::string& rDimensionName,
00165                                  const std::string& rDimensionUnits);
00166 
00176     int DefineFixedDimension(const std::string& rDimensionName,
00177                              const std::string& rDimensionUnits,
00178                              long dimensionSize);
00179 
00188     int DefineVariable(const std::string& rVariableName,
00189                        const std::string& rVariableUnits);
00190 
00197     void SetCommentForInfoFile(std::string comment)
00198     {
00199         mCommentForInfoFile = comment;
00200     }
00201 
00205     virtual void EndDefineMode();
00206 
00210     virtual void AdvanceAlongUnlimitedDimension();
00211 
00220     virtual void PutVariable(int variableID, double variableValue, long dimensionPosition = -1);
00221 
00225     virtual void Close();
00226 
00230     std::string GetOutputDirectory();
00231 };
00232 
00233 #endif //COLUMNDATAWRITER_HPP_