CsvFormat.cpp

Go to the documentation of this file.
00001 #include "CsvFormat.h"
00002 #include <fstream>
00003 #include <string>
00004 #include <iostream>
00005 #include <iomanip>
00006 #include "MtuFormat.h"
00007 #include "FatalException.h"
00008 #include <boost/date_time/posix_time/posix_time.hpp>
00009 using namespace std;
00010 
00011 namespace gplib
00012   {
00013     CsvFormat::CsvFormat()
00014       {
00015       }
00016 
00017     CsvFormat::~CsvFormat()
00018       {
00019       }
00020 
00021     void CsvFormat::GetData(const std::string filename)
00022       {
00023         ifstream infile(filename.c_str());
00024         char dummy[255];
00025         string line1, line2, line3, line4, line5, line6;
00026         double number;
00027         vector<double>::iterator outit;
00028 
00029         infile.getline(dummy, sizeof(dummy));
00030         infile.getline(dummy, sizeof(dummy));
00031         infile.getline(dummy, sizeof(dummy));
00032         infile.getline(dummy, sizeof(dummy));
00033         infile.getline(dummy, sizeof(dummy));
00034         infile.getline(dummy, sizeof(dummy));
00035         while (infile.good())
00036           {
00037             infile.precision(8);
00038             //infile >> number;
00039             //t.push_back(number);
00040             //infile.ignore(256,',');
00041 
00042             infile >> number;
00043             if (infile.good())
00044               {
00045                 Ex.GetData().push_back(number);
00046                 infile.ignore(256, ',');
00047 
00048                 infile >> number;
00049                 Ey.GetData().push_back(number);
00050                 infile.ignore(256, ',');
00051 
00052                 infile >> number;
00053                 Hx.GetData().push_back(number);
00054                 infile.ignore(256, ',');
00055 
00056                 infile >> number;
00057                 Hy.GetData().push_back(number);
00058                 infile.ignore(256, ',');
00059 
00060                 infile >> number;
00061                 Hz.GetData().push_back(number);
00062                 infile.ignore(256, ',');
00063               }
00064           }
00065         if (!infile.eof())
00066           {
00067             throw FatalException("Problem reading file: " + filename);
00068           }
00069       }
00070 
00071     void CsvFormat::WriteData(const std::string filename)
00072       {
00073         ofstream outfile;
00074 
00075         outfile.open(filename.c_str());
00076         for (unsigned int i = 0; i < Ex.GetData().size(); ++i)
00077           {
00078             outfile.precision(8);
00079             outfile << setw(10) << boost::posix_time::to_simple_string(t.at(i))
00080                 << ",";
00081             outfile << setw(10) << Ex.GetData().at(i) << ",";
00082             outfile << setw(10) << Ey.GetData().at(i) << ",";
00083             outfile << setw(10) << Hx.GetData().at(i) << ",";
00084             outfile << setw(10) << Hy.GetData().at(i) << ",";
00085             outfile << setw(10) << Hz.GetData().at(i) << endl;
00086           }
00087         outfile.close();
00088 
00089       }
00090 
00091     CsvFormat& CsvFormat::operator=(CsvFormat& source)
00092       {
00093         if (this != &source)
00094           {
00095             this->TimeSeries::operator=(source);
00096           }
00097         return *this;
00098       }
00099 
00100     CsvFormat& CsvFormat::operator=(MtuFormat& source)
00101       {
00102         this->TimeSeries::operator=(source);
00103         return *this;
00104       }
00105 
00106     CsvFormat& CsvFormat::operator=(TimeSeries& source)
00107       {
00108         this->TimeSeries::operator=(source);
00109         return *this;
00110       }
00111     void CsvFormat::GetData()
00112       {
00113 
00114       }
00115   }

Generated on Tue May 4 16:52:14 2010 for GPLIB++ by  doxygen 1.5.8