mtucross.cpp
Go to the documentation of this file.00001 #include <fstream>
00002 #include <iostream>
00003 #include <vector>
00004 #include <string>
00005 #include <algorithm>
00006 #include <boost/shared_ptr.hpp>
00007 #include <boost/date_time/posix_time/posix_time.hpp>
00008 #include "TimeSeriesData.h"
00009 #include "miscfunc.h"
00010 #include "Util.h"
00011
00012 using namespace std;
00013 using namespace gplib;
00014
00015 string version = "$Id: mtuadaptive.cpp 942 2007-04-08 16:13:01Z max $";
00016
00017 int main()
00018 {
00019 cout
00020 << "This is tscross: Calculate the 0 lag cross-correlation between components of two times series"
00021 << endl << endl;
00022 cout << " The program will ask for reference and input filename. " << endl;
00023 cout
00024 << " The cross correlation for each component is written to the screen."
00025 << endl << endl;
00026 cout << " This is Version: " << version << endl << endl;
00027
00028 TimeSeriesData Data1, Data2;
00029
00030 int index;
00031 string data1filename, data2filename;
00032
00033 data1filename = AskFilename("Data file 1: ");
00034 Data1.GetData(data1filename);
00035 cout << "Component Index (Hx,Hy,Ex,Ey): ";
00036 cin >> index;
00037 data2filename = AskFilename("Data file 2: ");
00038 Data2.GetData(data2filename);
00039 cout << "Data1 Start time: " << Data1.GetData().GetTime().front() << endl;
00040 cout << "Dat2 Start time: " << Data2.GetData().GetTime().front() << endl;
00041 if (Data1.GetData().GetTime().front() != Data2.GetData().GetTime().front())
00042 {
00043 cerr << "Time series not synchronized !" << endl;
00044 return 100;
00045 }
00046
00047 int length = Data1.GetData().Size();
00048
00049 cout << "Input End time: " << Data1.GetData().GetTime().back() << endl;
00050 cout << "Reference End time: " << Data2.GetData().GetTime().back() << endl;
00051
00052 TimeSeriesComponent *RefComp;
00053 switch (index)
00054 {
00055 case 1:
00056 RefComp = &Data1.GetData().GetHx();
00057 break;
00058 case 2:
00059 RefComp = &Data1.GetData().GetHy();
00060 break;
00061 case 3:
00062 RefComp = &Data1.GetData().GetEx();
00063 break;
00064 case 4:
00065 RefComp = &Data1.GetData().GetEy();
00066 break;
00067 default:
00068 cerr << "Component index not valid !";
00069 return 100;
00070 break;
00071 }
00072 double cross = Cross(RefComp->GetData(), Data2.GetData().GetHx().GetData(),
00073 0, length);
00074 cout << "Cross Hx: " << cross << endl;
00075 cross = Cross(RefComp->GetData(), Data2.GetData().GetHy().GetData(), 0,
00076 length);
00077 cout << "Cross Hy: " << cross << endl;
00078 cross = Cross(RefComp->GetData(), Data2.GetData().GetEx().GetData(), 0,
00079 length);
00080 cout << "Cross Ex: " << cross << endl;
00081 cross = Cross(RefComp->GetData(), Data2.GetData().GetEy().GetData(), 0,
00082 length);
00083 cout << "Cross Ey: " << cross << endl;
00084 }
00085