GPLIB++
cag++.cpp
Go to the documentation of this file.
1 /*!
2  * \file
3  * This is the cagniard algorithm to calculate synthetic 1D forward responses for MT.
4  * It reads in model files in the following simple format:
5  * <TABLE>
6  * <TR> <TD> No. of layers </TD> </TR>
7  * <TR> <TD> Thickness in km </TD> <TD> Resistivity in \f$\Omega m\f$ </TD></TR>
8  * </TABLE>
9  *
10  * The user has to specify the output filename without the ending. ".mtt" will be appended
11  * automatically to indicate that this file is in Goettingen .mtt format.
12  *
13  * There are two different modes: In standard mode (mode 0)
14  * the frequencies at which the responses are
15  * calculated are based on some realistic frequencies used in deep MT surveys (300Hz - 10.000s).
16  * In mode 1 the user can specify a window length and sampling rate and the output frequencies are
17  * based on the fft of a windows with those parameters. This is only useful for some special
18  * processing applications and might be removed in the future.
19  */
20 
21 #include <iostream>
22 #include <string>
23 #include "Util.h"
24 #include "C1DMTSynthData.h"
25 #include <iterator>
26 
27 using namespace std;
28 using namespace gplib;
29 
30 int main(int argc, char *argv[])
31  {
32  string version =
33  "$Id: cag++.cpp 20 2005-11-11 12:57:01 +0100 (Fr, 11 Nov 2005) max $";
34  cout << endl << endl;
35  cout << "Program " << version << endl;
36  cout << "Calculates 1D MT Responses from input models " << endl;
37  cout
38  << "Based on Cagniard algorithm, with stability enhancements taken from A. Avdeeva "
39  << endl;
40 
41  C1DMTSynthData Synthetic; // create Object for Calculation of Synthetics
42 
43 
44  double samplerate, freqstep;
45  int samplelength;
46  const double eps = 1e-5;
47  string modelfilename, mttfilename;
48  int mode = 0;
49  try
50  {
51  if (argc == 2)
52  {
53  modelfilename = argv[1];
54  mttfilename = modelfilename;
55  mode = 0;
56  }
57  else
58  {
59  modelfilename = AskFilename("Model filename: ");
60 
61  cout << "Output Format is .mtt ! Do not append ending. " << endl;
62  mttfilename = AskFilename("Output filename: ");
63 
64  cout
65  << "Use Mode = 0 for standard calculation with fixed frequencies (long period) "
66  << endl;
67  cout
68  << "Use Mode = 1 if you want frequencies to be calculated from sample rate and window length."
69  << endl;
70  cout
71  << "Use Mode = 2 if you want to specify the frequency range and sampling."
72  << endl;
73  cout << "Mode: ";
74  cin >> mode;
75  }
76  Synthetic.ReadModel(modelfilename); // read in model
77  switch (mode)
78  {
79  case 1: //if we want frequencies for a certain window length and sampling rate
80  {
81  cout << "Sampling rate in Hz: "; //ask
82  cin >> samplerate;
83  cout << "Length for continuous sample (number of samples): ";
84  cin >> samplelength;
85  freqstep = samplerate / samplelength;
86  trealdata frequency;
87  frequency.push_back(eps); //zero frequency means not valid so we use a small value for the static
88  for (int i = 1; i < samplelength / 2; ++i) // add frequencies
89  {
90  frequency.push_back(freqstep * i);
91  }
92  Synthetic.SetFrequencies(frequency);//copy them to forward calculation object
93  break;
94  }
95  case 2:
96  {
97  double minfreq = 0.0;
98  cout << "Minimum frequency in Hz: ";
99  cin >> minfreq;
100  double maxfreq = 0.0;
101  cout << "Maximum frequency in Hz: ";
102  cin >> maxfreq;
103  double sampling = 0.0;
104  cout << "Frequencies per decade: ";
105  cin >> sampling;
106  if (maxfreq < minfreq)
107  {
108  std::cerr << "Maximum frequency less than minimum freuqency !"
109  << std::endl;
110  return 100;
111  }
112  if (sampling <= 0.0)
113  {
114  std::cerr << "Sampling step is not positive !" << std::endl;
115  return 200;
116  }
117  minfreq = log10(minfreq);
118  maxfreq = log10(maxfreq);
119  double step = 1.0 / sampling;
120  trealdata frequency;
121  for (double currfreq = minfreq; currfreq < maxfreq; currfreq
122  += step)
123  {
124  frequency.push_back(std::pow(10.0, currfreq));
125  }
126  Synthetic.SetFrequencies(frequency);//copy them to forward calculation object
127  break;
128  }
129  }
130 
131  Synthetic.CalcSynthetic(); // Calculate Model
132  Synthetic.WriteAsMtt(mttfilename); // Write out Mtt file
133  } catch (FatalException &e)
134  {
135  cerr << e.what() << endl;
136  return -1;
137  }
138  }
void ReadModel(std::string filename)
Read the model from a file.
int main(int argc, char *argv[])
Definition: cag++.cpp:30
virtual void CalcSynthetic()
Calculate the synthetic data given the previously set parameters.
void WriteAsMtt(const std::string filename)
Write data in goettingen .mtt format.
Definition: MTStation.cpp:681
Calculate synthetic MT data for a 1D model using Cagniard's algorithm.
string version
Definition: makeinput.cpp:16
void SetFrequencies(const trealdata &freqs)
Set the frequencies of the tensor elements, invalidates the previously stored impedance data...
Definition: MTStation.cpp:144
The basic exception class for all errors that arise in gplib.