surfnoise.cpp

Go to the documentation of this file.
00001 #include <iostream>
00002 #include <string>
00003 #include <algorithm>
00004 #include <cstdlib>
00005 #include <ctime>
00006 #include <boost/random/lagged_fibonacci.hpp>
00007 #include <boost/random/normal_distribution.hpp>
00008 #include <boost/random/variate_generator.hpp>
00009 #include <boost/bind.hpp>
00010 #include "SurfaceWaveData.h"
00011 #include "Util.h"
00012 
00013 using namespace std;
00014 using namespace gplib;
00015 
00016 int main(int argc, char* argv[])
00017   {
00018     SurfaceWaveData Data;
00019     string datafilename, outfilename;
00020     double noiselevel;
00021 
00022     string version = "$Id: surfnoise.cpp 1816 2009-09-07 11:28:35Z mmoorkamp $";
00023     cout << endl << endl;
00024     cout << "Program " << version << endl;
00025     cout << " Add random noise to surface wave dispersion data" << endl;
00026     cout
00027         << " Input is a surface wave dispersion file, output a dispersion file with added noise"
00028         << endl;
00029     cout << " The noise level is specified relative to each datapoint" << endl;
00030     cout << endl << endl;
00031     if (argc > 3)
00032       {
00033         datafilename = argv[1];
00034         outfilename = argv[2];
00035         noiselevel = atof(argv[3]);
00036       }
00037     else
00038       {
00039         datafilename = AskFilename("Input file: ");
00040         outfilename = AskFilename("Output filename: ");
00041         cout << "Noise level: ";
00042         cin >> noiselevel;
00043       }
00044     Data.ReadFile(datafilename);
00045     boost::lagged_fibonacci607
00046         generator(static_cast<unsigned int>(std::time(0)));
00047 
00048     //add noise to each dispersion value
00049     const size_t ndata = Data.GetPhaseVelocities().size();
00050     for (size_t i =0; i < ndata; ++i)
00051       {
00052         Data.SetPhaseVelocities().at(i) = boost::variate_generator<boost::lagged_fibonacci607&,
00053         boost::normal_distribution<> >(generator,
00054             boost::normal_distribution<>(Data.GetPhaseVelocities().at(i),
00055                 Data.GetPhaseVelocities().at(i)* noiselevel))();
00056       }
00057     Data.WriteAscii(outfilename);
00058   }

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