chooserecfunc.cpp
Go to the documentation of this file.00001 #include <grace_np.h>
00002 #include <boost/filesystem/operations.hpp>
00003 #include <boost/filesystem/path.hpp>
00004 #include <boost/filesystem/convenience.hpp>
00005 #include <boost/version.hpp>
00006 #include <iostream>
00007 #include <gsl/gsl_math.h>
00008 #include <string>
00009 #include "SeismicDataComp.h"
00010
00011 namespace fs = boost::filesystem;
00012 using namespace std;
00013 using namespace gplib;
00014
00015 int main(int argc, char* argv[])
00016 {
00017 SeismicDataComp RecData;
00018
00019 string version = "$Id: chooserecfunc.cpp 1837 2009-11-27 14:17:58Z mmoorkamp $";
00020 cout << endl << endl;
00021 cout << "Program " << version << endl;
00022 cout
00023 << " Display all the receiver functions in a directory and select good and bad ones "
00024 << endl;
00025 cout << " Receiver functions are identified by file ending '.rec' " << endl;
00026 cout
00027 << " Type 'g' for good or 'b' for bad after receiver function is displayed "
00028 << endl;
00029 cout << endl << endl;
00030
00031 fs::path full_path(fs::initial_path());
00032
00033 if ( !fs::exists(full_path) )
00034 {
00035 std::cout << "\nNot found: " << full_path.native_file_string()
00036 << std::endl;
00037 return 1;
00038 }
00039 std::string statid;
00040 cout << "Enter station identifier: ";
00041 cin >> statid;
00042 if (GraceOpen(2048) == -1)
00043 {
00044 fprintf(stderr, "Can't run Grace. \n");
00045 exit(EXIT_FAILURE);
00046 }
00047 fs::directory_iterator end_iter;
00048 std::string response;
00049 for (fs::directory_iterator dir_itr(full_path); dir_itr != end_iter; ++dir_itr)
00050 {
00051
00052
00053 if (extension(*dir_itr) == ".rec" && dir_itr->leaf().find(statid) != string::npos)
00054 {
00055 std::string currentname(dir_itr->leaf());
00056 RecData.ReadData(currentname);
00057 const double dt = RecData.GetDt();
00058 for (size_t i = 0; i < RecData.GetData().size() && GraceIsOpen(); i++)
00059 {
00060 if (finite(RecData.GetData().at(i)))
00061
00062 {
00063 GracePrintf("g0.s0 point %f, %f", i *dt, RecData.GetData().at(i));
00064 }
00065 else
00066
00067 {
00068 GracePrintf("g0.s0 point %f, %f", i *dt, 10000.0);
00069 }
00070 }
00071 double ymax = *max_element(RecData.GetData().begin(), RecData.GetData().end());
00072 double ymin = *min_element(RecData.GetData().begin(), RecData.GetData().end());
00073 GracePrintf("world xmax %f", RecData.GetData().size()*dt);
00074 GracePrintf("world ymax %f", ymax);
00075 GracePrintf("world ymin %f", ymin);
00076 GracePrintf("xaxis tick major %f", RecData.GetData().size()*dt/5.0);
00077 GracePrintf("xaxis tick minor %f", RecData.GetData().size()*dt/10.0);
00078 GracePrintf("yaxis tick major %f", ymax/5);
00079 GracePrintf("yaxis tick minor %f", ymax/10);
00080 GraceCommand(("title \" "+ currentname +" \" ").c_str());
00081 GracePrintf("redraw");
00082 std::cin >> response;
00083 if (response == "b")
00084 fs::rename(currentname, fs::path("bad") / currentname);
00085 else if (response == "g")
00086 fs::rename(currentname, fs::path("good") / currentname);
00087 else
00088 cout <<"Invalid reply, ignoring file !" << endl;
00089 GracePrintf("KILL g0.s0");
00090
00091 std::cout << "Data size: " << RecData.GetData().size() << std::endl;
00092 }
00093
00094
00095
00096 }
00097 if (GraceIsOpen())
00098 GraceClose();
00099 }