GPLIB++
ptselect.cpp
Go to the documentation of this file.
1 #include <grace_np.h>
2 #include "boost/filesystem/operations.hpp"
3 #include "boost/filesystem/path.hpp"
4 #include "boost/filesystem/convenience.hpp"
5 #include <iostream>
6 #include <string>
7 #include "PTensorMTStation.h"
8 #include "Util.h"
9 
10 namespace fs = boost::filesystem;
11 using namespace std;
12 using namespace gplib;
13 
14 int main(int argc, char* argv[])
15  {
16  PTensorMTStation Data;
17 
18  string version = "$Id: ptselect.cpp 1870 2011-04-01 11:55:47Z mmoorkamp $";
19  cout << endl << endl;
20  cout << "Program " << version << endl;
21  cout
22  << " Display all phase tensor files in a directory and select good and bad ones "
23  << endl;
24  cout << " Files are identified by file ending '.ptensor' " << endl;
25  cout << " Type 'g' for good or 'b' for bad after data is displayed "
26  << endl;
27  cout << endl << endl;
28 
29  //if they do not exist,
30  //we create two directories, baddir for the files we sort out
31  //and gooddir for the files we want to use
32  const std::string baddir = "bad";
33  const std::string gooddir = "good";
34  if (!fs::exists(baddir))
35  fs::create_directory(baddir);
36  if (!fs::exists(gooddir))
37  fs::create_directory(gooddir);
38  fs::path full_path(fs::initial_path());
39 
40  if (!fs::exists(full_path))
41  {
42  std::cout << "\nNot found: " << full_path
43  << std::endl;
44  return 1;
45  }
46  //we compare all data with the data from one site
47  //this makes it easier to see differences and similarities
48  std::string mastersite = AskFilename("Enter site for permanent display: ");
49  //initialize xmgrace which we use for displaying the data
50  if (GraceOpen(2048) == -1)
51  {
52  fprintf(stderr, "Can't run Grace. \n");
53  exit(EXIT_FAILURE);
54  }
55  fs::directory_iterator end_iter;
56  std::string response;
57  Data.GetData(mastersite);
58  //plot phase tensor elements for master site
59  for (unsigned int i = 0; i < Data.GetTensor().size() && GraceIsOpen(); i++)
60  {
61  GracePrintf("g0.s0 point %f, %f", 1. / Data.at(i).GetFrequency(),
62  Data.at(i).GetPhi11());
63  GracePrintf("g0.s1 point %f, %f", 1. / Data.at(i).GetFrequency(),
64  Data.at(i).GetPhi12());
65  GracePrintf("g0.s2 point %f, %f", 1. / Data.at(i).GetFrequency(),
66  Data.at(i).GetPhi21());
67  GracePrintf("g0.s3 point %f, %f", 1. / Data.at(i).GetFrequency(),
68  Data.at(i).GetPhi22());
69  }
70  GracePrintf("xaxes scale logarithmic");
71  GracePrintf("autoscale");
72  GracePrintf("redraw");
73  cin >> response;
74  //plot the other elements
75  for (fs::directory_iterator dir_itr(full_path); //for all files in current directory
76  dir_itr != end_iter; ++dir_itr)
77  {
78  if (extension(*dir_itr) == ".ptensor")
79  {
80  std::string currentname(dir_itr->path().filename().string());
81  Data.GetData(currentname);
82  for (unsigned int i = 0; i < Data.GetTensor().size()
83  && GraceIsOpen(); i++)
84  {
85  GracePrintf("g0.s4 point %f, %f", 1.
86  / Data.at(i).GetFrequency(), Data.at(i).GetPhi11());
87  GracePrintf("g0.s5 point %f, %f", 1.
88  / Data.at(i).GetFrequency(), Data.at(i).GetPhi12());
89  GracePrintf("g0.s6 point %f, %f", 1.
90  / Data.at(i).GetFrequency(), Data.at(i).GetPhi21());
91  GracePrintf("g0.s7 point %f, %f", 1.
92  / Data.at(i).GetFrequency(), Data.at(i).GetPhi22());
93  }
94 
95  GraceCommand(("title \" " + currentname + " \" ").c_str());
96  GracePrintf("redraw");
97  std::cin >> response;
98 
99  if (response == "b")
100  fs::rename(currentname, baddir);
101  else if (response == "g")
102  fs::rename(currentname, gooddir);
103  else
104  cout << "Invalid reply, ignoring file !" << endl;
105  GracePrintf("KILL g0.s4");
106  GracePrintf("KILL g0.s5");
107  GracePrintf("KILL g0.s6");
108  GracePrintf("KILL g0.s7");
109  //GraceFlush();
110  }
111 
112  }
113  if (GraceIsOpen())
114  GraceClose();
115  }
double GetPhi22() const
Definition: PTensorMTData.h:49
double GetFrequency() const
Definition: PTensorMTData.h:89
std::vector< PTensorMTData > & GetTensor()
const PTensorMTData & at(const unsigned int i) const
double GetPhi11() const
Definition: PTensorMTData.h:25
int main(int argc, char *argv[])
Definition: ptselect.cpp:14
void GetData(const std::string &filename)
double GetPhi12() const
Definition: PTensorMTData.h:33
string version
Definition: makeinput.cpp:16
double GetPhi21() const
Definition: PTensorMTData.h:41