12 using namespace gplib;
16 string version =
"$Id: stackrf.cpp 1825 2009-11-03 13:38:06Z mmoorkamp $";
18 cout <<
"Program " << version << endl;
19 cout <<
" Stack a number of receiver functions and";
20 cout <<
" write out the averaged results." << endl;
21 cout <<
" The program assumes that all RF have the same";
22 cout <<
" sampling rate and shift, it does not correct for moveout."
25 string reclistname = AskFilename(
"File with list of filenames: ");
26 string outfilename = AskFilename(
"Outfilename root: ");
33 const unsigned int nrecfunc = RF.
GetList().size();
34 cout <<
"Read " << nrecfunc <<
" receiver functions." << endl;
36 const unsigned int rflength = RF.
GetList().front()->GetData().size();
38 gplib::rvec AvgRF(rflength),
StdDev(rflength);
39 fill_n(AvgRF.begin(), rflength, 0.0);
40 fill_n(StdDev.begin(), rflength, 0.0);
42 for (
unsigned int i = 0; i < nrecfunc; ++i)
45 if (RF.
GetList().at(i)->GetData().size() != rflength)
47 cerr <<
"Incompatible data length in entry number " << i << endl;
50 transform(RF.
GetList().at(i)->GetData().begin(),
51 RF.
GetList().at(i)->GetData().end(), AvgRF.begin(), AvgRF.begin(),
62 AvgRF *= 1. / nrecfunc;
64 for (
unsigned int i = 0; i < nrecfunc; ++i)
66 for (
unsigned int j = 0; j < rflength; ++j)
68 StdDev(j) += pow2(AvgRF(j) - RF.
GetList().at(i)->GetData().at(
73 StackedRF = *RF.
GetList().front().get();
75 copy(AvgRF.begin(), AvgRF.end(), StackedRF.
GetData().begin());
78 StdDev *= 1. / (nrecfunc - 1);
80 ofstream outfile((outfilename +
".avg.asc").c_str());
81 const double dt = RF.
GetList().front()->GetDt();
82 for (
unsigned int i = 0; i < rflength; ++i)
83 outfile << i * dt + RF.
GetList().front()->GetB() <<
" " << AvgRF(i)
84 <<
" " << sqrt(
StdDev(i) / nrecfunc) << endl;
tseiscompvector & GetList()
Return the content of the list for manipulation.
std::vector< double > & GetData()
Access for data vector, for ease of use and efficiency we return a reference.
Manages a collection of seismic traces, mainly provides functionality to read in data specified in a ...
std::iterator_traits< InputIterator >::value_type StdDev(InputIterator begin, InputIterator end, typename std::iterator_traits< InputIterator >::value_type mv)
Calculate the Standard deviation with a given mean.
void ReadList(const std::string filename)
read in a file with names and optionally coordinates
int WriteAsSac(const std::string &filename) const
Write the data in sac binary format.