GPLIB++
mtumedian.cpp
Go to the documentation of this file.
1 #include <iostream>
2 #include <string>
3 #include <numeric>
4 #include "statutils.h"
5 #include "TimeSeriesData.h"
6 
7 using namespace std;
8 using namespace gplib;
9 
10 string version = "$Id: ";
11 
12 int main(int argc, char *argv[])
13  {
14  string infilename;
15  if (argc == 2)
16  {
17  infilename = argv[1];
18  }
19  else
20  {
21  cout
22  << "This is mtumedian: Apply a median filter to Phoenix time series"
23  << endl << endl;
24  cout << " Usage: mtumedian infilename " << endl;
25  cout << " Ending '.med' will be automatically assigned to outfilename"
26  << endl << endl;
27  cout << " This is Version: " << version << endl << endl;
28  cout << " Mtu-Filename: ";
29  cin >> infilename;
30  }
31  size_t seglength = 0;
32  cout << "Segment length for Median: ";
33  cin >> seglength;
34 
35  TimeSeriesData Data;
36 
37  Data.GetData(infilename);
38  size_t datalength = Data.GetData().GetEx().GetData().size();
39  for (size_t i = seglength / 2; i < datalength - seglength / 2; ++i)
40  {
41  const size_t startindex = i - seglength / 2;
42  const size_t endindex = i + seglength / 2;
43  Data.GetData().GetEx().GetData().at(i) = Median(
44  Data.GetData().GetEx().GetData().begin() + startindex,
45  Data.GetData().GetEx().GetData().begin() + endindex);
46  Data.GetData().GetEx().GetData().at(i) = Median(
47  Data.GetData().GetEy().GetData().begin() + startindex,
48  Data.GetData().GetEy().GetData().begin() + endindex);
49  Data.GetData().GetEx().GetData().at(i) = Median(
50  Data.GetData().GetHx().GetData().begin() + startindex,
51  Data.GetData().GetHx().GetData().begin() + endindex);
52  Data.GetData().GetEx().GetData().at(i) = Median(
53  Data.GetData().GetHy().GetData().begin() + startindex,
54  Data.GetData().GetHy().GetData().begin() + endindex);
55  }
56  Data.WriteAsMtu(infilename + ".med");
57  }
std::iterator_traits< InputIterator >::value_type Median(InputIterator begin, InputIterator end)
Calculate the median for a vector style container.
Definition: statutils.h:102
std::vector< double > & GetData()
Access for data vector, for ease of use and efficiency we return a reference.
TimeSeries & GetData()
return a reference to the actual object stored in the pointer
TimeSeriesComponent & GetEx()
Definition: TimeSeries.h:47
int main(int argc, char *argv[])
Definition: mtumedian.cpp:12
string version
Definition: mtumedian.cpp:10
TimeSeriesComponent & GetHy()
Definition: TimeSeries.h:39
void WriteAsMtu(std::string filename_base)
Write data to file in Phoenix MTU format.
TimeSeriesData stores a pointer to the different components of magnetotelluric data and provides func...
TimeSeriesComponent & GetEy()
Definition: TimeSeries.h:51
TimeSeriesComponent & GetHx()
Access function for Hx, returns reference for efficiency.
Definition: TimeSeries.h:35