cag++.cpp

Go to the documentation of this file.
00001 /*!
00002  * \file
00003  * This is the cagniard algorithm to calculate synthetic 1D forward responses for MT.
00004  *  It reads in model files in the following simple format:
00005  * <TABLE>
00006  * <TR> <TD> No. of layers </TD> </TR>
00007  * <TR> <TD> Thickness in km </TD>  <TD> Resistivity in \f$\Omega m\f$  </TD></TR>
00008  * </TABLE>
00009  *
00010  * The user has to specify the output filename without the ending. ".mtt" will be appended
00011  * automatically to indicate that this file is in Goettingen .mtt format.
00012  *
00013  * There are two different modes: In standard mode (mode 0)
00014  * the frequencies at which the responses are
00015  * calculated are based on some realistic frequencies used in deep MT surveys (300Hz - 10.000s).
00016  * In mode 1 the user can specify a window length and sampling rate and the output frequencies are
00017  * based on the fft of a windows with those parameters. This is only useful for some special
00018  * processing applications and might be removed in the future.
00019  */
00020 
00021 #include <iostream>
00022 #include <string>
00023 #include "Util.h"
00024 #include "C1DMTSynthData.h"
00025 #include <iterator>
00026 
00027 using namespace std;
00028 using namespace gplib;
00029 
00030 int main(int argc, char *argv[])
00031   {
00032     string version =
00033         "$Id: cag++.cpp 20 2005-11-11 12:57:01 +0100 (Fr, 11 Nov 2005) max $";
00034     cout << endl << endl;
00035     cout << "Program " << version << endl;
00036     cout << "Calculates 1D MT Responses from input models " << endl;
00037     cout
00038         << "Based on Cagniard algorithm, with stability enhancements taken from A. Avdeeva "
00039         << endl;
00040 
00041     C1DMTSynthData Synthetic; // create Object for Calculation of Synthetics
00042 
00043 
00044     double samplerate, freqstep;
00045     int samplelength;
00046     const double eps = 1e-5;
00047     string modelfilename, mttfilename;
00048     int mode = 0;
00049     try
00050       {
00051         if (argc == 2)
00052           {
00053             modelfilename = argv[1];
00054             mttfilename = modelfilename;
00055             mode = 0;
00056           }
00057         else
00058           {
00059             modelfilename = AskFilename("Model filename: ");
00060 
00061             cout << "Output Format is .mtt ! Do not append ending. " << endl;
00062             mttfilename = AskFilename("Output filename: ");
00063 
00064             cout
00065                 << "Use Mode = 0 for standard calculation with fixed frequencies (long period) "
00066                 << endl;
00067             cout
00068                 << "Use Mode = 1 if you want frequencies to be calculated from sample rate and window length."
00069                 << endl;
00070             cout
00071                 << "Use Mode = 2 if you want to specify the frequency range and sampling."
00072                 << endl;
00073             cout << "Mode: ";
00074             cin >> mode;
00075           }
00076         Synthetic.ReadModel(modelfilename); // read in model
00077         switch (mode)
00078           {
00079         case 1: //if we want frequencies for a certain window length and sampling rate
00080           {
00081             cout << "Sampling rate in Hz: "; //ask
00082             cin >> samplerate;
00083             cout << "Length for continuous sample (number of samples): ";
00084             cin >> samplelength;
00085             freqstep = samplerate / samplelength;
00086             trealdata frequency;
00087             frequency.push_back(eps); //zero frequency means not valid so we use a small value for the static
00088             for (int i = 1; i < samplelength / 2; ++i) // add frequencies
00089               {
00090                 frequency.push_back(freqstep * i);
00091               }
00092             Synthetic.SetFrequencies(frequency);//copy them to forward calculation object
00093             break;
00094           }
00095         case 2:
00096           {
00097             double minfreq = 0.0;
00098             cout << "Minimum frequency in Hz: ";
00099             cin >> minfreq;
00100             double maxfreq = 0.0;
00101             cout << "Maximum frequency in Hz: ";
00102             cin >> maxfreq;
00103             double sampling = 0.0;
00104             cout << "Frequencies per decade: ";
00105             cin >> sampling;
00106 
00107             minfreq = log10(minfreq);
00108             maxfreq = log10(maxfreq);
00109             double step = 1.0 / sampling;
00110             trealdata frequency;
00111             for (double currfreq = minfreq; currfreq < maxfreq; currfreq
00112                 += step)
00113               {
00114                 frequency.push_back(std::pow(10.0,currfreq));
00115               }
00116             Synthetic.SetFrequencies(frequency);//copy them to forward calculation object
00117             break;
00118           }
00119           }
00120 
00121         Synthetic.CalcSynthetic(); // Calculate Model
00122         Synthetic.WriteAsMtt(mttfilename); // Write out Mtt file
00123       } catch (FatalException &e)
00124       {
00125         cerr << e.what() << endl;
00126         return -1;
00127       }
00128   }

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