GPLIB++
LemiTsFormat.cpp
Go to the documentation of this file.
1 #include "LemiTsFormat.h"
2 #include "MtuFormat.h"
3 #include "BirrpAsciiFormat.h"
4 #include "FatalException.h"
5 #include <boost/cast.hpp>
6 #include <fstream>
7 
8 using namespace std;
9 
10 namespace gplib
11  {
12  LemiTsFormat::LemiTsFormat()
13  {
14  }
15 
16  LemiTsFormat::~LemiTsFormat()
17  {
18  }
19 
20  void LemiTsFormat::GetData()
21  {
22  throw FatalException("Not implemented");
23  }
24 
25  void LemiTsFormat::GetData(const std::string filename)
26  {
27  ifstream infile(filename.c_str());
28  double rawsecond, fraction; //the second information stored in the file
29  int year, month, day, hour, minute, second;
30  const double rate = 4.0; // the fixed sampling rate is 4 Hz
31  double number;
32 
33  while (infile.good())
34  {
35  infile.precision(15);
36  infile >> year >> month >> day >> hour >> minute >> rawsecond; //read in time information
37  second = static_cast<int> (rawsecond); //chop of the fractional part
38  fraction = rawsecond - static_cast<int> (rawsecond); // calculate the fractional part
39  TimeSeries::ttime currtime(
40  boost::gregorian::date(year, month, day),
41  boost::posix_time::time_duration(hour, minute, second)); //construct time structure
42  currtime += boost::posix_time::microseconds(
43  boost::numeric_cast<int>(fraction * 1000000));
44  t.push_back(currtime);
45  if (infile.good()) //if read was successfull
46  {
47  infile >> number;
48  Hx.GetData().push_back(number);
49  infile >> number;
50  Hy.GetData().push_back(number);
51  infile >> number;
52  Hz.GetData().push_back(number);
53  infile >> number >> number >> number; //we skip the two temperature values and read Ex
54  Ex.GetData().push_back(number);
55  infile >> number;
56  Ey.GetData().push_back(number);
57  infile >> number >> number >> number; // we skip the two additional channels and the extra time information
58  }
59  }
60  if (!infile.eof())
61  {
62  throw FatalException("Problem reading from file: " + filename);
63  }
64  Hx.SetSamplerate(rate);
65  Hy.SetSamplerate(rate);
66  Hz.SetSamplerate(rate);
67  Ex.SetSamplerate(rate);
68  Ey.SetSamplerate(rate);
69  }
70 
71  void LemiTsFormat::WriteData(const std::string filename)
72  {
73  throw FatalException("Not implemented");
74  }
75 
76  LemiTsFormat& LemiTsFormat::operator=(BirrpAsciiFormat& source)
77  {
78  this->TimeSeries::operator=(source);
79  return *this;
80  }
81 
82  LemiTsFormat& LemiTsFormat::operator=(MtuFormat& source)
83  {
84  this->TimeSeries::operator=(source);
85  return *this;
86  }
87 
88  LemiTsFormat& LemiTsFormat::operator=(TimeSeries& source)
89  {
90  this->TimeSeries::operator=(source);
91  return *this;
92  }
93 
94  LemiTsFormat& LemiTsFormat::operator=(LemiTsFormat& source)
95  {
96  if (this != &source)
97  {
98  this->TimeSeries::operator=(source);
99  }
100  return *this;
101  }
102  }
This class is the base class for all classes dealing with MT time series.
Definition: TimeSeries.h:14
Read and write ascii files produced by the LEMI instruments.
Definition: LemiTsFormat.h:15
BirrpAsciiFormat reads and stores MT data in the ascii format used by the birrp processing software...
boost::posix_time::ptime ttime
We use the boost library time functionality for time types and store the time for each point in a vec...
Definition: TimeSeries.h:18
Read and write phoenix mtu binary files.
Definition: MtuFormat.h:13
The basic exception class for all errors that arise in gplib.