corrselect.cpp

Go to the documentation of this file.
00001 #include "SeismicStationList.h"
00002 #include "VecMat.h"
00003 #include "miscfunc.h"
00004 #include <iostream>
00005 #include <fstream>
00006 #include <string>
00007 #include <vector>
00008 #include "Util.h"
00009 
00010 using namespace std;
00011 using namespace gplib;
00012 
00013 string version = "$Id: corrselect.cpp 1816 2009-09-07 11:28:35Z mmoorkamp $";
00014 
00015 gplib::rmat CalcCorrMatrix(const SeismicStationList::tseiscompvector &List)
00016   {
00017     const unsigned int nrf = List.size();
00018     gplib::rmat CorrMatrix(nrf, nrf);
00019     CorrMatrix *= 0.0;
00020     for (unsigned int i = 0; i < nrf; ++i)
00021       {
00022         for (unsigned int j = i; j < nrf; ++j)
00023           {
00024             CorrMatrix(i, j) = Cross(List.at(i)->GetData(),
00025                 List.at(j)->GetData(), 0, min(List.at(i)->GetData().size(),
00026                     List.at(j)->GetData().size()));
00027             CorrMatrix(j, i) = CorrMatrix(i, j);
00028           }
00029       }
00030     return CorrMatrix;
00031   }
00032 
00033 int main()
00034   {
00035     cout
00036         << " This is corrselect: Select receiver functions based on their correlation"
00037         << endl; // write some info
00038     cout << " Reads in receiver function in SAC format" << endl;
00039     cout << " This is Version: " << version << endl << endl;
00040 
00041     SeismicStationList RF;
00042 
00043     string reclistname = AskFilename("File with list of filenames: ");
00044     cin >> reclistname;
00045 
00046     RF.ReadList(reclistname);
00047 
00048     unsigned int nrf = RF.GetList().size();
00049     cout << "Read " << nrf << " receiver functions." << endl;
00050     string cont = "y";
00051     while (cont != "n")
00052       {
00053         gplib::rmat CorrMatrix = CalcCorrMatrix(RF.GetList());
00054         nrf = RF.GetList().size();
00055         for (unsigned int j = 0; j < nrf; ++j)
00056           cout << j << " " << CorrMatrix(0, j) << endl;
00057         ublas::scalar_vector<double> mul(nrf, 1. / nrf);
00058         gplib::rvec AvgCorr = prod(CorrMatrix, mul);
00059 
00060         cout << "Average Correlation: ";
00061         copy(AvgCorr.begin(), AvgCorr.end(), ostream_iterator<double> (cout,
00062             " "));
00063         cout << endl;
00064         cout << "Threshold: ";
00065         double threshold = 0.0;
00066         cin >> threshold;
00067         SeismicStationList::tseiscompvector::iterator it = RF.GetList().begin();
00068         for (unsigned int j = 0; j < nrf; ++j, ++it)
00069           {
00070             if (AvgCorr(j) < threshold)
00071               RF.GetList().erase(it);
00072           }
00073         cout << "Continue (y/n)";
00074         cin >> cont;
00075       }
00076     nrf = RF.GetList().size();
00077     for (unsigned int j = 0; j < nrf; ++j)
00078       {
00079         cout << RF.GetList().at(j)->GetName() << endl;
00080       }
00081   }

Generated on Tue May 4 16:52:14 2010 for GPLIB++ by  doxygen 1.5.8