12 #include <boost/function.hpp>
13 #include <boost/bind.hpp>
14 #include <boost/program_options.hpp>
16 #include <boost/progress.hpp>
25 using namespace gplib;
27 namespace po = boost::program_options;
29 string version =
"$Id: ptfreq.cpp 1851 2010-05-18 13:48:45Z mmoorkamp $";
35 int ntestcases = 0,
double errorfloor = 0.02)
38 const unsigned int nstations = StationList.
GetList().size();
40 cout <<
"Processing component: " << compname << endl << endl;
41 boost::progress_display show_progress(nstations);
43 for (
unsigned int i = 0; i < nstations; ++i)
45 string outfilename = StationList.
at(i).
GetName() + compname +
".dat";
46 ofstream outfile(outfilename.c_str());
47 const unsigned int nfreq = StationList.
at(i).
GetMTData().size();
48 for (
unsigned int j = 0; j < nfreq; ++j)
50 outfile << setw(12) << setfill(
' ') << setprecision(4) << 1.
51 / StationList.
at(i).
GetMTData().at(j).GetFrequency();
54 outfile << setw(12) << setfill(
' ') << setprecision(4)
55 << boost::bind(
f, &StationList.
at(i).
GetMTData().at(j))();
59 double JackMean, JackVar;
60 StationList.
at(i).
SetMTData().at(j).SetdZxx() = max(
61 StationList.
at(i).
at(j).
GetdZxx(), errorfloor * abs(
63 StationList.
at(i).
SetMTData().at(j).SetdZxy() = max(
64 StationList.
at(i).
at(j).
GetdZxy(), errorfloor * abs(
66 StationList.
at(i).
SetMTData().at(j).SetdZyx() = max(
67 StationList.
at(i).
at(j).
GetdZyx(), errorfloor * abs(
69 StationList.
at(i).
SetMTData().at(j).SetdZyy() = max(
70 StationList.
at(i).
at(j).
GetdZyy(), errorfloor * abs(
74 ErrEst.CalcErrors(JackMean, JackVar);
75 outfile <<
" " << setw(12) << setfill(
' ') << setprecision(4)
83 std::cout << std::endl << std::endl;
86 int main(
int argc,
char *argv[])
88 string infilename, outfilename;
91 cout <<
" This is ptfreq, calculate phasetensor elipses etc. from MT data"
94 <<
" Reads in a list of stations and outputs one file for each station"
97 <<
" Each file contains the frequency dependency of a component of the phase tensor for one site"
99 cout <<
" File endings will be automatically appended." << endl;
101 <<
" For error calculation, numbers < 2 will be interpreted as no error calculation."
103 cout <<
" This is Version: " <<
version << endl << endl;
105 int nbootsamples = -1;
106 double errorfloor = 0.0;
107 po::options_description desc(
"Allowed options");
108 desc.add_options()(
"help",
"produce help message")(
"nboot", po::value<int>(
109 &nbootsamples)->default_value(10000),
110 "The number of samples for bootstrap error calculation")(
"errfloor",
111 po::value<double>(&errorfloor)->default_value(0.01),
112 "The minimum relative error to assume for the data")
113 (
"input-file", po::value< string>(&infilename),
"input file");
115 po::positional_options_description p;
116 p.add(
"input-file", -1);
118 po::variables_map vm;
119 po::store(po::command_line_parser(argc, argv).
120 options(desc).positional(p).run(), vm);
123 if (vm.count(
"help")) {
124 cout << desc <<
"\n";
137 nbootsamples, errorfloor);
139 nbootsamples, errorfloor);
141 nbootsamples, errorfloor);
143 nbootsamples, errorfloor);
145 nbootsamples, errorfloor);
147 nbootsamples, errorfloor);
149 nbootsamples, errorfloor);
151 nbootsamples, errorfloor);
153 nbootsamples, errorfloor);
156 for (vector<MTStation>::iterator it = MTSites.GetList().begin(); it
157 != MTSites.GetList().end(); ++it)
160 string rotfilename = it->GetName() +
"_phiall.dat";
161 ofstream rotfile(rotfilename.c_str());
162 for (
unsigned int i = 0; i < it->GetFrequencies().size(); ++i)
164 rotfile << setw(12) << setfill(
' ') << setprecision(4) << 1.
165 / it->GetFrequencies().at(i);
166 rotfile << setw(12) << setfill(
' ') << setprecision(4)
167 << it->GetMTData().at(i).GetPhi11();
168 rotfile << setw(12) << setfill(
' ') << setprecision(4)
169 << it->GetMTData().at(i).GetPhi12();
170 rotfile << setw(12) << setfill(
' ') << setprecision(4)
171 << it->GetMTData().at(i).GetPhi21();
172 rotfile << setw(12) << setfill(
' ') << setprecision(4)
173 << it->GetMTData().at(i).GetPhi22();
174 rotfile << setw(12) << setfill(
' ') << setprecision(4)
175 << it->GetMTData().at(i).GetAlpha_phi();
176 rotfile << setw(12) << setfill(
' ') << setprecision(4)
177 << it->GetMTData().at(i).GetBeta_phi();
178 rotfile << setw(12) << setfill(
' ') << setprecision(4)
179 << it->GetMTData().at(i).GetPhiMax();
180 rotfile << setw(12) << setfill(
' ') << setprecision(4)
181 << it->GetMTData().at(i).GetPhiMin() << endl;
187 string ptfilename = it->GetName() +
"_ptellip.dat";
188 ofstream ptfile(ptfilename.c_str());
189 for (
unsigned int i = 0; i < it->GetMTData().size(); ++i)
192 ptfile << setw(12) << setfill(
' ') << setprecision(4) << 1.
193 / it->GetMTData().at(i).GetFrequency();
195 ptfile << setw(12) << setfill(
' ') << setprecision(4) << 1.0;
198 ptfile << setw(12) << setfill(
' ') << setprecision(4)
199 << it->GetMTData().at(i).GetBeta_phi() * 180. / PI;
201 ptfile << setw(12) << setfill(
' ') << setprecision(4) << 90
202 - (it->GetMTData().at(i).GetPhiStrike()) * 180. / PI;
204 ptfile << setw(12) << setfill(
' ') << setprecision(4)
205 << it->GetMTData().at(i).GetPhiMax();
207 ptfile << setw(12) << setfill(
' ') << setprecision(4)
208 << it->GetMTData().at(i).GetPhiMin();
215 cerr << e.what() << endl;
MTStation & at(int loc)
Get a reference to a site at a given index.
double GetdZxx() const
Return tensor element errors.
double GetPhi11() const
All the following quantities are defined in Caldwell GJI 158, 457-469, the phase tensor elements...
const MTTensor & at(const unsigned int i) const
direct acces to a tensor at a given index
double GetPhiEllip() const
const float T[frequenzen]
void f(vector< double > &v1, vector< double > &v2, vector< double > &v3, vector< double > &v4)
std::complex< double > GetZyx() const
std::complex< double > GetZxy() const
double GetAlpha_phi() const
MTStationList holds a number of MTSites, usually associated with a single project, line, etc.
Implements the Jacknifing method of error estimation.
Generate random elements of a calculated quantity for MT impedance data.
tStationList & GetList()
Access to the complete vector of Stations.
Stores MT-Tensor components at a single frequency, calculates derived quantities. ...
void PrintComponent(const std::string &compname, boost::function< const T(const MTTensor *)> f, MTStationList &StationList, int ntestcases=0, double errorfloor=0.02)
This helper function prints out a single phase tensor component together with error information to a ...
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::complex< double > GetZxx() const
std::vector< MTTensor > & SetMTData()
Get the full vector of Tensor elements for reading and writing.
std::complex< double > GetZyy() const
Return tensor elements.
double GetBeta_phi() const
The basic exception class for all errors that arise in gplib.