GPLIB++
corrselect.cpp
Go to the documentation of this file.
1 #include "SeismicStationList.h"
2 #include "VecMat.h"
3 #include "miscfunc.h"
4 #include <iostream>
5 #include <fstream>
6 #include <string>
7 #include <vector>
8 #include "Util.h"
9 
10 using namespace std;
11 using namespace gplib;
12 
13 string version = "$Id: corrselect.cpp 1816 2009-09-07 11:28:35Z mmoorkamp $";
14 
16  {
17  const unsigned int nrf = List.size();
18  gplib::rmat CorrMatrix(nrf, nrf);
19  CorrMatrix *= 0.0;
20  for (unsigned int i = 0; i < nrf; ++i)
21  {
22  for (unsigned int j = i; j < nrf; ++j)
23  {
24  CorrMatrix(i, j) = Cross(List.at(i)->GetData(),
25  List.at(j)->GetData(), 0, min(List.at(i)->GetData().size(),
26  List.at(j)->GetData().size()));
27  CorrMatrix(j, i) = CorrMatrix(i, j);
28  }
29  }
30  return CorrMatrix;
31  }
32 
33 int main()
34  {
35  cout
36  << " This is corrselect: Select receiver functions based on their correlation"
37  << endl; // write some info
38  cout << " Reads in receiver function in SAC format" << endl;
39  cout << " This is Version: " << version << endl << endl;
40 
42 
43  string reclistname = AskFilename("File with list of filenames: ");
44  cin >> reclistname;
45 
46  RF.ReadList(reclistname);
47 
48  unsigned int nrf = RF.GetList().size();
49  cout << "Read " << nrf << " receiver functions." << endl;
50  string cont = "y";
51  while (cont != "n")
52  {
53  gplib::rmat CorrMatrix = CalcCorrMatrix(RF.GetList());
54  nrf = RF.GetList().size();
55  for (unsigned int j = 0; j < nrf; ++j)
56  cout << j << " " << CorrMatrix(0, j) << endl;
57  ublas::scalar_vector<double> mul(nrf, 1. / nrf);
58  gplib::rvec AvgCorr = prod(CorrMatrix, mul);
59 
60  cout << "Average Correlation: ";
61  copy(AvgCorr.begin(), AvgCorr.end(), ostream_iterator<double> (cout,
62  " "));
63  cout << endl;
64  cout << "Threshold: ";
65  double threshold = 0.0;
66  cin >> threshold;
67  SeismicStationList::tseiscompvector::iterator it = RF.GetList().begin();
68  for (unsigned int j = 0; j < nrf; ++j, ++it)
69  {
70  if (AvgCorr(j) < threshold)
71  RF.GetList().erase(it);
72  }
73  cout << "Continue (y/n)";
74  cin >> cont;
75  }
76  nrf = RF.GetList().size();
77  for (unsigned int j = 0; j < nrf; ++j)
78  {
79  cout << RF.GetList().at(j)->GetName() << endl;
80  }
81  }
int main()
Definition: corrselect.cpp:33
tseiscompvector & GetList()
Return the content of the list for manipulation.
std::vector< boost::shared_ptr< SeismicDataComp > > tseiscompvector
gplib::rmat CalcCorrMatrix(const SeismicStationList::tseiscompvector &List)
Definition: corrselect.cpp:15
Manages a collection of seismic traces, mainly provides functionality to read in data specified in a ...
void ReadList(const std::string filename)
read in a file with names and optionally coordinates
string version
Definition: corrselect.cpp:13