From f2468e9e17c1ec07efe20d55eaace1a19b95945a Mon Sep 17 00:00:00 2001 From: Carles Fernandez Date: Tue, 30 Oct 2018 02:18:32 +0100 Subject: [PATCH] Improve saving of observables dump: let the user to specify a full path and to deactivate generation of .mat files with dump_mat=false --- .../adapters/hybrid_observables.cc | 9 +-- .../observables/adapters/hybrid_observables.h | 1 + .../gnuradio_blocks/CMakeLists.txt | 4 +- .../gnuradio_blocks/hybrid_observables_cc.cc | 68 +++++++++++++------ .../gnuradio_blocks/hybrid_observables_cc.h | 7 +- 5 files changed, 60 insertions(+), 29 deletions(-) diff --git a/src/algorithms/observables/adapters/hybrid_observables.cc b/src/algorithms/observables/adapters/hybrid_observables.cc index 4313edfee..cf03f2d2c 100644 --- a/src/algorithms/observables/adapters/hybrid_observables.cc +++ b/src/algorithms/observables/adapters/hybrid_observables.cc @@ -38,21 +38,22 @@ using google::LogMessage; HybridObservables::HybridObservables(ConfigurationInterface* configuration, - std::string role, unsigned int in_streams, unsigned int out_streams) : - role_(role), in_streams_(in_streams), out_streams_(out_streams) + std::string role, unsigned int in_streams, unsigned int out_streams) : role_(role), in_streams_(in_streams), out_streams_(out_streams) { std::string default_dump_filename = "./observables.dat"; DLOG(INFO) << "role " << role; dump_ = configuration->property(role + ".dump", false); + dump_mat_ = configuration->property(role + ".dump_mat", true); dump_filename_ = configuration->property(role + ".dump_filename", default_dump_filename); - observables_ = hybrid_make_observables_cc(in_streams_, out_streams_, dump_, dump_filename_); + observables_ = hybrid_make_observables_cc(in_streams_, out_streams_, dump_, dump_mat_, dump_filename_); DLOG(INFO) << "Observables block ID (" << observables_->unique_id() << ")"; } HybridObservables::~HybridObservables() -{} +{ +} void HybridObservables::connect(gr::top_block_sptr top_block) diff --git a/src/algorithms/observables/adapters/hybrid_observables.h b/src/algorithms/observables/adapters/hybrid_observables.h index 57883374a..1beb968fa 100644 --- a/src/algorithms/observables/adapters/hybrid_observables.h +++ b/src/algorithms/observables/adapters/hybrid_observables.h @@ -83,6 +83,7 @@ public: private: hybrid_observables_cc_sptr observables_; bool dump_; + bool dump_mat_; std::string dump_filename_; std::string role_; unsigned int in_streams_; diff --git a/src/algorithms/observables/gnuradio_blocks/CMakeLists.txt b/src/algorithms/observables/gnuradio_blocks/CMakeLists.txt index d42409de6..82c5bc243 100644 --- a/src/algorithms/observables/gnuradio_blocks/CMakeLists.txt +++ b/src/algorithms/observables/gnuradio_blocks/CMakeLists.txt @@ -16,11 +16,11 @@ # along with GNSS-SDR. If not, see . # -set(OBS_GR_BLOCKS_SOURCES +set(OBS_GR_BLOCKS_SOURCES hybrid_observables_cc.cc ) -set(OBS_GR_BLOCKS_HEADERS +set(OBS_GR_BLOCKS_HEADERS hybrid_observables_cc.h ) diff --git a/src/algorithms/observables/gnuradio_blocks/hybrid_observables_cc.cc b/src/algorithms/observables/gnuradio_blocks/hybrid_observables_cc.cc index 81d385cf5..f9ed992b8 100644 --- a/src/algorithms/observables/gnuradio_blocks/hybrid_observables_cc.cc +++ b/src/algorithms/observables/gnuradio_blocks/hybrid_observables_cc.cc @@ -32,6 +32,7 @@ #include "hybrid_observables_cc.h" #include "display.h" #include "GPS_L1_CA.h" +#include "gnss_sdr_create_directory.h" #include #include #include @@ -45,42 +46,70 @@ using google::LogMessage; -hybrid_observables_cc_sptr hybrid_make_observables_cc(unsigned int nchannels_in, unsigned int nchannels_out, bool dump, std::string dump_filename) +hybrid_observables_cc_sptr hybrid_make_observables_cc(unsigned int nchannels_in, unsigned int nchannels_out, bool dump, bool dump_mat, std::string dump_filename) { - return hybrid_observables_cc_sptr(new hybrid_observables_cc(nchannels_in, nchannels_out, dump, dump_filename)); + return hybrid_observables_cc_sptr(new hybrid_observables_cc(nchannels_in, nchannels_out, dump, dump_mat, dump_filename)); } hybrid_observables_cc::hybrid_observables_cc(uint32_t nchannels_in, uint32_t nchannels_out, bool dump, + bool dump_mat, std::string dump_filename) : gr::block("hybrid_observables_cc", gr::io_signature::make(nchannels_in, nchannels_in, sizeof(Gnss_Synchro)), gr::io_signature::make(nchannels_out, nchannels_out, sizeof(Gnss_Synchro))) { d_dump = dump; + d_dump_mat = dump_mat and d_dump; + d_dump_filename = dump_filename; d_nchannels_out = nchannels_out; d_nchannels_in = nchannels_in; - d_dump_filename = dump_filename; T_rx_clock_step_samples = 0U; d_gnss_synchro_history = new Gnss_circular_deque(500, d_nchannels_out); // ############# ENABLE DATA FILE LOG ################# if (d_dump) { - if (!d_dump_file.is_open()) + std::string dump_path; + // Get path + if (d_dump_filename.find_last_of("/") != std::string::npos) { - try - { - d_dump_file.exceptions(std::ifstream::failbit | std::ifstream::badbit); - d_dump_file.open(d_dump_filename.c_str(), std::ios::out | std::ios::binary); - LOG(INFO) << "Observables dump enabled Log file: " << d_dump_filename.c_str(); - } - catch (const std::ifstream::failure &e) - { - LOG(WARNING) << "Exception opening observables dump file " << e.what(); - d_dump = false; - } + std::string dump_filename_ = d_dump_filename.substr(d_dump_filename.find_last_of("/") + 1); + dump_path = d_dump_filename.substr(0, d_dump_filename.find_last_of("/")); + d_dump_filename = dump_filename_; + } + else + { + dump_path = std::string("."); + } + if (d_dump_filename.empty()) + { + d_dump_filename = "observables.dat"; + } + // remove extension if any + if (d_dump_filename.substr(1).find_last_of(".") != std::string::npos) + { + d_dump_filename = d_dump_filename.substr(0, d_dump_filename.find_last_of(".")); + } + d_dump_filename.append(".dat"); + d_dump_filename = dump_path + boost::filesystem::path::preferred_separator + d_dump_filename; + // create directory + if (!gnss_sdr_create_directory(dump_path)) + { + std::cerr << "GNSS-SDR cannot create dump file for the Observables block. Wrong permissions?" << std::endl; + d_dump = false; + } + d_dump_file.exceptions(std::ifstream::failbit | std::ifstream::badbit); + try + { + d_dump_file.open(d_dump_filename.c_str(), std::ios::out | std::ios::binary); + LOG(INFO) << "Observables dump enabled Log file: " << d_dump_filename.c_str(); + } + catch (const std::ifstream::failure &e) + { + LOG(WARNING) << "Exception opening observables dump file " << e.what(); + d_dump = false; } } T_rx_TOW_ms = 0U; @@ -107,11 +136,9 @@ hybrid_observables_cc::~hybrid_observables_cc() LOG(WARNING) << "Exception in destructor closing the dump file " << ex.what(); } } - if (d_dump) + if (d_dump_mat) { - std::cout << "Writing observables .mat files ..."; save_matfile(); - std::cout << " done." << std::endl; } } @@ -119,14 +146,16 @@ hybrid_observables_cc::~hybrid_observables_cc() int32_t hybrid_observables_cc::save_matfile() { // READ DUMP FILE + std::string dump_filename = d_dump_filename; std::ifstream::pos_type size; int32_t number_of_double_vars = 7; int32_t epoch_size_bytes = sizeof(double) * number_of_double_vars * d_nchannels_out; std::ifstream dump_file; + std::cout << "Generating .mat file for " << dump_filename << std::endl; dump_file.exceptions(std::ifstream::failbit | std::ifstream::badbit); try { - dump_file.open(d_dump_filename.c_str(), std::ios::binary | std::ios::ate); + dump_file.open(dump_filename.c_str(), std::ios::binary | std::ios::ate); } catch (const std::ifstream::failure &e) { @@ -553,7 +582,6 @@ int hybrid_observables_cc::general_work(int noutput_items __attribute__((unused) { out[n][0] = epoch_data.at(n); } - if (d_dump) { // MULTIPLEXED FILE RECORDING - Record results to file diff --git a/src/algorithms/observables/gnuradio_blocks/hybrid_observables_cc.h b/src/algorithms/observables/gnuradio_blocks/hybrid_observables_cc.h index 0eed5da1b..033da7a25 100644 --- a/src/algorithms/observables/gnuradio_blocks/hybrid_observables_cc.h +++ b/src/algorithms/observables/gnuradio_blocks/hybrid_observables_cc.h @@ -48,7 +48,7 @@ class hybrid_observables_cc; typedef boost::shared_ptr hybrid_observables_cc_sptr; hybrid_observables_cc_sptr -hybrid_make_observables_cc(unsigned int nchannels_in, unsigned int nchannels_out, bool dump, std::string dump_filename); +hybrid_make_observables_cc(unsigned int nchannels_in, unsigned int nchannels_out, bool dump, bool dump_mat, std::string dump_filename); /*! * \brief This class implements a block that computes observables @@ -63,8 +63,8 @@ public: private: friend hybrid_observables_cc_sptr - hybrid_make_observables_cc(uint32_t nchannels_in, uint32_t nchannels_out, bool dump, std::string dump_filename); - hybrid_observables_cc(uint32_t nchannels_in, uint32_t nchannels_out, bool dump, std::string dump_filename); + hybrid_make_observables_cc(uint32_t nchannels_in, uint32_t nchannels_out, bool dump, bool dump_mat, std::string dump_filename); + hybrid_observables_cc(uint32_t nchannels_in, uint32_t nchannels_out, bool dump, bool dump_mat, std::string dump_filename); bool interpolate_data(Gnss_Synchro& out, const uint32_t& ch, const double& ti); bool interp_trk_obs(Gnss_Synchro& interpolated_obs, const uint32_t& ch, const uint64_t& rx_clock); double compute_T_rx_s(const Gnss_Synchro& a); @@ -82,6 +82,7 @@ private: uint32_t T_rx_TOW_ms; uint32_t T_rx_TOW_offset_ms; bool d_dump; + bool d_dump_mat; uint32_t d_nchannels_in; uint32_t d_nchannels_out; std::string d_dump_filename;