GNSS-SDR  0.0.21
An Open Source GNSS Software Defined Receiver
rinex_printer.h
Go to the documentation of this file.
1 /*!
2  * \file rinex_printer.h
3  * \brief Interface of a RINEX 2.11 / 3.01 printer
4  * See ftp://igs.org/pub/data/format/rinex301.pdf
5  *
6  * Receiver Independent EXchange Format (RINEX):
7  * The first proposal for the Receiver Independent Exchange Format RINEX
8  * was developed by the Astronomical Institute of the University of Berne
9  * for the easy exchange of the GPS data to be collected during the large
10  * European GPS campaign EUREF 89, which involved more than 60 GPS receivers
11  * of 4 different manufacturers.
12  * The governing aspect during the development was the fact that most geodetic
13  * processing software for GPS data use a well-defined set of observables:
14  * 1) The carrier-phase measurement at one or both carriers (actually being a
15  * measurement on the beat frequency between the received carrier of the
16  * satellite signal and a receiver-generated reference frequency).
17  * 2) The pseudorange (code) measurement , equivalent to the difference
18  * of the time of reception (expressed in the time frame of the receiver)
19  * and the time of transmission (expressed in the time frame of the satellite)
20  * of a distinct satellite signal.
21  * 3) The observation time being the reading of the receiver clock at the
22  * instant of validity of the carrier-phase and/or the code measurements.
23  * Note: A collection of the formats currently used by the IGS can be found
24  * here: https://igs.org/formats-and-standards/
25  * \author Carles Fernandez Prades, 2011-2026. cfernandez(at)cttc.es
26  * \author Mathieu Favreau, 2025-2026. favreau.mathieu(at)hotmail.com
27  *
28  * -----------------------------------------------------------------------------
29  *
30  * GNSS-SDR is a Global Navigation Satellite System software-defined receiver.
31  * This file is part of GNSS-SDR.
32  *
33  * Copyright (C) 2010-2026 (see AUTHORS file for a list of contributors)
34  * SPDX-License-Identifier: GPL-3.0-or-later
35  *
36  * -----------------------------------------------------------------------------
37  */
38 
39 #ifndef GNSS_SDR_RINEX_PRINTER_H
40 #define GNSS_SDR_RINEX_PRINTER_H
41 
42 #include "signal_enabled_flags.h"
43 #include <boost/date_time/posix_time/posix_time.hpp>
44 #include <cstdint> // for int32_t
45 #include <cstdlib> // for strtol, strtod
46 #include <fstream> // for fstream
47 #include <map> // for map
48 #include <string> // for string
49 #include <vector> // for vector
50 
51 
52 /** \addtogroup PVT
53  * \{ */
54 /** \addtogroup PVT_libs
55  * \{ */
56 
57 
59 class Beidou_Dnav_Iono;
61 class Galileo_Ephemeris;
62 class Galileo_Iono;
63 class Galileo_Utc_Model;
67 class Gnss_Synchro;
68 class Gps_CNAV_Ephemeris;
69 class Gps_CNAV_Iono;
70 class Gps_CNAV_Utc_Model;
71 class Gps_Ephemeris;
72 class Gps_Iono;
74 class Gps_Utc_Model;
75 class Rtklib_Solver;
76 
77 
78 /*!
79  * \brief Class that handles the generation of Receiver
80  * INdependent EXchange format (RINEX) files
81  */
83 {
84 public:
85  /*!
86  * \brief Constructor. Creates GNSS Navigation and Observables RINEX files.
87  */
88  explicit Rinex_Printer(uint32_t signal_enabled_flags,
89  int version = 3,
90  const std::string& base_path = ".",
91  const std::string& base_name = "-",
92  bool pre_2009_file = false);
93 
94  /*!
95  * \brief Destructor. Removes created files if empty.
96  */
98 
99  /*!
100  * \brief Print RINEX annotation. If it is the first annotation, it also
101  * prints the RINEX headers for navigation and observation files. If it is
102  * not the first annotation, it only annotates the observation, and updates
103  * the navigation header if UTC data was not available when writing it for
104  * the first time.
105  *
106  */
107  void print_rinex_annotation(const Rtklib_Solver* pvt_solver,
108  const std::map<int, Gnss_Synchro>& gnss_observables_map,
109  double rx_time,
110  bool flag_write_RINEX_obs_output);
111 
112  /*!
113  * \brief Print RINEX annotation for GPS NAV message
114  */
115  void log_rinex_nav_gps_nav(const std::map<int32_t, Gps_Ephemeris>& new_eph);
116 
117  /*!
118  * \brief Print RINEX annotation for GPS CNAV message
119  */
120  void log_rinex_nav_gps_cnav(const std::map<int32_t, Gps_CNAV_Ephemeris>& new_cnav_eph);
121 
122  /*!
123  * \brief Print RINEX annotation for Galileo NAV message
124  */
125  void log_rinex_nav_gal_nav(const std::map<int32_t, Galileo_Ephemeris>& new_gal_eph);
126 
127  /*!
128  * \brief Print RINEX annotation for Glonass GNAV message
129  */
130  void log_rinex_nav_glo_gnav(const std::map<int32_t, Glonass_Gnav_Ephemeris>& new_glo_eph);
131 
132  /*!
133  * \brief Print RINEX annotation for BeiDou DNAV message
134  */
135  void log_rinex_nav_bds_dnav(const std::map<int32_t, Beidou_Dnav_Ephemeris>& new_bds_eph);
136 
137  /*!
138  * \brief Returns true is the RINEX file headers are already written
139  */
140  inline bool is_rinex_header_written() const
141  {
142  return d_rinex_header_written;
143  }
144 
145  /*!
146  * \brief Returns name of RINEX navigation file(s)
147  */
148  inline std::vector<std::string> get_navfilename() const
149  {
150  return output_navfilename;
151  }
152 
153  /*!
154  * \brief Returns name of RINEX observation file
155  */
156  inline std::string get_obsfilename() const
157  {
158  return obsfilename;
159  }
160 
161 
162 private:
163  // Not the best, but reorder params to select the correct constructor
164  explicit Rinex_Printer(uint32_t signal_enabled_flags,
165  const std::string& base_name,
166  const std::string& base_rinex_path,
167  int version,
168  bool pre_2009_file);
169 
170  /*
171  * Generates the GPS Observation data header
172  */
173  void rinex_obs_header(std::fstream& out,
174  const std::string& time_constellation,
175  const boost::posix_time::ptime& system_time,
176  double seconds);
177 
178  /*
179  * Generates the Navigation Data header
180  */
181  void rinex_nav_header(std::fstream& out,
182  const std::vector<std::string>& iono_lines,
183  const std::vector<std::string>& time_corr_lines,
184  const std::string& leap_second_line) const;
185 
186  /*
187  * Computes the BDS Time and returns a boost::posix_time::ptime object
188  * \details Function used to convert the observation time into BDT time which is used
189  * as the default time for RINEX files
190  * \param eph BeiDou DNAV Ephemeris object
191  * \param obs_time Observation time in BDT seconds of week
192  */
193  boost::posix_time::ptime compute_BDS_time(const Beidou_Dnav_Ephemeris& eph, double obs_time) const;
194 
195  /*
196  * Computes the UTC time and returns a boost::posix_time::ptime object
197  */
198  boost::posix_time::ptime compute_UTC_time(const Gps_Navigation_Message& nav_msg) const;
199 
200  /*
201  * Computes the GPS time and returns a boost::posix_time::ptime object
202  */
203  boost::posix_time::ptime compute_GPS_time(const Gps_Ephemeris& eph, double obs_time) const;
204 
205  /*
206  * Computes the GPS time and returns a boost::posix_time::ptime object
207  */
208  boost::posix_time::ptime compute_GPS_time(const Gps_CNAV_Ephemeris& eph, double obs_time) const;
209 
210  /*
211  * Computes the Galileo time and returns a boost::posix_time::ptime object
212  */
213  boost::posix_time::ptime compute_Galileo_time(const Galileo_Ephemeris& eph, double obs_time) const;
214 
215  /*
216  * Computes the UTC Time and returns a boost::posix_time::ptime object
217  * \details Function used as a method to convert the observation time into UTC time which is used
218  * as the default time for RINEX files
219  * \param eph GLONASS GNAV Ephemeris object
220  * \param obs_time Observation time in GPS seconds of week
221  */
222  boost::posix_time::ptime compute_UTC_time(const Glonass_Gnav_Ephemeris& eph, double obs_time) const;
223 
224  /*
225  * Represents GPS time in the date time format. Leap years are considered, but leap seconds are not.
226  */
227  void to_date_time(int gps_week,
228  int gps_tow,
229  int& year,
230  int& month,
231  int& day,
232  int& hour,
233  int& minute,
234  int& second) const;
235 
236  void update_obs_header(std::fstream& out, const std::string& leap_second_line) const;
237 
238  const std::map<std::string, std::string> observationType; // PSEUDORANGE, CARRIER_PHASE, DOPPLER, SIGNAL_STRENGTH
239  const std::map<std::string, std::string> observationCode; // GNSS observation descriptors
240 
241  const Signal_Enabled_Flags d_flags;
242 
243  const int d_version; // RINEX version (2 for 2.10/2.11 and 3 for 3.01)
244  const std::string d_stringVersion; // RINEX version (2.10/2.11 or 3.01/3.02)
245 
246  double d_fake_cnav_iode;
247  bool d_rinex_header_updated;
248  bool d_rinex_header_gps_updated;
249  bool d_rinex_header_galileo_updated;
250  bool d_rinex_header_glonass_updated;
251  bool d_rinex_header_beidou_updated;
252  bool d_rinex_header_written;
253  const bool d_pre_2009_file;
254 
255  const std::string navfilename; // Name of RINEX navigation file
256  const std::string obsfilename; // Name of RINEX observation file
257  const std::string navGlofilename; // Name of RINEX navigation file for Glonass
258  std::vector<std::string> output_navfilename; // Name of output RINEX navigation file(s)
259 
260  std::fstream obsFile; // Output file stream for RINEX observation file
261  std::fstream navFile; // Output file stream for RINEX navigation data file
262  std::fstream navGloFile; // Output file stream for RINEX GLONASS navigation data file
263 };
264 
265 
266 /** \} */
267 /** \} */
268 #endif // GNSS_SDR_RINEX_PRINTER_H
This class is a storage for the GPS IONOSPHERIC data as described in IS-GPS-200M. ...
Definition: gps_iono.h:35
std::string get_obsfilename() const
Returns name of RINEX observation file.
This is a storage class for the GPS CNAV ephemeris data as described in IS-GPS-200M.
This class is a storage for the BeiDou DNAV UTC Model.
This class is a storage and orbital model functions for the GPS SV ephemeris data as described in IS-...
Definition: gps_ephemeris.h:40
bool is_rinex_header_written() const
Returns true is the RINEX file headers are already written.
This class is a storage for the BEIDOU IONOSPHERIC data as described in ICD v2.1. ...
Class that handles the generation of Receiver INdependent EXchange format (RINEX) files...
Definition: rinex_printer.h:82
void log_rinex_nav_gps_cnav(const std::map< int32_t, Gps_CNAV_Ephemeris > &new_cnav_eph)
Print RINEX annotation for GPS CNAV message.
Class to check the enabled signals.
void log_rinex_nav_gal_nav(const std::map< int32_t, Galileo_Ephemeris > &new_gal_eph)
Print RINEX annotation for Galileo NAV message.
This class is a storage and orbital model functions for the GLONASS SV ephemeris data as described in...
This class implements a PVT solution based on RTKLIB.
Definition: rtklib_solver.h:82
~Rinex_Printer()
Destructor. Removes created files if empty.
This is a storage class for the Beidou SV ephemeris data as described in BeiDou Navigation Satellite ...
This is the class that contains the information that is shared by the processing blocks.
Definition: gnss_synchro.h:38
void log_rinex_nav_glo_gnav(const std::map< int32_t, Glonass_Gnav_Ephemeris > &new_glo_eph)
Print RINEX annotation for Glonass GNAV message.
This class is a storage for the GPS UTC MODEL data as described in in IS-GPS-200M.
This class decodes a GPS NAV Data message as described in IS-GPS-200M.
void log_rinex_nav_gps_nav(const std::map< int32_t, Gps_Ephemeris > &new_eph)
Print RINEX annotation for GPS NAV message.
This class is a storage for the GALILEO IONOSPHERIC data as described in Galileo ICD paragraph 5...
Definition: galileo_iono.h:37
void print_rinex_annotation(const Rtklib_Solver *pvt_solver, const std::map< int, Gnss_Synchro > &gnss_observables_map, double rx_time, bool flag_write_RINEX_obs_output)
Print RINEX annotation. If it is the first annotation, it also prints the RINEX headers for navigatio...
This class is a storage and orbital model functions for the Galileo SV ephemeris data as described in...
This class is a storage for the GLONASS GNAV UTC MODEL data as described in GLONASS ICD (Edition 5...
This class is a storage for the GPS UTC MODEL data as described in IS-GPS-200M.
Definition: gps_utc_model.h:35
This class is a storage for the GLONASS SV ALMANAC data as described GLONASS ICD (Edition 5...
This class is a storage for the GALILEO UTC MODEL data as described in Galileo ICD https://www...
void log_rinex_nav_bds_dnav(const std::map< int32_t, Beidou_Dnav_Ephemeris > &new_bds_eph)
Print RINEX annotation for BeiDou DNAV message.
std::vector< std::string > get_navfilename() const
Returns name of RINEX navigation file(s)
This class is a storage for the GPS IONOSPHERIC data as described in IS-GPS-200M. ...
Definition: gps_cnav_iono.h:34
Rinex_Printer(uint32_t signal_enabled_flags, int version=3, const std::string &base_path=".", const std::string &base_name="-", bool pre_2009_file=false)
Constructor. Creates GNSS Navigation and Observables RINEX files.