00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
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
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