1
0
mirror of https://github.com/gnss-sdr/gnss-sdr synced 2024-12-15 12:40:35 +00:00

Improve saving of observables dump: let the user to specify a full path and to deactivate generation of .mat files with dump_mat=false

This commit is contained in:
Carles Fernandez 2018-10-30 02:18:32 +01:00
parent 1f6ae8ea16
commit f2468e9e17
5 changed files with 60 additions and 29 deletions

View File

@ -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)

View File

@ -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_;

View File

@ -16,11 +16,11 @@
# along with GNSS-SDR. If not, see <https://www.gnu.org/licenses/>.
#
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
)

View File

@ -32,6 +32,7 @@
#include "hybrid_observables_cc.h"
#include "display.h"
#include "GPS_L1_CA.h"
#include "gnss_sdr_create_directory.h"
#include <glog/logging.h>
#include <gnuradio/io_signature.h>
#include <matio.h>
@ -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<Gnss_Synchro>(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

View File

@ -48,7 +48,7 @@ class hybrid_observables_cc;
typedef boost::shared_ptr<hybrid_observables_cc> 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;