ColumnDataWriter.hpp

00001 /*
00002 
00003 Copyright (C) University of Oxford, 2005-2009
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  * Concrete DataWriter class. Writes grid-formatted data in space separated column form.
00030  * Each file has a header row with names and optional units for each column.
00031  *
00032 */
00033 #ifndef COLUMNDATAWRITER_HPP
00034 #define COLUMNDATAWRITER_HPP
00035 
00036 #include "AbstractDataWriter.hpp"
00037 #include "DataWriterVariable.hpp"
00038 #include "OutputFileHandler.hpp"
00039 #include "Exception.hpp"
00040 
00041 #include <string>
00042 #include <fstream>
00043 #include <iostream>
00044 #include <sstream>
00045 #include <iomanip>
00046 #include <cassert>
00047 #include <ctype.h>
00048 //#include <sys/stat.h> // For chmod()
00049 
00050 const int FILE_SUFFIX_WIDTH = 6;
00051 
00052 
00053 class ColumnDataWriter : public AbstractDataWriter
00054 {
00055 protected:
00056     OutputFileHandler mOutputFileHandler; 
00057 
00058     std::string mDirectory; 
00059     std::string mBaseName; 
00060     bool mIsInDefineMode; 
00061     bool mIsFixedDimensionSet; 
00062     bool mIsUnlimitedDimensionSet; 
00063     long mUnlimitedDimensionPosition; 
00064     long mFixedDimensionSize; 
00065     out_stream mpCurrentOutputFile; 
00066     out_stream mpCurrentAncillaryFile; 
00067     DataWriterVariable *mpUnlimitedDimensionVariable; 
00068     DataWriterVariable *mpFixedDimensionVariable; 
00070     std::string mUnlimitedDimensionName; 
00071     std::string mUnlimitedDimensionUnits; 
00073     std::string mFixedDimensionName; 
00074     std::string mFixedDimensionUnits; 
00076     std::vector<DataWriterVariable> mVariables; 
00078     static const int FIELD_WIDTH = 10; 
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;
00093 
00094     void CreateFixedDimensionFile(std::string filepath);
00095 
00096     void CreateInfoFile(std::string filepath);
00097 
00098     void CheckVariableName(std::string name); 
00099     void CheckUnitsName(std::string name); 
00100     void DoAdvanceAlongUnlimitedDimension();
00101 
00102 public:
00103 
00104     ColumnDataWriter(std::string directory, std::string baseName, bool cleanDirectory=true);
00105     virtual ~ColumnDataWriter();
00106     int DefineUnlimitedDimension(std::string dimensionName, std::string dimensionUnits);
00107     int DefineFixedDimension(std::string dimensionName, std::string dimensionUnits, long dimensionSize);
00108     int DefineVariable(std::string variableName, std::string variableUnits);
00109     virtual void EndDefineMode();
00110     virtual void AdvanceAlongUnlimitedDimension();
00111 
00112     virtual void PutVariable(int variableID, double variableValue, long dimensionPosition = -1);
00113     virtual void Close();
00114 
00115     std::string GetOutputDirectory(void);
00116 };
00117 
00118 #endif

Generated on Wed Mar 18 12:51:52 2009 for Chaste by  doxygen 1.5.5