calcrec.cpp

Go to the documentation of this file.
00001 #include <iostream>
00002 #include <string>
00003 #include <algorithm>
00004 #include "Util.h"
00005 #include "RecCalc.h"
00006 #include "CalcRecConf.h"
00007 #include "SeismicDataComp.h"
00008 #include "FatalException.h"
00009 #include "FilterFunc.h"
00010 #include "statutils.h"
00011 
00012 /*! \file
00013  * This program calculates a receiver function from single radial and vertical components.
00014  * When started the program only asks for the name of the files for these two components.
00015  * The output receiver function has the same name as the radial component with .rec appended.
00016  * All other aspects of the calculation are specified in the file calcrec.conf in the directory
00017  * in which the program is executed.
00018  *
00019  * The parameters for that file are as follows:
00020  *
00021  * <TABLE>
00022  * <TR> <TD> <B>Name </B></TD> <TD> <B>Description </B></TD></TR>
00023  * <TR> <TD> recmethod </TD>  <TD> Can be specdiv for spectral division method or iterdecon for iterative deconvolution. </TD></TR>
00024  * <TR> <TD> omega </TD>  <TD>The center of the gaussian used to filter the receiver function during estimation. </TD> </TR>
00025  * <TR> <TD> sigma </TD>  <TD>The width of the gaussian used to filter the receiver function during estimation.
00026  *    Larger values mean a more broad band reciever function that contains more detailed structure but is also susceptible to noise.</TD> </TR>
00027  * <TR> <TD> shift </TD>  <TD>The shift in seconds of the initial correlation peak. This is purely used for display purposes. </TD> </TR>
00028  * <TR> <TD> cc </TD>  <TD>(only specdiv) The waterlevel relative to the maximum autopower of the vertical component. </TD> </TR>
00029  * <TR> <TD> upperfreq </TD>  <TD>The upper frequency in Hz for the bandpass filter, if negative or not set it is ignored </TD> </TR>
00030  * <TR> <TD> lowerfreq </TD>  <TD>The lower frequency in Hz for the bandpass filter, if negative or not set it is ignored </TD> </TR>
00031  * </TABLE>
00032  * More details about these parameters can be found for example in
00033  * Langston, 1979, JGR 84(B9) 4749-4762
00034  * Liggoria, 1999, BSSA 89(5), 1395-1400
00035  */
00036 using namespace std;
00037 using namespace gplib;
00038 
00039 string version = "$Id: calcrec.cpp 1839 2010-03-05 17:04:34Z mmoorkamp $";
00040 
00041 int main(int argc, char *argv[])
00042   {
00043     // write some info
00044     cout << " This is datarec: Calculate receiver functions from input data"
00045         << endl;
00046     cout << " Reads in radial and vertical components in SAC format" << endl;
00047     cout
00048         << " Outputs a file with the name of the radial component and .rec appended"
00049         << endl;
00050     cout << " Some behaviour can be configured with the file calcrec.conf"
00051         << endl;
00052     cout << " This is Version: " << version << endl << endl;
00053     string modelfilename;
00054 
00055     CalcRecConf Config;
00056     SeismicDataComp Radial, Vertical;
00057     ResPkModel Model;
00058     string outfilename;
00059     try
00060       {
00061         //get the settings from the configuration file
00062         Config.GetData("calcrec.conf");
00063         //the default method is spectral division
00064         RecCalc::trfmethod rfmethod = RecCalc::specdiv;
00065         if (Config.recmethod == "iterdecon")
00066           {
00067             rfmethod = RecCalc::iterdecon;
00068           }
00069         string radfilename, verfilename;
00070         //get the names for the radial and vertical components
00071         //either from the command line or by asking the user
00072         if (argc == 3)
00073           {
00074             radfilename = argv[1];
00075             verfilename = argv[2];
00076           }
00077         else
00078           {
00079             radfilename = AskFilename("Radial Component: ");
00080             verfilename = AskFilename("Vertical Component: ");
00081           }
00082         //the receiver function name is determined from the radial component
00083         outfilename = radfilename + ".rec";
00084         //read in the two components
00085         Radial.ReadData(radfilename);
00086         Vertical.ReadData(verfilename);
00087         if (Config.upperfreq > 0.0 && Config.lowerfreq > 0.0
00088             && Config.upperfreq > Config.lowerfreq)
00089           {
00090             const double lowfilfreq = Config.lowerfreq * Radial.GetDt();
00091             const double upfilfreq = Config.upperfreq * Radial.GetDt();
00092             SimpleBp Bandpass(lowfilfreq,upfilfreq);
00093             std::transform(Radial.GetData().begin(),Radial.GetData().end(),Radial.GetData().begin(),Bandpass);
00094             std::transform(Vertical.GetData().begin(),Vertical.GetData().end(),Vertical.GetData().begin(),Bandpass);
00095           }
00096         //initialize the object to calculate receiver functions with some essential parameters
00097         RecCalc
00098             Receiver(Config.shift, Config.sigma, Config.cc, false, rfmethod);
00099         //do we want the initial correlation peak to have an amplitude of 1 ?
00100         Receiver.SetNormalize(Config.normalize);
00101         SeismicDataComp RecFunc;
00102         //calculate the receiver function
00103         Receiver.CalcRecData(Radial, Vertical, RecFunc);
00104         //write out a sac file with the receiver function
00105         RecFunc.WriteAsSac(outfilename);
00106       } catch (FatalException &e)
00107       {
00108         cerr << e.what() << endl; // if something fails print error
00109         return -1; // and stop execution
00110       }
00111   }

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