6 #include <boost/bind.hpp>
7 #include <boost/function.hpp>
10 #include "netcdfcpp.h"
14 using namespace gplib;
19 const size_t nsamples = Stations.
GetList().front()->GetData().size();
20 const size_t nstations = Stations.
GetList().size();
22 sort(Stations.
GetList().begin(), Stations.
GetList().end(), boost::bind(
23 less<double> (), boost::bind(
f, boost::bind(&boost::shared_ptr<
25 &boost::shared_ptr<SeismicDataComp>::get, _2))));
26 size_t nCompatStations = 0;
27 for (
size_t i = 0; i < nstations; ++i)
29 if (nsamples == Stations.
GetList().at(i)->GetData().size())
35 NcFile combrescdf((filename +
".nc").c_str(), NcFile::Replace);
36 NcDim* xd = combrescdf.add_dim(
"x", nCompatStations);
37 NcDim* yd = combrescdf.add_dim(
"y", nsamples);
38 NcVar* x = combrescdf.add_var(
"x", ncFloat, xd);
39 NcVar* y = combrescdf.add_var(
"y", ncFloat, yd);
40 NcVar* z = combrescdf.add_var(
"z", ncFloat, xd, yd);
41 float *xvals =
new float[xd->size()];
42 float *yvals =
new float[yd->size()];
43 float *zvals =
new float[xd->size() * yd->size()];
45 for (
size_t j = 0; j < nsamples; ++j)
46 yvals[j] = j * Stations.
GetList().front()->GetDt()
47 + Stations.
GetList().front()->GetB();
49 size_t stationindex = 0;
50 while (dataindex < nCompatStations)
52 xvals[dataindex] =
f(Stations.
GetList().at(stationindex).get());
53 if (nsamples == Stations.
GetList().at(stationindex)->GetData().size())
55 copy(Stations.
GetList().at(stationindex)->GetData().begin(),
56 Stations.
GetList().at(stationindex)->GetData().end(),
57 &zvals[dataindex * nsamples]);
62 cerr <<
"File: " << Stations.
GetList().at(stationindex)->GetName()
63 <<
" " <<
"has incompatible length: " << Stations.
GetList().at(
64 stationindex)->GetData().size() <<
" not " << nsamples << endl;
68 x->put(xvals, xd->size());
69 y->put(yvals, yd->size());
70 z->put(zvals, z->edges());
77 int main(
int argc,
char* argv[])
80 string listfilename, outfilename;
83 "$Id: plotrecfunc.cpp 1882 2014-06-12 08:15:20Z mmoorkamp $";
85 cout <<
"Program " << version << endl;
86 cout <<
" Print a number of receiver functions in one plot" << endl;
88 <<
" Input is a list of files, output an ascii file for plotting with xmgrace and a netcdf file"
91 <<
" Individual receiver functions are offset in y-direction by the chosen sorting criterion"
96 listfilename = argv[1];
97 outfilename = argv[2];
101 listfilename = AskFilename(
"List filename: ");
102 outfilename = AskFilename(
"Output filename: ");
104 boost::function<double(SeismicDataComp*)> SortFunc;
106 cout <<
"Specify Sorting Criterion: " << endl;
107 cout <<
" 1: Distance " << endl;
108 cout <<
" 2: Backazimuth " << endl;
113 SortFunc = &SeismicDataComp::GetGcarc;
116 SortFunc = &SeismicDataComp::GetBaz;
119 cerr <<
"Invalid choice !";
124 vector<double> distances(Stations.
GetList().size(), 0.0);
126 distances.begin(), boost::bind(SortFunc, boost::bind(
127 &boost::shared_ptr<SeismicDataComp>::get, _1)));
128 cout <<
"Parameters: " << endl;
129 copy(distances.begin(), distances.end(), ostream_iterator<double> (cout,
132 double meandist =
Mean(distances.begin(), distances.end());
133 cout <<
"Mean Parameter: " << meandist << endl;
134 vector<double> maxamps;
135 for (SeismicStationList::tseiscompvector::iterator CurrentStation =
136 Stations.
GetList().begin(); CurrentStation != Stations.
GetList().end(); CurrentStation++)
138 double currmax = *max_element(CurrentStation->get()->GetData().begin(),
139 CurrentStation->get()->GetData().end());
140 if (!std::isnan(currmax))
141 maxamps.push_back(currmax);
143 double meanamp =
Mean(maxamps.begin(), maxamps.end());
144 double yshift = 5.0 * meanamp / meandist;
145 cout <<
" Mean Amp: " << meanamp << endl;
146 ofstream outfile(outfilename.c_str());
147 for (SeismicStationList::tseiscompvector::iterator CurrentStation =
148 Stations.
GetList().begin(); CurrentStation != Stations.
GetList().end(); CurrentStation++)
150 for (
size_t i = 0; i < CurrentStation->get()->GetData().size(); ++i)
152 outfile << i * CurrentStation->get()->GetDt()
153 + CurrentStation->get()->GetB() <<
" "
154 << CurrentStation->get()->GetData().at(i) + (meandist
155 - SortFunc(CurrentStation->get())) * yshift << endl;
157 outfile << endl << endl;
tseiscompvector & GetList()
Return the content of the list for manipulation.
int main(int argc, char *argv[])
std::iterator_traits< InputIterator >::value_type Mean(InputIterator begin, InputIterator end)
Calculate the mean for a given range.
void f(vector< double > &v1, vector< double > &v2, vector< double > &v3, vector< double > &v4)
void WriteToNetCDF(string filename, SeismicStationList &Stations, boost::function< double(SeismicDataComp *)> f)
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