GPLIB++
chooserecfunc.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 <boost/algorithm/string.hpp>
6 #include <boost/version.hpp>
7 #include <iostream>
8 #include <string>
9 #include <cstdio>
10 #include "SeismicDataComp.h"
11 
12 namespace fs = boost::filesystem;
13 using namespace std;
14 using namespace gplib;
15 
16 int main(int argc, char* argv[])
17  {
19 
20  string version =
21  "$Id: chooserecfunc.cpp 1870 2011-04-01 11:55:47Z mmoorkamp $";
22  cout << endl << endl;
23  cout << "Program " << version << endl;
24  cout
25  << " Display all the receiver functions in a directory and select good and bad ones "
26  << endl;
27  cout << " Receiver functions are identified by file ending '.rec' " << endl;
28  cout
29  << " Type 'g' for good or 'b' for bad after receiver function is displayed "
30  << endl;
31  cout << endl << endl;
32 
33  fs::path full_path(fs::initial_path());
34 
35  if (!fs::exists(full_path))
36  {
37  std::cout << "\nNot found: " << full_path << std::endl;
38  return 1;
39  }
40  std::string statid;
41  cout << "Enter station identifier: ";
42  cin >> statid;
43  if (GraceOpen(2048) == -1)
44  {
45  fprintf(stderr, "Can't run Grace. \n");
46  exit(EXIT_FAILURE);
47  }
48  fs::directory_iterator end_iter;
49  std::string response;
50  for (fs::directory_iterator dir_itr(full_path); dir_itr != end_iter; ++dir_itr)
51  {
52  if (extension(*dir_itr) == ".rec" && boost::algorithm::contains(
53  dir_itr->path().filename().string(), statid))
54  {
55  std::string currentname(dir_itr->path().filename().string());
56  RecData.ReadData(currentname);
57  const double dt = RecData.GetDt();
58  for (size_t i = 0; i < RecData.GetData().size() && GraceIsOpen(); i++)
59  {
60  if (finite(RecData.GetData().at(i))) // if we have a valid value we display it
61 
62  {
63  GracePrintf("g0.s0 point %f, %f", i * dt,
64  RecData.GetData().at(i));
65  }
66  else //otherwise we show junk to signal bad data without upsetting xmgrace
67 
68  {
69  GracePrintf("g0.s0 point %f, %f", i * dt, 10000.0);
70  }
71  }
72  double ymax = *max_element(RecData.GetData().begin(),
73  RecData.GetData().end());
74  double ymin = *min_element(RecData.GetData().begin(),
75  RecData.GetData().end());
76  GracePrintf("world xmax %f", RecData.GetData().size() * dt);
77  GracePrintf("world ymax %f", ymax);
78  GracePrintf("world ymin %f", ymin);
79  GracePrintf("xaxis tick major %f", RecData.GetData().size() * dt
80  / 5.0);
81  GracePrintf("xaxis tick minor %f", RecData.GetData().size() * dt
82  / 10.0);
83  GracePrintf("yaxis tick major %f", ymax / 5);
84  GracePrintf("yaxis tick minor %f", ymax / 10);
85  GraceCommand(("title \" " + currentname + " \" ").c_str());
86  GracePrintf("redraw");
87  std::cin >> response;
88  if (response == "b")
89  fs::rename(currentname, fs::path("bad") / currentname);
90  else if (response == "g")
91  fs::rename(currentname, fs::path("good") / currentname);
92  else
93  cout << "Invalid reply, ignoring file !" << endl;
94  GracePrintf("KILL g0.s0");
95  //GraceFlush();
96  std::cout << "Data size: " << RecData.GetData().size() << std::endl;
97  }
98  //else
99  // std::cout << "Filename: " << dir_itr->leaf() << " " << extension(*dir_itr) << std::endl;
100 
101  }
102  if (GraceIsOpen())
103  GraceClose();
104  }
int ReadData(const std::string &filename, tseismicdataformat format=sac)
Read in data from a file, as we cannot determine the type from the ending we have to provide it...
std::vector< double > & GetData()
Access for data vector, for ease of use and efficiency we return a reference.
string version
Definition: makeinput.cpp:16
int main(int argc, char *argv[])
double GetDt() const
Return dt in s.
SeismicDataComp RecData
Definition: cadijoint.cpp:16