GPLIB++
diffangle.cpp
Go to the documentation of this file.
1 #include "MTStationList.h"
2 #include "CFatalException.h"
3 #include <iostream>
4 #include <string>
5 #include <fstream>
6 #include <iomanip>
7 #include "Jacknife.h"
8 
9 using namespace std;
10 using namespace gplib;
11 
12 string version = "$Id: diffangle.cpp 1816 2009-09-07 11:28:35Z mmoorkamp $";
13 void PromptAndReadStationFile(MTStationList &List, std::string prompt)
14  {
15  string listname;
16  cout << prompt;
17  cin >> listname;
18  try
19  {
20  List.GetData(listname); //try to read in all station data
21  } catch (FatalException &e)
22  {
23  cerr << e.what() << endl; // if something fails print error
24  exit(100); // and stop execution
25  }
26  }
27 
28 int PromptAndReadFreqIndex(MTStationList &List, std::string prompt)
29  {
30  cout << prompt << endl << endl;
31  cout << "Available Periods: " << List.GetCommonFrequencies().size() << endl;
32 
33  for (trealdata::const_iterator frequencies =
34  List.GetCommonFrequencies().begin(); frequencies
35  != List.GetCommonFrequencies().end(); ++frequencies)
36  {
37  cout << setw(9) << setfill(' ') << setprecision(4) << distance(
38  List.GetCommonFrequencies().begin(), frequencies);
39  cout << setw(15) << setfill(' ') << setprecision(8) << 1.
40  / (*frequencies) << endl;
41  }
42  int freqindex;
43  cout << "Select frequency Index: ";
44  cin >> freqindex;
45  return freqindex;
46  }
47 
48 int main()
49  {
50  string list1, list2; //storing names for input and root of output
51  cout
52  << " This is diffangle, calculate the difference in strike angle and phase split"
53  << endl; // write some info
54  cout << " for corresponding sites in two different lists. " << endl << endl;
55 
56  MTStationList MTSites1; // object for the first station list
57  PromptAndReadStationFile(MTSites1, "Station List 1:");
58  MTStationList MTSites2; // object for the second station list
59  PromptAndReadStationFile(MTSites2, "Station List 2:");
60  tStatSyncPair StatSync = FindCorrespondingSites(MTSites1.GetList(),
61  MTSites2.GetList());
62  const std::vector<tindexvector> freqindices1(MTSites1.GetComFreqIndices());
63  const std::vector<tindexvector> freqindices2(MTSites2.GetComFreqIndices());
64  int SelectedFreq1 = PromptAndReadFreqIndex(MTSites1, "List 1");
65  int SelectedFreq2 = PromptAndReadFreqIndex(MTSites2, "List 2");
66  ofstream outfile("out");
67  const int nbootsamples = 10000;
68  CJacknife ErrEst(nbootsamples); //init error estimation object
69  for (size_t i = 0; i < StatSync.size(); ++i)
70  {
71 
72  double strikediff = (StatSync.at(i).first->GetMTData().at(
73  freqindices1.at(i).at(SelectedFreq1)).GetPhiEllip()
74  - StatSync.at(i).second->GetMTData().at(freqindices2.at(i).at(
75  SelectedFreq2)).GetPhiEllip());
76  double strikeerr, dummy;
77  ErrEst.CalcErrors(&MTTensor::GetPhiEllip,
78  StatSync.at(i).first->GetMTData().at(freqindices1.at(i).at(
79  SelectedFreq1)), dummy, strikeerr);
80  double phidiffdiff = (StatSync.at(i).first->GetMTData().at(
81  freqindices1.at(i).at(SelectedFreq1)).GetBeta_phi()
82  - StatSync.at(i).second->GetMTData().at(freqindices2.at(i).at(
83  SelectedFreq2)).GetBeta_phi());
84  double phidifferr;
85  ErrEst.CalcErrors(&MTTensor::GetBeta_phi,
86  StatSync.at(i).first->GetMTData().at(freqindices1.at(i).at(
87  SelectedFreq1)), dummy, phidifferr);
88  outfile << phidiffdiff * 180. / PI << " " << strikediff << " "
89  << phidifferr * 180. / PI << " " << strikeerr << endl;
90  }
91  }
string version
Definition: diffangle.cpp:12
int PromptAndReadFreqIndex(MTStationList &List, std::string prompt)
Definition: diffangle.cpp:28
std::vector< std::pair< MTStation *, MTStation * > > tStatSyncPair
Definition: MTStationList.h:57
tStatSyncPair FindCorrespondingSites(tStationList &MasterList, tStationList &SlaveList)
Take two different site Lists of arguments and return a vector of pairs that point to the sites that ...
const trealdata & GetCommonFrequencies()
Get a vector with frequencies that are common to all sites.
Definition: MTStationList.h:47
MTStationList holds a number of MTSites, usually associated with a single project, line, etc.
Definition: MTStationList.h:16
int main()
Definition: diffangle.cpp:48
tStationList & GetList()
Access to the complete vector of Stations.
Definition: MTStationList.h:31
void PromptAndReadStationFile(MTStationList &List, std::string prompt)
Definition: diffangle.cpp:13
const std::vector< tindexvector > & GetComFreqIndices()
Get a vector that for each site contains the indices to the common frequencies.
Definition: MTStationList.h:42
void GetData(const std::string filename)
Read a list of filenames and the associated data in those files to fill the list. ...
double GetPhiEllip(const double phi11, const double phi12, const double phi21, const double phi22)
Return the ellipticity of the phase tensor.
Definition: ptfuncs.h:104
The basic exception class for all errors that arise in gplib.