GPLIB++
CsvFormat.cpp
Go to the documentation of this file.
1 #include "CsvFormat.h"
2 #include <fstream>
3 #include <string>
4 #include <iostream>
5 #include <iomanip>
6 #include "MtuFormat.h"
7 #include "FatalException.h"
8 #include <boost/date_time/posix_time/posix_time.hpp>
9 using namespace std;
10 
11 namespace gplib
12  {
13  CsvFormat::CsvFormat()
14  {
15  }
16 
17  CsvFormat::~CsvFormat()
18  {
19  }
20 
21  void CsvFormat::GetData(const std::string filename)
22  {
23  ifstream infile(filename.c_str());
24  char dummy[255];
25  string line1, line2, line3, line4, line5, line6;
26  double number;
27  vector<double>::iterator outit;
28 
29  infile.getline(dummy, sizeof(dummy));
30  infile.getline(dummy, sizeof(dummy));
31  infile.getline(dummy, sizeof(dummy));
32  infile.getline(dummy, sizeof(dummy));
33  infile.getline(dummy, sizeof(dummy));
34  infile.getline(dummy, sizeof(dummy));
35  while (infile.good())
36  {
37  infile.precision(8);
38  //infile >> number;
39  //t.push_back(number);
40  //infile.ignore(256,',');
41 
42  infile >> number;
43  if (infile.good())
44  {
45  Ex.GetData().push_back(number);
46  infile.ignore(256, ',');
47 
48  infile >> number;
49  Ey.GetData().push_back(number);
50  infile.ignore(256, ',');
51 
52  infile >> number;
53  Hx.GetData().push_back(number);
54  infile.ignore(256, ',');
55 
56  infile >> number;
57  Hy.GetData().push_back(number);
58  infile.ignore(256, ',');
59 
60  infile >> number;
61  Hz.GetData().push_back(number);
62  infile.ignore(256, ',');
63  }
64  }
65  if (!infile.eof())
66  {
67  throw FatalException("Problem reading file: " + filename);
68  }
69  }
70 
71  void CsvFormat::WriteData(const std::string filename)
72  {
73  ofstream outfile;
74 
75  outfile.open(filename.c_str());
76  for (unsigned int i = 0; i < Ex.GetData().size(); ++i)
77  {
78  outfile.precision(8);
79  outfile << setw(10) << boost::posix_time::to_simple_string(t.at(i))
80  << ",";
81  outfile << setw(10) << Ex.GetData().at(i) << ",";
82  outfile << setw(10) << Ey.GetData().at(i) << ",";
83  outfile << setw(10) << Hx.GetData().at(i) << ",";
84  outfile << setw(10) << Hy.GetData().at(i) << ",";
85  outfile << setw(10) << Hz.GetData().at(i) << endl;
86  }
87  outfile.close();
88 
89  }
90 
91  CsvFormat& CsvFormat::operator=(CsvFormat& source)
92  {
93  if (this != &source)
94  {
95  this->TimeSeries::operator=(source);
96  }
97  return *this;
98  }
99 
100  CsvFormat& CsvFormat::operator=(MtuFormat& source)
101  {
102  this->TimeSeries::operator=(source);
103  return *this;
104  }
105 
106  CsvFormat& CsvFormat::operator=(TimeSeries& source)
107  {
108  this->TimeSeries::operator=(source);
109  return *this;
110  }
111  void CsvFormat::GetData()
112  {
113 
114  }
115  }
This class is the base class for all classes dealing with MT time series.
Definition: TimeSeries.h:14
Read and write phoenix mtu binary files.
Definition: MtuFormat.h:13
This class reads and writes data from Comma Separated Files CSV as produced by Excel etc...
Definition: CsvFormat.h:14
The basic exception class for all errors that arise in gplib.