seisnoise.cpp
Go to the documentation of this file.00001 #include <iostream>
00002 #include <string>
00003 #include "SeismicDataComp.h"
00004 #include <algorithm>
00005 #include "Util.h"
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
00011 using namespace std;
00012 using namespace gplib;
00013
00014
00015
00016
00017
00018
00019
00020
00021 int main(int argc, char* argv[])
00022 {
00023 SeismicDataComp Data;
00024 string datafilename, outfilename;
00025 double noiselevel;
00026
00027 string version = "$Id: seisnoise.cpp 1816 2009-09-07 11:28:35Z mmoorkamp $";
00028 cout << endl << endl;
00029 cout << "Program " << version << endl;
00030 cout << " Add random noise to a seismogram" << endl;
00031 cout
00032 << " Input is a single component file, output a sac file with added noise"
00033 << endl;
00034 cout << " The noise level is specified relative to the maximum amplitude"
00035 << endl;
00036 cout << endl << endl;
00037 if (argc > 3)
00038 {
00039 datafilename = argv[1];
00040 outfilename = argv[2];
00041 noiselevel = atof(argv[3]);
00042 }
00043 else
00044 {
00045 datafilename = AskFilename("Input filename: ");
00046 outfilename = AskFilename("Output filename: ");
00047 cout << "Noise level: ";
00048 cin >> noiselevel;
00049 }
00050 Data.ReadData(datafilename);
00051 const double maxelem = *max_element(Data.GetData().begin(), Data.GetData().end());
00052 boost::lagged_fibonacci607
00053 generator(static_cast<unsigned int>(std::time(0)));
00054 boost::normal_distribution<> noise_dist(0.0, noiselevel*maxelem);
00055 boost::variate_generator<boost::lagged_fibonacci607&, boost::normal_distribution<> >
00056 noise(generator, noise_dist);
00057
00058
00059 transform(Data.GetData().begin(), Data.GetData().end(), Data.GetData().begin(), boost::bind(plus<double>(), _1, boost::bind(noise)));
00060 Data.WriteAsSac(outfilename);
00061 }