GPLIB++
PTensorMTStation.cpp
Go to the documentation of this file.
1 #include "PTensorMTStation.h"
2 #include <fstream>
3 #include <iomanip>
4 #include "FatalException.h"
5 
6 using namespace std;
7 
8 namespace gplib
9  {
10  PTensorMTStation::PTensorMTStation()
11  {
12  }
13 
14  PTensorMTStation::~PTensorMTStation()
15  {
16  }
17 
18  PTensorMTStation &PTensorMTStation::operator=(const MTStation &MTData)
19  {
20  Tensor.clear(); // clear old data
21  const unsigned int nfrequencies = MTData.GetMTData().size();
22  Tensor.reserve(nfrequencies);
23  for (unsigned int i = 0; i < nfrequencies; ++i)
24  {
25  Tensor.push_back(PTensorMTData(MTData.at(i).GetFrequency(),
26  MTData.at(i).GetPhi11(), MTData.at(i).GetPhi12(),
27  MTData.at(i).GetPhi21(), MTData.at(i).GetPhi22(), 0.0, 0.0,
28  0.0, 0.0));
29  }
30  return *this;
31  }
32 
33  const trealdata PTensorMTStation::GetFrequencies() const
34  {
35  trealdata temp(Tensor.size());
36  transform(Tensor.begin(), Tensor.end(), temp.begin(), mem_fun_ref(
37  &PTensorMTData::GetFrequency));
38  return temp;
39  }
40 
41  void PTensorMTStation::GetData(const std::string &filename)
42  {
43  ifstream infile(filename.c_str());
44  Tensor.clear();
45  double period, phi11, phi12, phi21, phi22, dphi11, dphi12, dphi21,
46  dphi22;
47  while (infile.good())
48  {
49  infile >> period >> phi11 >> dphi11 >> phi12 >> dphi12 >> phi21
50  >> dphi21 >> phi22 >> dphi22;
51  if (infile.good())
52  {
53  Tensor.push_back(PTensorMTData(1. / period, phi11, phi12,
54  phi21, phi22, dphi11, dphi12, dphi21, dphi22));
55  }
56  }
57  if (Tensor.size() < 1)
58  throw FatalException("Ptensor file does not exist or is empty !");
59  }
60 
61  void PTensorMTStation::WriteData(const std::string &filename)
62  {
63  ofstream outfile((filename + ".ptensor").c_str());
64  const unsigned int nfreq = Tensor.size();
65  for (unsigned int i = 0; i < nfreq; ++i)
66  {
67  outfile << 1. / Tensor.at(i).GetFrequency() << " ";
68  outfile << Tensor.at(i).GetPhi11() << " "
69  << Tensor.at(i).GetdPhi11() << " ";
70  outfile << Tensor.at(i).GetPhi12() << " "
71  << Tensor.at(i).GetdPhi12() << " ";
72  outfile << Tensor.at(i).GetPhi21() << " "
73  << Tensor.at(i).GetdPhi21() << " ";
74  outfile << Tensor.at(i).GetPhi22() << " "
75  << Tensor.at(i).GetdPhi22() << endl;
76  }
77  }
78  }
This class is for the special case where we only have phase tensor data and errors, but not the full impedance.
Definition: PTensorMTData.h:12
double GetPhi11() const
All the following quantities are defined in Caldwell GJI 158, 457-469, the phase tensor elements...
Definition: MTTensor.h:422
const MTTensor & at(const unsigned int i) const
direct acces to a tensor at a given index
Definition: MTStation.h:114
double GetPhi21() const
Definition: MTTensor.h:438
double GetFrequency() const
Get the frequency for the impedance.
Definition: MTTensor.h:113
double GetPhi12() const
Definition: MTTensor.h:430
double GetPhi22() const
Definition: MTTensor.h:446
The class MTStation is used to store the transfer functions and related information for a MT-site...
Definition: MTStation.h:17
CMTStation MTData
Definition: cadijoint.cpp:15
const std::vector< MTTensor > & GetMTData() const
Get the full vector of Tensor elements read only.
Definition: MTStation.h:119
The basic exception class for all errors that arise in gplib.