From d3f4b1d5a0df8929a97adb3da646e0a4f5b20ac7 Mon Sep 17 00:00:00 2001 From: Carles Fernandez Date: Tue, 25 Feb 2020 08:25:19 +0100 Subject: [PATCH] Apply clang-tidy, document new flags --- src/utils/rinex-tools/README.md | 6 +- src/utils/rinex-tools/obsdiff.cc | 126 ++++++++++++++++--------------- 2 files changed, 68 insertions(+), 64 deletions(-) diff --git a/src/utils/rinex-tools/README.md b/src/utils/rinex-tools/README.md index 32f525d4f..946a29a7c 100644 --- a/src/utils/rinex-tools/README.md +++ b/src/utils/rinex-tools/README.md @@ -71,8 +71,8 @@ Despite this flexibility, we recommend using only a single form: `--variable=val Available command-line flags: -| **Command-line flag** | **Default value** | **Description** | -|:------------------------------:|:-----------------:|:-----------------| +| **Command-line flag** | **Default value** | **Description** | +|:-------------------------:|:-----------------:|:-----------------| | `--skip_obs_transitory_s` | `30.0` | Skip the initial observable outputs to avoid transitory results [s]. | | `--skip_obs_ends_s` | `5.0` | Skip the lasts observable outputs to avoid transitory results [s]. | | `--single_diffs` | `false` | [`true`, `false`]: If `true`, the program also computes the single difference errors for [Carrier Phase](https://gnss-sdr.org/docs/sp-blocks/observables/#carrier-phase-measurement) and [Doppler](https://gnss-sdr.org/docs/sp-blocks/observables/#doppler-shift-measurement) measurements (requires LO synchronization between receivers). | @@ -81,4 +81,6 @@ Available command-line flags: | `--dupli_sat_prns` | `1,2,3,4` | List of duplicated satellites PRN pairs (_i.e._, `1,2,3,4` indicates that the PRNs 1,2 share the same orbit. The same applies for PRNs 3,4). | | `--ref_rinex_obs` | `reference.obs` | Filename of reference RINEX observation file. | | `--test_rinex_obs` | `test.obs` | Filename of tested RINEX observation file. | +| `--remove_rx_clock_error` | `false` | Compute and remove the receivers clock error prior to compute observable differences (requires a valid RINEX nav file for both receivers) | +| `--rinex_nav` | `reference.nav` | Filename of reference RINEX navigation file. Only needed if `remove_rx_clock_error` is set to `true`. | | `--show_plots` | `true` | [`true`, `false`]: If `true`, and if [gnuplot](http://www.gnuplot.info/) is found on the system, displays results plots on screen. Please set it to `false` for non-interactive testing. | diff --git a/src/utils/rinex-tools/obsdiff.cc b/src/utils/rinex-tools/obsdiff.cc index ead64638f..8a4e7119c 100644 --- a/src/utils/rinex-tools/obsdiff.cc +++ b/src/utils/rinex-tools/obsdiff.cc @@ -81,7 +81,7 @@ bool file_exist(const char* fileName) } -std::map ReadRinexObs(std::string rinex_file, char system, std::string signal) +std::map ReadRinexObs(const std::string& rinex_file, char system, const std::string& signal) { std::map obs_map; if (not file_exist(rinex_file.c_str())) @@ -121,9 +121,9 @@ std::map ReadRinexObs(std::string rinex_file, char system, std:: std::cout << "Reading RINEX OBS file " << rinex_file << " ...\n"; while (r_ref >> r_ref_data) { - for (std::set::iterator prn_it = PRN_set.begin(); prn_it != PRN_set.end(); ++prn_it) + for (auto& prn_it : PRN_set) { - prn.id = *prn_it; + prn.id = prn_it; gpstk::CommonTime time = r_ref_data.time; double sow(static_cast(time).sow); @@ -334,7 +334,7 @@ void carrier_phase_double_diff( std::vector time_vector(measurement_time.colptr(0), measurement_time.colptr(0) + measurement_time.n_rows); - if (measurement_time.size() > 0) + if (!measurement_time.empty()) { // debug // std::vector tmp_time_vec(measurement_time.colptr(0), @@ -424,7 +424,7 @@ void carrier_phase_single_diff( std::vector time_vector(measurement_time.colptr(0), measurement_time.colptr(0) + measurement_time.n_rows); - if (measurement_time.size() > 0) + if (!measurement_time.empty()) { // 2. RMSE arma::vec err; @@ -517,7 +517,7 @@ void carrier_doppler_double_diff( std::vector time_vector(measurement_time.colptr(0), measurement_time.colptr(0) + measurement_time.n_rows); - if (measurement_time.size() > 0) + if (!measurement_time.empty()) { // debug // std::vector tmp_time_vec(measurement_time.colptr(0), @@ -606,7 +606,7 @@ void carrier_doppler_single_diff( std::vector time_vector(measurement_time.colptr(0), measurement_time.colptr(0) + measurement_time.n_rows); - if (measurement_time.size() > 0) + if (!measurement_time.empty()) { // 2. RMSE arma::vec err; @@ -698,7 +698,7 @@ void code_pseudorange_double_diff( std::vector time_vector(measurement_time.colptr(0), measurement_time.colptr(0) + measurement_time.n_rows); - if (measurement_time.size() > 0) + if (!measurement_time.empty()) { // debug // std::vector tmp_time_vec(measurement_time.colptr(0), @@ -789,7 +789,7 @@ void code_pseudorange_single_diff( std::vector time_vector(measurement_time.colptr(0), measurement_time.colptr(0) + measurement_time.n_rows); - if (measurement_time.size() > 0) + if (!measurement_time.empty()) { // 2. RMSE arma::vec err; @@ -843,7 +843,7 @@ void code_pseudorange_single_diff( } -double compute_rx_clock_error(std::string rinex_nav_filename, std::string rinex_obs_file) +double compute_rx_clock_error(const std::string& rinex_nav_filename, const std::string& rinex_obs_file) { std::cout << "Computing receiver's clock error..." << std::endl; if (not file_exist(rinex_nav_filename.c_str())) @@ -879,7 +879,10 @@ double compute_rx_clock_error(std::string rinex_nav_filename, std::string rinex_ rnffs >> hdr; // Storing the ephemeris in "bcstore" - while (rnffs >> rne) bcestore.addEphemeris(rne); + while (rnffs >> rne) + { + bcestore.addEphemeris(rne); + } // Setting the criteria for looking up ephemeris bcestore.SearchNear(); @@ -1063,7 +1066,7 @@ void RINEX_doublediff_dupli_sat() // special test mode for duplicated satellites // read rinex receiver-under-test observations std::map test_obs = ReadRinexObs(FLAGS_test_rinex_obs, 'G', std::string("1C\0")); - if (test_obs.size() == 0) + if (test_obs.empty()) { return; } @@ -1071,12 +1074,12 @@ void RINEX_doublediff_dupli_sat() double initial_transitory_s = FLAGS_skip_obs_transitory_s; std::cout << "Skipping initial transitory of " << initial_transitory_s << " [s]" << std::endl; arma::uvec index; - for (std::map::iterator it = test_obs.begin(); it != test_obs.end(); ++it) + for (auto& test_ob : test_obs) { - index = arma::find(it->second.col(0) >= (it->second.col(0)(0) + initial_transitory_s), 1, "first"); + index = arma::find(test_ob.second.col(0) >= (test_ob.second.col(0)(0) + initial_transitory_s), 1, "first"); if ((!index.empty()) and (index(0) > 0)) { - it->second.shed_rows(0, index(0)); + test_ob.second.shed_rows(0, index(0)); } } @@ -1134,7 +1137,7 @@ void RINEX_doublediff(bool remove_rx_clock_error) // read rinex receiver-under-test observations std::map test_obs = ReadRinexObs(FLAGS_test_rinex_obs, 'G', std::string("1C\0")); - if (ref_obs.size() == 0 or test_obs.size() == 0) + if (ref_obs.empty() or test_obs.empty()) { return; } @@ -1155,12 +1158,12 @@ void RINEX_doublediff(bool remove_rx_clock_error) double initial_transitory_s = FLAGS_skip_obs_transitory_s; std::cout << "Skipping initial transitory of " << initial_transitory_s << " [s]" << std::endl; arma::uvec index; - for (std::map::iterator it = test_obs.begin(); it != test_obs.end(); ++it) + for (auto& test_ob : test_obs) { - index = arma::find(it->second.col(0) >= (it->second.col(0)(0) + initial_transitory_s), 1, "first"); + index = arma::find(test_ob.second.col(0) >= (test_ob.second.col(0)(0) + initial_transitory_s), 1, "first"); if ((!index.empty()) and (index(0) > 0)) { - it->second.shed_rows(0, index(0)); + test_ob.second.shed_rows(0, index(0)); } } @@ -1174,12 +1177,12 @@ void RINEX_doublediff(bool remove_rx_clock_error) // cut rover vector std::cout << "Cutting rover observations vector end.." << std::endl; arma::uvec index2; - for (std::map::iterator it = test_obs.begin(); it != test_obs.end(); ++it) + for (auto& test_ob : test_obs) { - index = arma::find(it->second.col(0) >= ref_obs_time.back(), 1, "first"); + index = arma::find(test_ob.second.col(0) >= ref_obs_time.back(), 1, "first"); if ((!index.empty()) and (index(0) > 0)) { - it->second.shed_rows(index(0), it->second.n_rows - 1); + test_ob.second.shed_rows(index(0), test_ob.second.n_rows - 1); } } } @@ -1188,12 +1191,12 @@ void RINEX_doublediff(bool remove_rx_clock_error) // there are more base observations than rover observations // cut base vector std::cout << "Cutting base observations vector end.." << std::endl; - for (std::map::iterator it = ref_obs.begin(); it != ref_obs.end(); ++it) + for (auto& ref_ob : ref_obs) { - index = arma::find(it->second.col(0) >= test_obs_time.back(), 1, "first"); + index = arma::find(ref_ob.second.col(0) >= test_obs_time.back(), 1, "first"); if ((!index.empty()) and (index(0) > 0)) { - it->second.shed_rows(index(0), it->second.n_rows - 1); + ref_ob.second.shed_rows(index(0), ref_ob.second.n_rows - 1); } } } @@ -1204,74 +1207,74 @@ void RINEX_doublediff(bool remove_rx_clock_error) double skip_ends_s = FLAGS_skip_obs_ends_s; std::cout << "Skipping last " << skip_ends_s << " [s] of observations" << std::endl; - for (std::map::iterator it = test_obs.begin(); it != test_obs.end(); ++it) + for (auto& test_ob : test_obs) { - index = arma::find(it->second.col(0) >= (test_obs_time.back() - skip_ends_s), 1, "first"); + index = arma::find(test_ob.second.col(0) >= (test_obs_time.back() - skip_ends_s), 1, "first"); if ((!index.empty()) and (index(0) > 0)) { - it->second.shed_rows(index(0), it->second.n_rows - 1); + test_ob.second.shed_rows(index(0), test_ob.second.n_rows - 1); } } - for (std::map::iterator it = ref_obs.begin(); it != ref_obs.end(); ++it) + for (auto& ref_ob : ref_obs) { - index = arma::find(it->second.col(0) >= (ref_obs_time.back() - skip_ends_s), 1, "first"); + index = arma::find(ref_ob.second.col(0) >= (ref_obs_time.back() - skip_ends_s), 1, "first"); if ((!index.empty()) and (index(0) > 0)) { - it->second.shed_rows(index(0), it->second.n_rows - 1); + ref_ob.second.shed_rows(index(0), ref_ob.second.n_rows - 1); } } // Save observations in .mat files std::cout << "Saving RAW observables inputs to .mat files...\n"; - for (std::map::iterator it = ref_obs.begin(); it != ref_obs.end(); ++it) + for (auto& ref_ob : ref_obs) { // std::cout << it->first << " => " << it->second.n_rows << '\n'; // std::cout << it->first << " has NaN values: " << it->second.has_nan() << '\n'; - std::vector tmp_time_vec(it->second.col(0).colptr(0), - it->second.col(0).colptr(0) + it->second.n_rows); - std::vector tmp_vector(it->second.col(2).colptr(0), - it->second.col(2).colptr(0) + it->second.n_rows); - save_mat_xy(tmp_time_vec, tmp_vector, std::string("ref_doppler_sat" + std::to_string(it->first))); + std::vector tmp_time_vec(ref_ob.second.col(0).colptr(0), + ref_ob.second.col(0).colptr(0) + ref_ob.second.n_rows); + std::vector tmp_vector(ref_ob.second.col(2).colptr(0), + ref_ob.second.col(2).colptr(0) + ref_ob.second.n_rows); + save_mat_xy(tmp_time_vec, tmp_vector, std::string("ref_doppler_sat" + std::to_string(ref_ob.first))); - std::vector tmp_vector2(it->second.col(3).colptr(0), - it->second.col(3).colptr(0) + it->second.n_rows); - save_mat_xy(tmp_time_vec, tmp_vector2, std::string("ref_carrier_phase_sat" + std::to_string(it->first))); + std::vector tmp_vector2(ref_ob.second.col(3).colptr(0), + ref_ob.second.col(3).colptr(0) + ref_ob.second.n_rows); + save_mat_xy(tmp_time_vec, tmp_vector2, std::string("ref_carrier_phase_sat" + std::to_string(ref_ob.first))); - std::vector tmp_vector3(it->second.col(1).colptr(0), - it->second.col(1).colptr(0) + it->second.n_rows); - save_mat_xy(tmp_time_vec, tmp_vector3, std::string("ref_pseudorange_sat" + std::to_string(it->first))); + std::vector tmp_vector3(ref_ob.second.col(1).colptr(0), + ref_ob.second.col(1).colptr(0) + ref_ob.second.n_rows); + save_mat_xy(tmp_time_vec, tmp_vector3, std::string("ref_pseudorange_sat" + std::to_string(ref_ob.first))); } - for (std::map::iterator it = test_obs.begin(); it != test_obs.end(); ++it) + for (auto& test_ob : test_obs) { // std::cout << it->first << " => " << it->second.n_rows << '\n'; // std::cout << it->first << " has NaN values: " << it->second.has_nan() << '\n'; - std::vector tmp_time_vec(it->second.col(0).colptr(0), - it->second.col(0).colptr(0) + it->second.n_rows); - std::vector tmp_vector(it->second.col(2).colptr(0), - it->second.col(2).colptr(0) + it->second.n_rows); - save_mat_xy(tmp_time_vec, tmp_vector, std::string("measured_doppler_sat" + std::to_string(it->first))); + std::vector tmp_time_vec(test_ob.second.col(0).colptr(0), + test_ob.second.col(0).colptr(0) + test_ob.second.n_rows); + std::vector tmp_vector(test_ob.second.col(2).colptr(0), + test_ob.second.col(2).colptr(0) + test_ob.second.n_rows); + save_mat_xy(tmp_time_vec, tmp_vector, std::string("measured_doppler_sat" + std::to_string(test_ob.first))); - std::vector tmp_vector2(it->second.col(3).colptr(0), - it->second.col(3).colptr(0) + it->second.n_rows); - save_mat_xy(tmp_time_vec, tmp_vector2, std::string("measured_carrier_phase_sat" + std::to_string(it->first))); + std::vector tmp_vector2(test_ob.second.col(3).colptr(0), + test_ob.second.col(3).colptr(0) + test_ob.second.n_rows); + save_mat_xy(tmp_time_vec, tmp_vector2, std::string("measured_carrier_phase_sat" + std::to_string(test_ob.first))); - std::vector tmp_vector3(it->second.col(1).colptr(0), - it->second.col(1).colptr(0) + it->second.n_rows); - save_mat_xy(tmp_time_vec, tmp_vector3, std::string("measured_pseudorange_sat" + std::to_string(it->first))); + std::vector tmp_vector3(test_ob.second.col(1).colptr(0), + test_ob.second.col(1).colptr(0) + test_ob.second.n_rows); + save_mat_xy(tmp_time_vec, tmp_vector3, std::string("measured_pseudorange_sat" + std::to_string(test_ob.first))); } // select reference satellite std::set PRN_set = available_gps_prn; double min_range = std::numeric_limits::max(); int ref_sat_id = 1; - for (std::set::iterator ref_prn_it = PRN_set.begin(); ref_prn_it != PRN_set.end(); ++ref_prn_it) + for (auto& ref_prn_it : PRN_set) { - if (ref_obs.find(*ref_prn_it) != ref_obs.end() and test_obs.find(*ref_prn_it) != test_obs.end()) + if (ref_obs.find(ref_prn_it) != ref_obs.end() and test_obs.find(ref_prn_it) != test_obs.end()) { - if (test_obs.at(*ref_prn_it).at(0, 1) < min_range) + if (test_obs.at(ref_prn_it).at(0, 1) < min_range) { - min_range = test_obs.at(*ref_prn_it).at(0, 1); - ref_sat_id = *ref_prn_it; + min_range = test_obs.at(ref_prn_it).at(0, 1); + ref_sat_id = ref_prn_it; } } } @@ -1280,9 +1283,8 @@ void RINEX_doublediff(bool remove_rx_clock_error) if (ref_obs.find(ref_sat_id) != ref_obs.end() and test_obs.find(ref_sat_id) != test_obs.end()) { std::cout << "Using reference satellite SV " << ref_sat_id << " with minimum range of " << min_range << " [meters]" << std::endl; - for (std::set::iterator current_prn_it = PRN_set.begin(); current_prn_it != PRN_set.end(); ++current_prn_it) + for (auto& current_sat_id : PRN_set) { - int current_sat_id = *current_prn_it; if (current_sat_id != ref_sat_id) { if (ref_obs.find(current_sat_id) != ref_obs.end() and test_obs.find(current_sat_id) != test_obs.end())