SimpleDataWriter.cpp
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
00034
00035
00036 #include "SimpleDataWriter.hpp"
00037 #include "OutputFileHandler.hpp"
00038 #include "Exception.hpp"
00039
00040 SimpleDataWriter::SimpleDataWriter(const std::string& rDirectory,
00041 const std::string& rFileName,
00042 const std::vector<std::vector<double> >& rData,
00043 bool cleanDirectory)
00044 {
00045 if (rData.size() == 0)
00046 {
00047 EXCEPTION("Data vector is empty");
00048 }
00049
00050 for (unsigned i=0; i<rData.size(); i++)
00051 {
00052 if (rData[i].size() != rData[0].size())
00053 {
00054 EXCEPTION("Data vector sizes are not all equal");
00055 }
00056 }
00057
00058 OutputFileHandler output_file_handler(rDirectory, cleanDirectory);
00059 out_stream p_file = output_file_handler.OpenOutputFile(rFileName);
00060
00061 for (unsigned j=0; j<rData[0].size(); j++)
00062 {
00063 for (unsigned i=0; i<rData.size(); i++)
00064 {
00065 (*p_file) << rData[i][j] << "\t";
00066 }
00067 (*p_file) << "\n";
00068 }
00069 p_file->close();
00070 }
00071
00072 SimpleDataWriter::SimpleDataWriter(const std::string& rDirectory,
00073 const std::string& rFileName,
00074 const std::vector<double>& rT,
00075 const std::vector<double>& rX,
00076 bool cleanDirectory)
00077 {
00078 std::vector<std::vector<double> > data;
00079 data.push_back(rT);
00080 data.push_back(rX);
00081 SimpleDataWriter(rDirectory, rFileName, data, cleanDirectory);
00082 }
00083
00084 SimpleDataWriter::SimpleDataWriter(const std::string& rDirectory,
00085 const std::string& rFileName,
00086 const std::vector<double>& rData,
00087 bool cleanDirectory)
00088 {
00089 std::vector<std::vector<double> > data;
00090 data.push_back(rData);
00091 SimpleDataWriter(rDirectory, rFileName, data, cleanDirectory);
00092 }