stackrf.cpp
Go to the documentation of this file.00001 #include "SeismicStationList.h"
00002 #include "SeismicDataComp.h"
00003 #include "VecMat.h"
00004 #include "miscfunc.h"
00005 #include <iostream>
00006 #include <fstream>
00007 #include <string>
00008 #include "NumUtil.h"
00009 #include "Util.h"
00010
00011 using namespace std;
00012 using namespace gplib;
00013
00014 int main()
00015 {
00016 string version = "$Id: stackrf.cpp 1825 2009-11-03 13:38:06Z mmoorkamp $";
00017 cout << endl << endl;
00018 cout << "Program " << version << endl;
00019 cout << " Stack a number of receiver functions and";
00020 cout << " write out the averaged results." << endl;
00021 cout << " The program assumes that all RF have the same";
00022 cout << " sampling rate and shift, it does not correct for moveout."
00023 << endl;
00024 cout << endl << endl;
00025 string reclistname = AskFilename("File with list of filenames: ");
00026 string outfilename = AskFilename("Outfilename root: ");
00027
00028 SeismicStationList RF;
00029 SeismicDataComp StackedRF;
00030
00031 RF.ReadList(reclistname);
00032
00033 const unsigned int nrecfunc = RF.GetList().size();
00034 cout << "Read " << nrecfunc << " receiver functions." << endl;
00035
00036 const unsigned int rflength = RF.GetList().front()->GetData().size();
00037
00038 gplib::rvec AvgRF(rflength), StdDev(rflength);
00039 fill_n(AvgRF.begin(), rflength, 0.0);
00040 fill_n(StdDev.begin(), rflength, 0.0);
00041
00042 for (unsigned int i = 0; i < nrecfunc; ++i)
00043 {
00044
00045 if (RF.GetList().at(i)->GetData().size() != rflength)
00046 {
00047 cerr << "Incompatible data length in entry number " << i << endl;
00048 return 100;
00049 }
00050 transform(RF.GetList().at(i)->GetData().begin(),
00051 RF.GetList().at(i)->GetData().end(), AvgRF.begin(), AvgRF.begin(),
00052 std::plus<double>());
00053
00054
00055
00056
00057
00058
00059
00060 }
00061
00062 AvgRF *= 1. / nrecfunc;
00063
00064 for (unsigned int i = 0; i < nrecfunc; ++i)
00065 {
00066 for (unsigned int j = 0; j < rflength; ++j)
00067 {
00068 StdDev(j) += pow2(AvgRF(j) - RF.GetList().at(i)->GetData().at(
00069 j));
00070 }
00071 }
00072
00073 StackedRF = *RF.GetList().front().get();
00074
00075 copy(AvgRF.begin(), AvgRF.end(), StackedRF.GetData().begin());
00076
00077 StackedRF.WriteAsSac(outfilename + ".avg");
00078 StdDev *= 1. / (nrecfunc - 1);
00079
00080 ofstream outfile((outfilename + ".avg.asc").c_str());
00081 const double dt = RF.GetList().front()->GetDt();
00082 for (unsigned int i = 0; i < rflength; ++i)
00083 outfile << i * dt + RF.GetList().front()->GetB() << " " << AvgRF(i)
00084 << " " << sqrt(StdDev(i) / nrecfunc) << endl;
00085 }