GPLIB++
printmu.cpp
Go to the documentation of this file.
1 #include <iostream>
2 #include <fstream>
3 #include "MTStation.h"
4 #include "MTSampleGenerator.h"
5 #include "Jacknife.h"
6 #include <boost/function.hpp>
7 #include "Util.h"
8 
9 using namespace std;
10 using namespace gplib;
11 
12 /*!
13  * \addtogroup UtilProgs Utility Programs
14  *@{
15  * \file
16  * Calculate various dimensionality indicators for MT data and their errors and write them to a file
17  */
18 
19 //! This helper function calculates the errors for a single parameter and writes the values to a file in ascii format
20 void WriteParameterToFile(const MTStation &Data, const string &filename,
21  boost::function<double (const MTTensor*)> f)
22  {
23  // we use a fixed number of samples for the jacknifing
24  const int errorcases = 10000;
25  const double errorfloor = 0.02;
26  double JackMean, JackErr;
27  ofstream muoutfile(filename.c_str());
28  //for each period
29  for (size_t i = 0; i < Data.GetMTData().size(); ++i)
30  {
31  //calculate the error
32  MTSampleGenerator Generator(f, Data.GetMTData().at(i), errorfloor);
33  Jacknife<MTSampleGenerator> ErrEst(errorcases, Generator);
34  ErrEst.CalcErrors(JackMean, JackErr);
35  // and write period, data, error to a file
36  muoutfile << 1. / Data.GetMTData().at(i).GetFrequency();
37  muoutfile << " " << f(&Data.GetMTData().at(i)) << " " << sqrt(JackErr)
38  << endl;
39  }
40  }
41 
42 int main(int argc, char *argv[])
43  {
44  string infilename;
45  MTStation Data;
46  // find out which file to work on
47  if (argc == 2)
48  {
49  infilename = argv[1];
50  }
51  else
52  {
53  infilename = AskFilename("Infilename: ");
54  }
55  //read in the data from the file
56  Data.GetData(infilename);
57  //write out various dimensionality indicators
58  WriteParameterToFile(Data, infilename + ".mu", &MTTensor::GetMu);
59  WriteParameterToFile(Data, infilename + ".kappa", &MTTensor::GetKappa);
60  WriteParameterToFile(Data, infilename + ".sigma", &MTTensor::GetSigma);
61  WriteParameterToFile(Data, infilename + ".eta", &MTTensor::GetEta);
62  WriteParameterToFile(Data, infilename + ".Q", &MTTensor::GetQ);
63  WriteParameterToFile(Data, infilename + ".I1", &MTTensor::GetI1);
64  WriteParameterToFile(Data, infilename + ".I2", &MTTensor::GetI2);
65  WriteParameterToFile(Data, infilename + ".I3", &MTTensor::GetI3);
66  WriteParameterToFile(Data, infilename + ".I4", &MTTensor::GetI4);
67  WriteParameterToFile(Data, infilename + ".I5", &MTTensor::GetI5);
68  WriteParameterToFile(Data, infilename + ".I6", &MTTensor::GetI6);
69  WriteParameterToFile(Data, infilename + ".I7", &MTTensor::GetI7);
70  //we cannot write this with WriteParameterToFile, so we do it separately
71  ofstream muoutfile((infilename + ".d2").c_str());
72  for (size_t i = 0; i < Data.GetMTData().size(); ++i)
73  {
74  muoutfile << 1. / Data.GetMTData().at(i).GetFrequency();
75  muoutfile << " " << 2 * Data.GetMTData().at(i).GetdBerd()
76  / Data.GetMTData().at(i).GetD2() << endl;
77  }
78 
79  }
80 /*@}*/
81 
void f(vector< double > &v1, vector< double > &v2, vector< double > &v3, vector< double > &v4)
Definition: perftest.cpp:17
virtual void GetData(const std::string filename)
read in data from file, determines format by ending
Definition: MTStation.cpp:597
The class MTStation is used to store the transfer functions and related information for a MT-site...
Definition: MTStation.h:17
Implements the Jacknifing method of error estimation.
Definition: Jacknife.h:20
Generate random elements of a calculated quantity for MT impedance data.
int main()
Definition: angleavg.cpp:12
Stores MT-Tensor components at a single frequency, calculates derived quantities. ...
Definition: MTTensor.h:16
const std::vector< MTTensor > & GetMTData() const
Get the full vector of Tensor elements read only.
Definition: MTStation.h:119
void WriteParameterToFile(const MTStation &Data, const string &filename, boost::function< double(const MTTensor *)> f)
This helper function calculates the errors for a single parameter and writes the values to a file in ...
Definition: printmu.cpp:20