rotts.cpp
Go to the documentation of this file.00001 #include <iostream>
00002 #include <string>
00003 #include <numeric>
00004 #include "TimeSeriesData.h"
00005 #include "FatalException.h"
00006 #include "statutils.h"
00007 #include "Util.h"
00008
00009 using namespace std;
00010 using namespace gplib;
00011
00012 string version = "$Id: rotts.cpp 1844 2010-04-12 11:34:25Z mmoorkamp $";
00013
00014
00015
00016
00017
00018
00019
00020
00021 int main(int argc, char *argv[])
00022 {
00023 string infilename;
00024
00025 cout << "This is rotts: Rotate time series to a 0 mean By component"
00026 << endl << endl;
00027 cout << " Usage: rotts filename1" << endl;
00028 cout
00029 << " The output files will have the same name as the input files + .rot "
00030 << endl << endl;
00031 cout << " This is Version: " << version << endl << endl;
00032 if (argc == 2)
00033 {
00034 infilename = argv[1];
00035 }
00036 else
00037 {
00038 infilename = AskFilename("Input Filename: ");
00039
00040 }
00041 cout << "Rotating ... " << endl;
00042 TimeSeriesData Data1;
00043 try
00044 {
00045 Data1.GetData(infilename);
00046
00047 double hymedian = Median(Data1.GetData().GetHy().GetData().begin(),
00048 Data1.GetData().GetHy().GetData().end());
00049 double hxmedian = Median(Data1.GetData().GetHx().GetData().begin(),
00050 Data1.GetData().GetHx().GetData().end());
00051 cout << "Hy Median before: " << hymedian << endl;
00052
00053 double phi = hymedian / sqrt(std::pow(hxmedian, 2) + std::pow(hymedian, 2));
00054 cout << "Estimated angle: " << phi << endl;
00055 double newhx, newhy;
00056 double sinphi = sin(-phi);
00057 double cosphi = cos(-phi);
00058 const unsigned int ndata = Data1.GetData().GetHy().GetData().size();
00059 for (unsigned int i = 0; i < ndata; ++i)
00060 {
00061 newhx = cosphi * Data1.GetData().GetHx().GetData().at(i) + sinphi
00062 * Data1.GetData().GetHy().GetData().at(i);
00063 newhy = sinphi * Data1.GetData().GetHx().GetData().at(i) + cosphi
00064 * Data1.GetData().GetHy().GetData().at(i);
00065 Data1.GetData().GetHx().GetData().at(i) = newhx;
00066 Data1.GetData().GetHy().GetData().at(i) = newhy;
00067 }
00068 hymedian = Median(Data1.GetData().GetHy().GetData().begin(),
00069 Data1.GetData().GetHy().GetData().end());
00070 cout << "Hy Median after: " << hymedian << endl;
00071 Data1.WriteAsBirrp(infilename + ".rot");
00072 } catch (const FatalException &e)
00073 {
00074 cerr << e.what() << endl;
00075 }
00076 cout << "... done " << endl;
00077 }
00078
00079