GPLIB++
surfnoise.cpp
Go to the documentation of this file.
1 #include <iostream>
2 #include <string>
3 #include <algorithm>
4 #include <cstdlib>
5 #include <ctime>
6 #include <boost/random/lagged_fibonacci.hpp>
7 #include <boost/random/normal_distribution.hpp>
8 #include <boost/random/variate_generator.hpp>
9 #include <boost/bind.hpp>
10 #include "SurfaceWaveData.h"
11 #include "Util.h"
12 
13 using namespace std;
14 using namespace gplib;
15 
16 int main(int argc, char* argv[])
17  {
18  SurfaceWaveData Data;
19  string datafilename, outfilename;
20  double noiselevel;
21 
22  string version = "$Id: surfnoise.cpp 1816 2009-09-07 11:28:35Z mmoorkamp $";
23  cout << endl << endl;
24  cout << "Program " << version << endl;
25  cout << " Add random noise to surface wave dispersion data" << endl;
26  cout
27  << " Input is a surface wave dispersion file, output a dispersion file with added noise"
28  << endl;
29  cout << " The noise level is specified relative to each datapoint" << endl;
30  cout << endl << endl;
31  if (argc > 3)
32  {
33  datafilename = argv[1];
34  outfilename = argv[2];
35  noiselevel = atof(argv[3]);
36  }
37  else
38  {
39  datafilename = AskFilename("Input file: ");
40  outfilename = AskFilename("Output filename: ");
41  cout << "Noise level: ";
42  cin >> noiselevel;
43  }
44  Data.ReadFile(datafilename);
45  boost::lagged_fibonacci607
46  generator(static_cast<unsigned int>(std::time(0)));
47 
48  //add noise to each dispersion value
49  const size_t ndata = Data.GetPhaseVelocities().size();
50  for (size_t i =0; i < ndata; ++i)
51  {
52  Data.SetPhaseVelocities().at(i) = boost::variate_generator<boost::lagged_fibonacci607&,
53  boost::normal_distribution<> >(generator,
54  boost::normal_distribution<>(Data.GetPhaseVelocities().at(i),
55  Data.GetPhaseVelocities().at(i)* noiselevel))();
56  }
57  Data.WriteAscii(outfilename);
58  }
const trealdata & GetPhaseVelocities() const
Read-only access to the vector of phase velocities.
A class to read, write and store fundamental mode surface wave dispersion data.
string version
Definition: makeinput.cpp:16
virtual void WriteAscii(const std::string &filename) const
Write the data in simple ascii format.
void ReadFile(const std::string &filename)
Read data from file, depending on the extension.
trealdata & SetPhaseVelocities()
Read-write access to phase velocities, the format might be changed in the future. ...
int main(int argc, char *argv[])
Definition: surfnoise.cpp:16