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 using namespace std;
00013 int main(int argc, char* argv[])
00014   {
00015     SurfaceWaveData Data;
00016     string datafilename, outfilename;
00017     double noiselevel;
00018 
00019     string version = "$Id: surfnoise.cpp 1706 2008-06-06 07:14:04Z mmoorkamp $";
00020     cout << endl << endl;
00021     cout << "Program " << version << endl;
00022     cout << " Add random noise to surface wave dispersion data" << endl;
00023     cout
00024         << " Input is a surface wave dispersion file, output a dispersion file with added noise"
00025         << endl;
00026     cout << " The noise level is specified relative to each datapoint" << endl;
00027     cout << endl << endl;
00028     if (argc > 3)
00029       {
00030         datafilename = argv[1];
00031         outfilename = argv[2];
00032         noiselevel = atof(argv[3]);
00033       }
00034     else
00035       {
00036         datafilename = AskFilename("Input file: ");
00037         outfilename = AskFilename("Output filename: ");
00038         cout << "Noise level: ";
00039         cin >> noiselevel;
00040       }
00041     Data.ReadFile(datafilename);
00042     boost::lagged_fibonacci607
00043         generator(static_cast<unsigned int>(std::time(0)));
00044 
00045     //add noise to each dispersion value
00046     const size_t ndata = Data.GetPhaseVelocities().size();
00047     for (size_t i =0; i < ndata; ++i)
00048       {
00049         Data.SetPhaseVelocities().at(i) = boost::variate_generator<boost::lagged_fibonacci607&,
00050         boost::normal_distribution<> >(generator,
00051             boost::normal_distribution<>(Data.GetPhaseVelocities().at(i),
00052                 Data.GetPhaseVelocities().at(i)* noiselevel))();
00053       }
00054     Data.WriteAscii(outfilename);
00055   }

Generated on Fri Jul 4 15:30:21 2008 for GPLIB++ by  doxygen 1.5.5