9 void Interpolate(
const std::vector<double> &xvalues,
const std::vector<double> &yvalues,
10 const std::vector<double> &InterpX, std::vector<double> &InterpY)
12 const size_t ninter = InterpX.size();
14 for (
size_t i = 0; i < ninter; ++i)
16 while (xvalues[currindex] <= InterpX[i] && currindex <= xvalues.size())
18 if ( currindex > xvalues.size())
20 InterpY.push_back(0.0);
24 if (currindex == 0 && InterpX[i] == xvalues[currindex])
26 InterpY.push_back(yvalues[currindex]);
30 if (currindex == xvalues.size() && InterpX[i] == xvalues[currindex - 1])
32 InterpY.push_back(yvalues[currindex - 1]);
36 double curry = yvalues[currindex - 1]
37 + (yvalues[currindex] - yvalues[currindex - 1])
38 / (xvalues[currindex] - xvalues[currindex - 1])
39 * (InterpX[i] - xvalues[currindex - 1]);
40 InterpY.push_back(curry);
49 const std::vector<double> &yvalues,
const std::vector<double> &InterpX,
50 std::vector<double> &InterpY)
52 const size_t ninter = InterpX.size();
54 for (
size_t i = 0; i < ninter; ++i)
56 while (xvalues[currindex] <= InterpX[i] && currindex <= xvalues.size())
58 if ( currindex > xvalues.size())
60 InterpY.push_back(0.0);
64 if (currindex == 0 && InterpX[i] == xvalues[currindex])
66 InterpY.push_back(yvalues[currindex]);
70 if (currindex == xvalues.size() && InterpX[i] == xvalues[currindex - 1])
72 InterpY.push_back(yvalues[currindex - 1]);
76 double curry = std::max(yvalues[currindex - 1], yvalues[currindex]);
77 InterpY.push_back(curry);
85 void SetMissing(std::complex<double> &value,
double &error)
87 value = std::complex<double>(1.0, 1.0);
91 int main(
int argc,
char* argv[])
93 string version =
"$Id: freqinter.cpp 1886 2014-10-29 12:38:46Z mmoorkamp $";
95 cout <<
"Program " << version << endl;
96 cout <<
" Read in several files with MT tensor data" << endl;
97 cout <<
" and keep interpolate between frequencies. The files will be written in"
100 <<
" .mtt format. If the input files were in that format they will be overwritten"
102 cout << endl << endl;
107 std::string infilename;
111 infilename = argv[1];
116 infilename = AskFilename(
"Station Filename: ");
120 const size_t nstats = MTSites.
GetList().size();
124 std::cout <<
"Frequency matrix \n" << std::endl;
125 std::cout << std::setw(12) <<
"Filename ";
127 for (
double freq : MasterFreqs)
129 std::cout << std::setw(10) << freq << std::endl;
131 std::cout << std::endl;
133 std::cout <<
"Frequencies per decade: ";
135 std::cin >> freqperdec;
137 double minfreq = *std::min_element(MasterFreqs.begin(), MasterFreqs.end());
138 double maxfreq = *std::max_element(MasterFreqs.begin(), MasterFreqs.end());
139 double decades = log10(maxfreq) - log10(minfreq);
140 size_t nfreq = ceil(decades * freqperdec);
141 double freqstep = decades / nfreq;
142 std::vector<double> OutFreqs(nfreq);
143 for (
size_t i = 0; i < nfreq; ++i)
145 OutFreqs.at(i) = pow10(log10(minfreq) + freqstep * i);
148 std::cout <<
"Output frequencies: ";
149 std::copy(OutFreqs.begin(), OutFreqs.end(),
150 std::ostream_iterator<double>(std::cout,
" "));
155 const double tolerance = 0.05;
156 for (
size_t i = 0; i < nstats; ++i)
159 std::cout << std::setw(10) << MTSites.
at(i).
GetName();
163 std::vector<double> ZxxR, ZxxI, ZxyR, ZxyI, ZyxR, ZyxI, ZyyR, ZyyI, dZxx,
165 size_t nvals = CurrData.size();
166 for (
size_t j = 0; j < nvals; ++j)
168 auto CurrTensor = CurrData.at(j);
169 ZxxR.push_back(std::real(CurrTensor.GetZxx()));
170 ZxxI.push_back(std::imag(CurrTensor.GetZxx()));
171 ZxyR.push_back(std::real(CurrTensor.GetZxy()));
172 ZxyI.push_back(std::imag(CurrTensor.GetZxy()));
173 ZyxR.push_back(std::real(CurrTensor.GetZyx()));
174 ZyxI.push_back(std::imag(CurrTensor.GetZyx()));
175 ZyyR.push_back(std::real(CurrTensor.GetZyy()));
176 ZyyI.push_back(std::imag(CurrTensor.GetZyy()));
177 dZxx.push_back(CurrTensor.GetdZxx());
178 dZxy.push_back(CurrTensor.GetdZxy());
179 dZyx.push_back(CurrTensor.GetdZyx());
180 dZyy.push_back(CurrTensor.GetdZyy());
182 std::vector<double> IZxxR, IZxxI, IZxyR, IZxyI, IZyxR, IZyxI, IZyyR, IZyyI,
183 IdZxx, IdZxy, IdZyx, IdZyy;
200 for (
size_t j = 0; j < nfreq; ++j)
202 if (IZxxR[j] != 0.0 || IZxxI[j] != 0.0)
204 OutSite.
SetMTData().at(j).SetZxx() = std::complex<double>(IZxxR[j],
206 OutSite.
SetMTData().at(j).SetdZxx() = IdZxx[j];
214 if (IZxyR[j] != 0.0 || IZxyI[j] != 0.0)
216 OutSite.
SetMTData().at(j).SetZxy() = std::complex<double>(IZxyR[j],
218 OutSite.
SetMTData().at(j).SetdZxy() = IdZxy[j];
226 if (IZyxR[j] != 0.0 || IZyxI[j] != 0.0)
228 OutSite.
SetMTData().at(j).SetZyx() = std::complex<double>(IZyxR[j],
230 OutSite.
SetMTData().at(j).SetdZyx() = IdZyx[j];
238 if (IZyyR[j] != 0.0 || IZyyI[j] != 0.0)
240 OutSite.
SetMTData().at(j).SetZyy() = std::complex<double>(IZyyR[j],
242 OutSite.
SetMTData().at(j).SetdZyy() = IdZyy[j];
251 OutList.
GetList().push_back(OutSite);
256 for (
size_t i = 0; i < nstats; ++i)
262 cerr << e.what() << endl;
MTStation & at(int loc)
Get a reference to a site at a given index.
void Interpolate(const std::vector< double > &xvalues, const std::vector< double > &yvalues, const std::vector< double > &InterpX, std::vector< double > &InterpY)
int main(int argc, char *argv[])
The class MTStation is used to store the transfer functions and related information for a MT-site...
void InterpolateError(const std::vector< double > &xvalues, const std::vector< double > &yvalues, const std::vector< double > &InterpX, std::vector< double > &InterpY)
MTStationList holds a number of MTSites, usually associated with a single project, line, etc.
void SetMissing(std::complex< double > &value, double &error)
tStationList & GetList()
Access to the complete vector of Stations.
void WriteAsMtt(const std::string filename)
Write data in goettingen .mtt format.
void GetData(const std::string filename)
Read a list of filenames and the associated data in those files to fill the list. ...
const std::vector< MTTensor > & GetMTData() const
Get the full vector of Tensor elements read only.
std::vector< MTTensor > & SetMTData()
Get the full vector of Tensor elements for reading and writing.
trealdata GetFrequencies() const
return the available frequencies in a single vector
void SetFrequencies(const trealdata &freqs)
Set the frequencies of the tensor elements, invalidates the previously stored impedance data...
The basic exception class for all errors that arise in gplib.