cag++.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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;
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);
00077 switch (mode)
00078 {
00079 case 1:
00080 {
00081 cout << "Sampling rate in Hz: ";
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);
00088 for (int i = 1; i < samplelength / 2; ++i)
00089 {
00090 frequency.push_back(freqstep * i);
00091 }
00092 Synthetic.SetFrequencies(frequency);
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);
00117 break;
00118 }
00119 }
00120
00121 Synthetic.CalcSynthetic();
00122 Synthetic.WriteAsMtt(mttfilename);
00123 } catch (FatalException &e)
00124 {
00125 cerr << e.what() << endl;
00126 return -1;
00127 }
00128 }