GPLIB++
mtucut.cpp
Go to the documentation of this file.
1 #include <iostream>
2 #include <string>
3 #include "Util.h"
4 #include "TimeSeriesData.h"
5 #include <boost/date_time/posix_time/posix_time.hpp>
6 
7 using namespace std;
8 using namespace gplib;
9 
10 /*!
11  * \addtogroup UtilProgs Utility Programs
12  *@{
13  * \file
14  * Cut a MT time series to a given number of points and (optionally) shift the beginning
15  * by some points.
16  */
17 
18 string version = "$Id: mtucut.cpp 1889 2016-05-25 13:16:12Z mmoorkamp $";
19 
20 int main(int argc, char *argv[])
21  {
22  string infilename;
23  size_t newlength, startindex;
24 
25  cout << "This is mtucut: Cut Phoenix time series to a given length" << endl
26  << endl;
27  cout
28  << "Ending .cut + ending [ts3,ts4,ts5] will be automatically assigned to outfilename"
29  << endl << endl;
30  cout << "This is Version: " << version << endl << endl;
31 
32  if (argc == 2)
33  {
34  infilename = argv[1];
35  }
36  else
37  {
38  infilename = AskFilename("Mtu-Filename: ");
39  }
40 
41  TimeSeriesData Data;
42  Data.GetData(infilename);
43  cout << "Old length: " << Data.GetData().GetEx().GetData().size() << endl;
44  cout << "Old Start time: " << Data.GetData().GetTime().front() << endl;
45  cout << "Old End time: " << Data.GetData().GetTime().back() << endl;
46  cout << "New length: ";
47  cin >> newlength;
48  cout << "Startindex: ";
49  cin >> startindex;
50 
51  const size_t length = Data.GetData().GetEx().GetData().size();
52  if (newlength + startindex > length)
53  {
54  cerr << "Selected segment is partially outside time series !";
55  return 100;
56  }
57  else
58  {
59  // remove the data at the beginning that is not needed any more
60  Data.GetData().erase(0, startindex);
61  //remove the data at the end, that is not needed any more
62  Data.GetData().erase(Data.GetData().Size() - (Data.GetData().Size()
63  - newlength), Data.GetData().Size());
64  Data.WriteAsMtu(infilename + ".cut");
65  }
66 
67  cout << "New Start time: " << Data.GetData().GetTime().front() << endl;
68  cout << "New End time: " << Data.GetData().GetTime().back() << endl;
69 
70  }
71 /*@}*/
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
void erase(const int startindex, const int endindex)
Erase data between startindex and endindex.
Definition: TimeSeries.cpp:59
void WriteAsMtu(std::string filename_base)
Write data to file in Phoenix MTU format.
string version
Definition: mtucut.cpp:18
int main()
Definition: angleavg.cpp:12
TimeSeriesData stores a pointer to the different components of magnetotelluric data and provides func...
ttimedata & GetTime()
Definition: TimeSeries.h:55
size_t Size()
Return the size of the time series, throws if one of the components has a different size...
Definition: TimeSeries.cpp:74