GPLIB++
mtucross.cpp
Go to the documentation of this file.
1 #include <fstream>
2 #include <iostream>
3 #include <vector>
4 #include <string>
5 #include <algorithm>
6 #include <boost/shared_ptr.hpp>
7 #include <boost/date_time/posix_time/posix_time.hpp>
8 #include "TimeSeriesData.h"
9 #include "miscfunc.h"
10 #include "Util.h"
11 
12 using namespace std;
13 using namespace gplib;
14 
15 string version = "$Id: mtuadaptive.cpp 942 2007-04-08 16:13:01Z max $";
16 
17 int main()
18  {
19  cout
20  << "This is tscross: Calculate the 0 lag cross-correlation between components of two times series"
21  << endl << endl;
22  cout << " The program will ask for reference and input filename. " << endl;
23  cout
24  << " The cross correlation for each component is written to the screen."
25  << endl << endl;
26  cout << " This is Version: " << version << endl << endl;
27 
28  TimeSeriesData Data1, Data2;
29 
30  int index;
31  string data1filename, data2filename;
32 
33  data1filename = AskFilename("Data file 1: ");
34  Data1.GetData(data1filename);
35  cout << "Component Index (Hx,Hy,Ex,Ey): ";
36  cin >> index;
37  data2filename = AskFilename("Data file 2: ");
38  Data2.GetData(data2filename);
39  cout << "Data1 Start time: " << Data1.GetData().GetTime().front() << endl;
40  cout << "Dat2 Start time: " << Data2.GetData().GetTime().front() << endl;
41  if (Data1.GetData().GetTime().front() != Data2.GetData().GetTime().front())
42  {
43  cerr << "Time series not synchronized !" << endl;
44  return 100;
45  }
46 
47  int length = Data1.GetData().Size();
48 
49  cout << "Input End time: " << Data1.GetData().GetTime().back() << endl;
50  cout << "Reference End time: " << Data2.GetData().GetTime().back() << endl;
51 
52  TimeSeriesComponent *RefComp;
53  switch (index)
54  {
55  case 1:
56  RefComp = &Data1.GetData().GetHx();
57  break;
58  case 2:
59  RefComp = &Data1.GetData().GetHy();
60  break;
61  case 3:
62  RefComp = &Data1.GetData().GetEx();
63  break;
64  case 4:
65  RefComp = &Data1.GetData().GetEy();
66  break;
67  default:
68  cerr << "Component index not valid !";
69  return 100;
70  break;
71  }
72  double cross = Cross(RefComp->GetData(), Data2.GetData().GetHx().GetData(),
73  0, length);
74  cout << "Cross Hx: " << cross << endl;
75  cross = Cross(RefComp->GetData(), Data2.GetData().GetHy().GetData(), 0,
76  length);
77  cout << "Cross Hy: " << cross << endl;
78  cross = Cross(RefComp->GetData(), Data2.GetData().GetEx().GetData(), 0,
79  length);
80  cout << "Cross Ex: " << cross << endl;
81  cross = Cross(RefComp->GetData(), Data2.GetData().GetEy().GetData(), 0,
82  length);
83  cout << "Cross Ey: " << cross << endl;
84  }
85 
int main()
Definition: mtucross.cpp:17
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
TimeSeriesComponent & GetHy()
Definition: TimeSeries.h:39
TimeSeriesComponent is the base storage class for all types of time series data.
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
TimeSeriesComponent & GetEy()
Definition: TimeSeries.h:51
string version
Definition: mtucross.cpp:15
TimeSeriesComponent & GetHx()
Access function for Hx, returns reference for efficiency.
Definition: TimeSeries.h:35