[hamradio-commits] [gnss-sdr] 124/303: Add ability to log GPS dual freq (L1/L2C) observations

Carles Fernandez carles_fernandez-guest at moszumanska.debian.org
Mon Feb 13 22:35:54 UTC 2017


This is an automated email from the git hooks/post-receive script.

carles_fernandez-guest pushed a commit to branch master
in repository gnss-sdr.

commit 2f145e8f19ac84f2a17eb0b53ca7b4f38ad33b77
Author: Carles Fernandez <carles.fernandez at gmail.com>
Date:   Sat Oct 29 17:15:04 2016 +0200

    Add ability to log GPS dual freq (L1/L2C) observations
---
 src/algorithms/PVT/libs/rinex_printer.cc | 2564 ++++++++++++++++++------------
 src/algorithms/PVT/libs/rinex_printer.h  |   14 +-
 2 files changed, 1540 insertions(+), 1038 deletions(-)

diff --git a/src/algorithms/PVT/libs/rinex_printer.cc b/src/algorithms/PVT/libs/rinex_printer.cc
index 6b1bad6..2438705 100644
--- a/src/algorithms/PVT/libs/rinex_printer.cc
+++ b/src/algorithms/PVT/libs/rinex_printer.cc
@@ -220,8 +220,6 @@ Rinex_Printer::~Rinex_Printer()
 }
 
 
-
-
 void Rinex_Printer::lengthCheck(const std::string& line)
 {
     if (line.length() != 80)
@@ -234,7 +232,6 @@ void Rinex_Printer::lengthCheck(const std::string& line)
 }
 
 
-
 std::string Rinex_Printer::createFilename(std::string type)
 {
     const std::string stationName = "GSDR"; // 4-character station name designator
@@ -505,360 +502,149 @@ void Rinex_Printer::rinex_nav_header(std::fstream& out, const Galileo_Iono& iono
 }
 
 
-void Rinex_Printer::update_nav_header(std::fstream& out, const Galileo_Iono& galileo_iono, const Galileo_Utc_Model& utc_model, const Galileo_Almanac& galileo_almanac)
+void Rinex_Printer::rinex_nav_header(std::fstream& out, const Gps_CNAV_Iono & iono, const Gps_CNAV_Utc_Model & utc_model)
 {
-    std::vector<std::string> data;
-    std::string line_aux;
+    std::string line;
 
-    long pos = out.tellp();
-    out.seekp(0);
-    data.clear();
+    // -------- Line 1
+    line = std::string(5, ' ');
+    line += stringVersion;
+    line += std::string(11, ' ');
+    line += std::string("N: GNSS NAV DATA");
+    line += std::string(4, ' ');
+    line += std::string("G: GPS");
+    line += std::string(14, ' ');
+    line += std::string("RINEX VERSION / TYPE");
+    Rinex_Printer::lengthCheck(line);
+    out << line << std::endl;
 
-    bool no_more_finds = false;
-    std::string line_str;
+    // -------- Line 2
+    line.clear();
+    line += Rinex_Printer::getLocalTime();
+    line += std::string("PGM / RUN BY / DATE");
+    line += std::string(1, ' ');
+    Rinex_Printer::lengthCheck(line);
+    out << line << std::endl;
 
-    while(!out.eof())
-        {
-            std::getline(out, line_str);
+    // -------- Line 3
+    line.clear();
+    line += Rinex_Printer::leftJustify("GPS NAVIGATION MESSAGE FILE GENERATED BY GNSS-SDR", 60);
+    line += Rinex_Printer::leftJustify("COMMENT", 20);
+    Rinex_Printer::lengthCheck(line);
+    out << line << std::endl;
 
-            if(!no_more_finds)
-                {
-                    line_aux.clear();
+    // -------- Line COMMENT
+    line.clear();
+    std::string gnss_sdr_version(GNSS_SDR_VERSION);
+    line += "GNSS-SDR VERSION ";
+    line += Rinex_Printer::leftJustify(gnss_sdr_version, 43);
+    line += Rinex_Printer::leftJustify("COMMENT", 20);
+    Rinex_Printer::lengthCheck(line);
+    out << line << std::endl;
 
-                    if ((line_str.find("GAL", 0) != std::string::npos) && (line_str.find("IONOSPHERIC CORR", 59) != std::string::npos))
-                        {
-                            line_aux += std::string("GAL ");
-                            line_aux += std::string(1, ' ');
-                            line_aux += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(galileo_iono.ai0_5, 10, 2), 12);
-                            line_aux += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(galileo_iono.ai1_5, 10, 2), 12);
-                            line_aux += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(galileo_iono.ai2_5, 10, 2), 12);
-                            double zero = 0.0;
-                            line_aux += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(zero, 10, 2), 12);
-                            line_aux += std::string(7, ' ');
-                            line_aux += Rinex_Printer::leftJustify("IONOSPHERIC CORR", 20);
-                            data.push_back(line_aux);
-                        }
-                    else if ((line_str.find("GAUT", 0) != std::string::npos) && (line_str.find("TIME SYSTEM CORR", 59) != std::string::npos))
-                        {
-                            line_aux += std::string("GAUT");
-                            line_aux += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(utc_model.A0_6, 16, 2), 18);
-                            line_aux += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(utc_model.A1_6, 15, 2), 16);
-                            line_aux += Rinex_Printer::rightJustify(boost::lexical_cast<std::string>(utc_model.t0t_6), 7);
-                            line_aux += Rinex_Printer::rightJustify(boost::lexical_cast<std::string>(utc_model.WNot_6), 5);
-                            line_aux += std::string(10, ' ');
-                            line_aux += Rinex_Printer::leftJustify("TIME SYSTEM CORR", 20);
-                            data.push_back(line_aux);
-                        }
-                    else if ((line_str.find("GPGA", 0) != std::string::npos) && (line_str.find("TIME SYSTEM CORR", 59) != std::string::npos))
-                        {
-                            line_aux += std::string("GPGA");
-                            line_aux += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(galileo_almanac.A_0G_10, 16, 2), 18);
-                            line_aux += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(galileo_almanac.A_1G_10, 15, 2), 16);
-                            line_aux += Rinex_Printer::rightJustify(boost::lexical_cast<std::string>(galileo_almanac.t_0G_10), 7);
-                            line_aux += Rinex_Printer::rightJustify(boost::lexical_cast<std::string>(galileo_almanac.WN_0G_10), 5);
-                            line_aux += std::string(10, ' ');
-                            line_aux += Rinex_Printer::leftJustify("TIME SYSTEM CORR", 20);
-                            data.push_back(line_aux);
-                        }
-                    else if (line_str.find("LEAP SECONDS", 59) != std::string::npos)
-                        {
-                            line_aux += Rinex_Printer::rightJustify(boost::lexical_cast<std::string>(utc_model.Delta_tLS_6), 6);
-                            line_aux += Rinex_Printer::rightJustify(boost::lexical_cast<std::string>(utc_model.Delta_tLSF_6), 6);
-                            line_aux += Rinex_Printer::rightJustify(boost::lexical_cast<std::string>(utc_model.WN_LSF_6), 6);
-                            line_aux += Rinex_Printer::rightJustify(boost::lexical_cast<std::string>(utc_model.DN_6), 6);
-                            line_aux += std::string(36, ' ');
-                            line_aux += Rinex_Printer::leftJustify("LEAP SECONDS", 20);
-                            data.push_back(line_aux);
-                        }
-                    else if (line_str.find("END OF HEADER", 59) != std::string::npos)
-                        {
-                            data.push_back(line_str);
-                            no_more_finds = true;
-                        }
-                    else
-                        {
-                            data.push_back(line_str);
-                        }
+    // -------- Line COMMENT
+    line.clear();
+    line += Rinex_Printer::leftJustify("See http://gnss-sdr.org", 60);
+    line += Rinex_Printer::leftJustify("COMMENT", 20);
+    Rinex_Printer::lengthCheck(line);
+    out << line << std::endl;
 
-                }
-            else
-                {
-                    data.push_back(line_str);
-                }
-        }
+    // -------- Line ionospheric info 1
+    line.clear();
+    line += std::string("GPSA");
+    line += std::string(1, ' ');
+    line += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(iono.d_alpha0, 10, 2), 12);
+    line += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(iono.d_alpha1, 10, 2), 12);
+    line += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(iono.d_alpha2, 10, 2), 12);
+    line += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(iono.d_alpha3, 10, 2), 12);
+    line += std::string(7, ' ');
+    line += Rinex_Printer::leftJustify("IONOSPHERIC CORR", 20);
+    Rinex_Printer::lengthCheck(line);
+    out << line << std::endl;
 
-    out.close();
-    out.open(navGalfilename, std::ios::out | std::ios::trunc);
-    out.seekp(0);
-    for (int i = 0; i < (int) data.size() - 1; i++)
-        {
-            out << data[i] << std::endl;
-        }
-    out.close();
-    out.open(navGalfilename, std::ios::out | std::ios::app);
-    out.seekp(pos);
-    std::cout << "The RINEX Navigation file header has been updated with UTC and IONO info." << std::endl;
+    // -------- Line ionospheric info 2
+    line.clear();
+    line += std::string("GPSB");
+    line += std::string(1, ' ');
+    line += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(iono.d_beta0, 10, 2), 12);
+    line += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(iono.d_beta1, 10, 2), 12);
+    line += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(iono.d_beta2, 10, 2), 12);
+    line += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(iono.d_beta3, 10, 2), 12);
+    line += std::string(7, ' ');
+    line += Rinex_Printer::leftJustify("IONOSPHERIC CORR", 20);
+    Rinex_Printer::lengthCheck(line);
+    out << line << std::endl;
+
+    // -------- Line 5 system time correction
+    line.clear();
+    line += std::string("GPUT");
+    line += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(utc_model.d_A0, 16, 2), 18);
+    line += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(utc_model.d_A1, 15, 2), 16);
+    line += Rinex_Printer::rightJustify(boost::lexical_cast<std::string>(utc_model.d_t_OT), 7);
+    line += Rinex_Printer::rightJustify(boost::lexical_cast<std::string>(utc_model.i_WN_T + 1024), 5);  // valid until 2019
+    /*  if ( SBAS )
+    {
+      line += string(1, ' ');
+      line += leftJustify(asString(d_t_OT_SBAS),5);
+      line += string(1, ' ');
+      line += leftJustify(asString(d_WN_T_SBAS),2);
+      line += string(1, ' ');
+           }
+    else
+     */
+    line += std::string(10, ' ');
+    line += Rinex_Printer::leftJustify("TIME SYSTEM CORR", 20);
+    Rinex_Printer::lengthCheck(line);
+    out << line << std::endl;
+
+    // -------- Line 6 leap seconds
+    // For leap second information, see http://www.endruntechnologies.com/leap.htm
+    line.clear();
+    line += Rinex_Printer::rightJustify(boost::lexical_cast<std::string>(utc_model.d_DeltaT_LS), 6);
+    line += Rinex_Printer::rightJustify(boost::lexical_cast<std::string>(utc_model.d_DeltaT_LSF), 6);
+    line += Rinex_Printer::rightJustify(boost::lexical_cast<std::string>(utc_model.i_WN_LSF), 6);
+    line += Rinex_Printer::rightJustify(boost::lexical_cast<std::string>(utc_model.i_DN), 6);
+    line += std::string(36, ' ');
+    line += Rinex_Printer::leftJustify("LEAP SECONDS", 20);
+    Rinex_Printer::lengthCheck(line);
+    out << line << std::endl;
+
+
+    // -------- End of Header
+    line.clear();
+    line += std::string(60, ' ');
+    line += Rinex_Printer::leftJustify("END OF HEADER", 20);
+    Rinex_Printer::lengthCheck(line);
+    out << line << std::endl;
 }
 
 
-void Rinex_Printer::update_nav_header(std::fstream& out, const Gps_Utc_Model& utc_model, const Gps_Iono& iono)
+void Rinex_Printer::rinex_nav_header(std::fstream& out, const Gps_Iono& iono, const Gps_Utc_Model& utc_model)
 {
-    std::vector<std::string> data;
-    std::string line_aux;
+    std::string line;
 
-    long pos = out.tellp();
-    out.seekp(0);
-    data.clear();
+    // -------- Line 1
+    line = std::string(5, ' ');
+    line += stringVersion;
+    line += std::string(11, ' ');
 
-    bool no_more_finds = false;
-    std::string line_str;
+    if (version == 2)
+        {
+            line += std::string("N: GPS NAV DATA");
+            line += std::string(25, ' ');
+        }
 
-    while(!out.eof())
+    if (version == 3 )
         {
-            std::getline(out, line_str);
+            line += std::string("N: GNSS NAV DATA");
+            line += std::string(4, ' ');
+            //! \todo Add here other systems...
+            line += std::string("G: GPS");
+            line += std::string(14, ' ');
+            // ...
 
-            if(!no_more_finds)
-                {
-                    line_aux.clear();
+        }
 
-                    if (version == 2)
-                        {
-                            if (line_str.find("ION ALPHA", 59) != std::string::npos)
-                                {
-                                    line_aux += std::string(2, ' ');
-                                    line_aux += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(iono.d_alpha0, 10, 2), 12);
-                                    line_aux += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(iono.d_alpha1, 10, 2), 12);
-                                    line_aux += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(iono.d_alpha2, 10, 2), 12);
-                                    line_aux += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(iono.d_alpha3, 10, 2), 12);
-                                    line_aux += std::string(10, ' ');
-                                    line_aux += Rinex_Printer::leftJustify("ION ALPHA", 20);
-                                    data.push_back(line_aux);
-                                }
-                            else if (line_str.find("ION BETA", 59) != std::string::npos)
-                                {
-                                    line_aux += std::string(2, ' ');
-                                    line_aux += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(iono.d_beta0, 10, 2), 12);
-                                    line_aux += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(iono.d_beta1, 10, 2), 12);
-                                    line_aux += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(iono.d_beta2, 10, 2), 12);
-                                    line_aux += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(iono.d_beta3, 10, 2), 12);
-                                    line_aux += std::string(10, ' ');
-                                    line_aux += Rinex_Printer::leftJustify("ION BETA", 20);
-                                    data.push_back(line_aux);
-                                }
-                            else if (line_str.find("DELTA-UTC", 59) != std::string::npos)
-                                {
-                                    line_aux += std::string(3, ' ');
-                                    line_aux += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(utc_model.d_A0, 18, 2), 19);
-                                    line_aux += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(utc_model.d_A1, 18, 2), 19);
-                                    line_aux += Rinex_Printer::rightJustify(boost::lexical_cast<std::string>(utc_model.d_t_OT), 9);
-                                    line_aux += Rinex_Printer::rightJustify(boost::lexical_cast<std::string>(utc_model.i_WN_T + 1024), 9); // valid until 2019
-                                    line_aux += std::string(1, ' ');
-                                    line_aux += Rinex_Printer::leftJustify("DELTA-UTC: A0,A1,T,W", 20);
-                                    data.push_back(line_aux);
-                                }
-                            else if (line_str.find("LEAP SECONDS", 59) != std::string::npos)
-                                {
-                                    line_aux += Rinex_Printer::rightJustify(boost::lexical_cast<std::string>(utc_model.d_DeltaT_LS), 6);
-                                    line_aux += std::string(54, ' ');
-                                    line_aux += Rinex_Printer::leftJustify("LEAP SECONDS", 20);
-                                    data.push_back(line_aux);
-                                }
-                            else if (line_str.find("END OF HEADER", 59) != std::string::npos)
-                                {
-                                    data.push_back(line_str);
-                                    no_more_finds = true;
-                                }
-                            else
-                                {
-                                    data.push_back(line_str);
-                                }
-                        }
-
-                    if (version == 3)
-                        {
-                            if (line_str.find("GPSA", 0) != std::string::npos)
-                                {
-                                    line_aux += std::string("GPSA");
-                                    line_aux += std::string(1, ' ');
-                                    line_aux += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(iono.d_alpha0, 10, 2), 12);
-                                    line_aux += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(iono.d_alpha1, 10, 2), 12);
-                                    line_aux += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(iono.d_alpha2, 10, 2), 12);
-                                    line_aux += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(iono.d_alpha3, 10, 2), 12);
-                                    line_aux += std::string(7, ' ');
-                                    line_aux += Rinex_Printer::leftJustify("IONOSPHERIC CORR", 20);
-                                    data.push_back(line_aux);
-                                }
-                            else if (line_str.find("GPSB", 0) != std::string::npos)
-                                {
-                                    line_aux += std::string("GPSB");
-                                    line_aux += std::string(1, ' ');
-                                    line_aux += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(iono.d_beta0, 10, 2), 12);
-                                    line_aux += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(iono.d_beta1, 10, 2), 12);
-                                    line_aux += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(iono.d_beta2, 10, 2), 12);
-                                    line_aux += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(iono.d_beta3, 10, 2), 12);
-                                    line_aux += std::string(7, ' ');
-                                    line_aux += Rinex_Printer::leftJustify("IONOSPHERIC CORR", 20);
-                                    data.push_back(line_aux);
-                                }
-                            else if (line_str.find("GPUT", 0) != std::string::npos)
-                                {
-                                    line_aux += std::string("GPUT");
-                                    line_aux += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(utc_model.d_A0, 16, 2), 18);
-                                    line_aux += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(utc_model.d_A1, 15, 2), 16);
-                                    line_aux += Rinex_Printer::rightJustify(boost::lexical_cast<std::string>(utc_model.d_t_OT), 7);
-                                    line_aux += Rinex_Printer::rightJustify(boost::lexical_cast<std::string>(utc_model.i_WN_T + 1024), 5);  // valid until 2019
-                                    line_aux += std::string(10, ' ');
-                                    line_aux += Rinex_Printer::leftJustify("TIME SYSTEM CORR", 20);
-                                    data.push_back(line_aux);
-                                }
-                            else if (line_str.find("LEAP SECONDS", 59) != std::string::npos)
-                                {
-                                    line_aux += Rinex_Printer::rightJustify(boost::lexical_cast<std::string>(utc_model.d_DeltaT_LS), 6);
-                                    line_aux += Rinex_Printer::rightJustify(boost::lexical_cast<std::string>(utc_model.d_DeltaT_LSF), 6);
-                                    line_aux += Rinex_Printer::rightJustify(boost::lexical_cast<std::string>(utc_model.i_WN_LSF), 6);
-                                    line_aux += Rinex_Printer::rightJustify(boost::lexical_cast<std::string>(utc_model.i_DN), 6);
-                                    line_aux += std::string(36, ' ');
-                                    line_aux += Rinex_Printer::leftJustify("LEAP SECONDS", 20);
-                                    data.push_back(line_aux);
-                                }
-                            else if (line_str.find("END OF HEADER", 59) != std::string::npos)
-                                {
-                                    data.push_back(line_str);
-                                    no_more_finds = true;
-                                }
-                            else
-                                {
-                                    data.push_back(line_str);
-                                }
-                        }
-                }
-            else
-                {
-                    data.push_back(line_str);
-                }
-        }
-
-    out.close();
-    out.open(navfilename, std::ios::out | std::ios::trunc);
-    out.seekp(0);
-    for (int i = 0; i < (int) data.size() - 1; i++)
-        {
-            out << data[i] << std::endl;
-        }
-    out.close();
-    out.open(navfilename, std::ios::out | std::ios::app);
-    out.seekp(pos);
-    std::cout << "The RINEX Navigation file header has been updated with UTC and IONO info." << std::endl;
-}
-
-
-void Rinex_Printer::update_nav_header(std::fstream & out, const Gps_CNAV_Utc_Model & utc_model, const Gps_CNAV_Iono & iono )
-{
-    std::vector<std::string> data;
-    std::string line_aux;
-
-    long pos = out.tellp();
-    out.seekp(0);
-    data.clear();
-
-    bool no_more_finds = false;
-    std::string line_str;
-
-    while(!out.eof())
-        {
-            std::getline(out, line_str);
-
-            if(!no_more_finds)
-                {
-                    line_aux.clear();
-
-                    if (line_str.find("GPSA", 0) != std::string::npos)
-                        {
-                            line_aux += std::string("GPSA");
-                            line_aux += std::string(1, ' ');
-                            line_aux += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(iono.d_alpha0, 10, 2), 12);
-                            line_aux += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(iono.d_alpha1, 10, 2), 12);
-                            line_aux += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(iono.d_alpha2, 10, 2), 12);
-                            line_aux += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(iono.d_alpha3, 10, 2), 12);
-                            line_aux += std::string(7, ' ');
-                            line_aux += Rinex_Printer::leftJustify("IONOSPHERIC CORR", 20);
-                            data.push_back(line_aux);
-                        }
-                    else if (line_str.find("GPSB", 0) != std::string::npos)
-                        {
-                            line_aux += std::string("GPSB");
-                            line_aux += std::string(1, ' ');
-                            line_aux += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(iono.d_beta0, 10, 2), 12);
-                            line_aux += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(iono.d_beta1, 10, 2), 12);
-                            line_aux += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(iono.d_beta2, 10, 2), 12);
-                            line_aux += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(iono.d_beta3, 10, 2), 12);
-                            line_aux += std::string(7, ' ');
-                            line_aux += Rinex_Printer::leftJustify("IONOSPHERIC CORR", 20);
-                            data.push_back(line_aux);
-                        }
-                    else if (line_str.find("GPUT", 0) != std::string::npos)
-                        {
-                            line_aux += std::string("GPUT");
-                            line_aux += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(utc_model.d_A0, 16, 2), 18);
-                            line_aux += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(utc_model.d_A1, 15, 2), 16);
-                            line_aux += Rinex_Printer::rightJustify(boost::lexical_cast<std::string>(utc_model.d_t_OT), 7);
-                            line_aux += Rinex_Printer::rightJustify(boost::lexical_cast<std::string>(utc_model.i_WN_T + 1024), 5);  // valid until 2019
-                            line_aux += std::string(10, ' ');
-                            line_aux += Rinex_Printer::leftJustify("TIME SYSTEM CORR", 20);
-                            data.push_back(line_aux);
-                        }
-                    else if (line_str.find("LEAP SECONDS", 59) != std::string::npos)
-                        {
-                            line_aux += Rinex_Printer::rightJustify(boost::lexical_cast<std::string>(utc_model.d_DeltaT_LS), 6);
-                            line_aux += Rinex_Printer::rightJustify(boost::lexical_cast<std::string>(utc_model.d_DeltaT_LSF), 6);
-                            line_aux += Rinex_Printer::rightJustify(boost::lexical_cast<std::string>(utc_model.i_WN_LSF), 6);
-                            line_aux += Rinex_Printer::rightJustify(boost::lexical_cast<std::string>(utc_model.i_DN), 6);
-                            line_aux += std::string(36, ' ');
-                            line_aux += Rinex_Printer::leftJustify("LEAP SECONDS", 20);
-                            data.push_back(line_aux);
-                        }
-                    else if (line_str.find("END OF HEADER", 59) != std::string::npos)
-                        {
-                            data.push_back(line_str);
-                            no_more_finds = true;
-                        }
-                    else
-                        {
-                            data.push_back(line_str);
-                        }
-                }
-            else
-                {
-                    data.push_back(line_str);
-                }
-        }
-
-    out.close();
-    out.open(navfilename, std::ios::out | std::ios::trunc);
-    out.seekp(0);
-    for (int i = 0; i < (int) data.size() - 1; i++)
-        {
-            out << data[i] << std::endl;
-        }
-    out.close();
-    out.open(navfilename, std::ios::out | std::ios::app);
-    out.seekp(pos);
-    std::cout << "The RINEX Navigation file header has been updated with UTC and IONO info." << std::endl;
-}
-
-
-void Rinex_Printer::rinex_nav_header(std::fstream& out, const Gps_CNAV_Iono & iono, const Gps_CNAV_Utc_Model & utc_model)
-{
-    std::string line;
-
-    // -------- Line 1
-    line = std::string(5, ' ');
-    line += stringVersion;
-    line += std::string(11, ' ');
-    line += std::string("N: GNSS NAV DATA");
-    line += std::string(4, ' ');
-    line += std::string("G: GPS");
-    line += std::string(14, ' ');
     line += std::string("RINEX VERSION / TYPE");
     Rinex_Printer::lengthCheck(line);
     out << line << std::endl;
@@ -896,158 +682,27 @@ void Rinex_Printer::rinex_nav_header(std::fstream& out, const Gps_CNAV_Iono & io
 
     // -------- Line ionospheric info 1
     line.clear();
-    line += std::string("GPSA");
-    line += std::string(1, ' ');
-    line += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(iono.d_alpha0, 10, 2), 12);
-    line += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(iono.d_alpha1, 10, 2), 12);
-    line += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(iono.d_alpha2, 10, 2), 12);
-    line += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(iono.d_alpha3, 10, 2), 12);
-    line += std::string(7, ' ');
-    line += Rinex_Printer::leftJustify("IONOSPHERIC CORR", 20);
-    Rinex_Printer::lengthCheck(line);
-    out << line << std::endl;
-
-    // -------- Line ionospheric info 2
-    line.clear();
-    line += std::string("GPSB");
-    line += std::string(1, ' ');
-    line += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(iono.d_beta0, 10, 2), 12);
-    line += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(iono.d_beta1, 10, 2), 12);
-    line += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(iono.d_beta2, 10, 2), 12);
-    line += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(iono.d_beta3, 10, 2), 12);
-    line += std::string(7, ' ');
-    line += Rinex_Printer::leftJustify("IONOSPHERIC CORR", 20);
-    Rinex_Printer::lengthCheck(line);
-    out << line << std::endl;
-
-    // -------- Line 5 system time correction
-    line.clear();
-    line += std::string("GPUT");
-    line += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(utc_model.d_A0, 16, 2), 18);
-    line += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(utc_model.d_A1, 15, 2), 16);
-    line += Rinex_Printer::rightJustify(boost::lexical_cast<std::string>(utc_model.d_t_OT), 7);
-    line += Rinex_Printer::rightJustify(boost::lexical_cast<std::string>(utc_model.i_WN_T + 1024), 5);  // valid until 2019
-    /*  if ( SBAS )
-    {
-      line += string(1, ' ');
-      line += leftJustify(asString(d_t_OT_SBAS),5);
-      line += string(1, ' ');
-      line += leftJustify(asString(d_WN_T_SBAS),2);
-      line += string(1, ' ');
-           }
-    else
-     */
-    line += std::string(10, ' ');
-    line += Rinex_Printer::leftJustify("TIME SYSTEM CORR", 20);
-    Rinex_Printer::lengthCheck(line);
-    out << line << std::endl;
-
-    // -------- Line 6 leap seconds
-    // For leap second information, see http://www.endruntechnologies.com/leap.htm
-    line.clear();
-    line += Rinex_Printer::rightJustify(boost::lexical_cast<std::string>(utc_model.d_DeltaT_LS), 6);
-    line += Rinex_Printer::rightJustify(boost::lexical_cast<std::string>(utc_model.d_DeltaT_LSF), 6);
-    line += Rinex_Printer::rightJustify(boost::lexical_cast<std::string>(utc_model.i_WN_LSF), 6);
-    line += Rinex_Printer::rightJustify(boost::lexical_cast<std::string>(utc_model.i_DN), 6);
-    line += std::string(36, ' ');
-    line += Rinex_Printer::leftJustify("LEAP SECONDS", 20);
-    Rinex_Printer::lengthCheck(line);
-    out << line << std::endl;
-
-
-    // -------- End of Header
-    line.clear();
-    line += std::string(60, ' ');
-    line += Rinex_Printer::leftJustify("END OF HEADER", 20);
-    Rinex_Printer::lengthCheck(line);
-    out << line << std::endl;
-}
-
-
-void Rinex_Printer::rinex_nav_header(std::fstream& out, const Gps_Iono& iono, const Gps_Utc_Model& utc_model)
-{
-    std::string line;
-
-    // -------- Line 1
-    line = std::string(5, ' ');
-    line += stringVersion;
-    line += std::string(11, ' ');
-
-    if (version == 2)
-        {
-            line += std::string("N: GPS NAV DATA");
-            line += std::string(25, ' ');
-        }
-
-    if (version == 3 )
-        {
-            line += std::string("N: GNSS NAV DATA");
-            line += std::string(4, ' ');
-            //! \todo Add here other systems...
-            line += std::string("G: GPS");
-            line += std::string(14, ' ');
-            // ...
-
-        }
-
-    line += std::string("RINEX VERSION / TYPE");
-    Rinex_Printer::lengthCheck(line);
-    out << line << std::endl;
-
-    // -------- Line 2
-    line.clear();
-    line += Rinex_Printer::getLocalTime();
-    line += std::string("PGM / RUN BY / DATE");
-    line += std::string(1, ' ');
-    Rinex_Printer::lengthCheck(line);
-    out << line << std::endl;
-
-    // -------- Line 3
-    line.clear();
-    line += Rinex_Printer::leftJustify("GPS NAVIGATION MESSAGE FILE GENERATED BY GNSS-SDR", 60);
-    line += Rinex_Printer::leftJustify("COMMENT", 20);
-    Rinex_Printer::lengthCheck(line);
-    out << line << std::endl;
-
-    // -------- Line COMMENT
-    line.clear();
-    std::string gnss_sdr_version(GNSS_SDR_VERSION);
-    line += "GNSS-SDR VERSION ";
-    line += Rinex_Printer::leftJustify(gnss_sdr_version, 43);
-    line += Rinex_Printer::leftJustify("COMMENT", 20);
-    Rinex_Printer::lengthCheck(line);
-    out << line << std::endl;
-
-    // -------- Line COMMENT
-    line.clear();
-    line += Rinex_Printer::leftJustify("See http://gnss-sdr.org", 60);
-    line += Rinex_Printer::leftJustify("COMMENT", 20);
-    Rinex_Printer::lengthCheck(line);
-    out << line << std::endl;
-
-    // -------- Line ionospheric info 1
-    line.clear();
-    if (version == 2)
-        {
-            line += std::string(2, ' ');
-            line += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(iono.d_alpha0, 10, 2), 12);
-            line += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(iono.d_alpha1, 10, 2), 12);
-            line += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(iono.d_alpha2, 10, 2), 12);
-            line += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(iono.d_alpha3, 10, 2), 12);
-            line += std::string(10, ' ');
-            line += Rinex_Printer::leftJustify("ION ALPHA", 20);
-        }
-    if (version == 3)
-        {
-            line += std::string("GPSA");
-            line += std::string(1, ' ');
-            line += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(iono.d_alpha0, 10, 2), 12);
-            line += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(iono.d_alpha1, 10, 2), 12);
-            line += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(iono.d_alpha2, 10, 2), 12);
-            line += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(iono.d_alpha3, 10, 2), 12);
-            line += std::string(7, ' ');
-            line += Rinex_Printer::leftJustify("IONOSPHERIC CORR", 20);
-        }
+    if (version == 2)
+        {
+            line += std::string(2, ' ');
+            line += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(iono.d_alpha0, 10, 2), 12);
+            line += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(iono.d_alpha1, 10, 2), 12);
+            line += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(iono.d_alpha2, 10, 2), 12);
+            line += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(iono.d_alpha3, 10, 2), 12);
+            line += std::string(10, ' ');
+            line += Rinex_Printer::leftJustify("ION ALPHA", 20);
+        }
+    if (version == 3)
+        {
+            line += std::string("GPSA");
+            line += std::string(1, ' ');
+            line += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(iono.d_alpha0, 10, 2), 12);
+            line += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(iono.d_alpha1, 10, 2), 12);
+            line += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(iono.d_alpha2, 10, 2), 12);
+            line += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(iono.d_alpha3, 10, 2), 12);
+            line += std::string(7, ' ');
+            line += Rinex_Printer::leftJustify("IONOSPHERIC CORR", 20);
+        }
     Rinex_Printer::lengthCheck(line);
     out << line << std::endl;
 
@@ -1143,102 +798,557 @@ void Rinex_Printer::rinex_nav_header(std::fstream& out, const Gps_Iono& iono, co
 }
 
 
-void Rinex_Printer::update_nav_header(std::fstream& out, const Gps_Iono& gps_iono, const Gps_Utc_Model& gps_utc_model, const Galileo_Iono& galileo_iono, const Galileo_Utc_Model& galileo_utc_model, const Galileo_Almanac& galileo_almanac)
+void Rinex_Printer::rinex_nav_header(std::fstream& out, const Gps_Iono& gps_iono, const Gps_Utc_Model& gps_utc_model, const Galileo_Iono& galileo_iono, const Galileo_Utc_Model& galileo_utc_model, const Galileo_Almanac& galileo_almanac)
 {
-    std::vector<std::string> data;
-    std::string line_aux;
+    std::string line;
+        stringVersion = "3.02";
+        version = 3;
 
-    long pos = out.tellp();
-    out.seekp(0);
-    data.clear();
+        // -------- Line 1
+        line = std::string(5, ' ');
+        line += stringVersion;
+        line += std::string(11, ' ');
+        line += std::string("N: GNSS NAV DATA");
+        line += std::string(4, ' ');
+        line += std::string("M: MIXED");
+        line += std::string(12, ' ');
+        line += std::string("RINEX VERSION / TYPE");
+        Rinex_Printer::lengthCheck(line);
+        out << line << std::endl;
 
-    bool no_more_finds = false;
-    std::string line_str;
+        // -------- Line 2
+        line.clear();
+        line += Rinex_Printer::getLocalTime();
+        line += std::string("PGM / RUN BY / DATE");
+        line += std::string(1, ' ');
+        Rinex_Printer::lengthCheck(line);
+        out << line << std::endl;
 
-    while(!out.eof())
-        {
-            std::getline(out, line_str);
+        // -------- Line COMMENT
+        line.clear();
+        line += Rinex_Printer::leftJustify("GNSS NAVIGATION MESSAGE FILE GENERATED BY GNSS-SDR", 60);
+        line += Rinex_Printer::leftJustify("COMMENT", 20);
+        Rinex_Printer::lengthCheck(line);
+        out << line << std::endl;
 
-            if(!no_more_finds)
-                {
-                    line_aux.clear();
+        // -------- Line COMMENT
+        line.clear();
+        std::string gnss_sdr_version(GNSS_SDR_VERSION);
+        line += "GNSS-SDR VERSION ";
+        line += Rinex_Printer::leftJustify(gnss_sdr_version, 43);
+        line += Rinex_Printer::leftJustify("COMMENT", 20);
+        Rinex_Printer::lengthCheck(line);
+        out << line << std::endl;
 
-                    if (line_str.find("GPSA", 0) != std::string::npos)
-                        {
-                            line_aux += std::string("GPSA");
-                            line_aux += std::string(1, ' ');
-                            line_aux += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(gps_iono.d_alpha0, 10, 2), 12);
-                            line_aux += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(gps_iono.d_alpha1, 10, 2), 12);
-                            line_aux += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(gps_iono.d_alpha2, 10, 2), 12);
-                            line_aux += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(gps_iono.d_alpha3, 10, 2), 12);
-                            line_aux += std::string(7, ' ');
-                            line_aux += Rinex_Printer::leftJustify("IONOSPHERIC CORR", 20);
-                            data.push_back(line_aux);
-                        }
-                    else if ((line_str.find("GAL", 0) != std::string::npos) && (line_str.find("IONOSPHERIC CORR", 59) != std::string::npos))
-                        {
-                            line_aux += std::string("GAL ");
-                            line_aux += std::string(1, ' ');
-                            line_aux += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(galileo_iono.ai0_5, 10, 2), 12);
-                            line_aux += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(galileo_iono.ai1_5, 10, 2), 12);
-                            line_aux += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(galileo_iono.ai2_5, 10, 2), 12);
-                            double zero = 0.0;
-                            line_aux += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(zero, 10, 2), 12);
-                            line_aux += std::string(7, ' ');
-                            line_aux += Rinex_Printer::leftJustify("IONOSPHERIC CORR", 20);
-                            data.push_back(line_aux);
-                        }
-                    else if ((line_str.find("GPSB", 0) != std::string::npos) && (line_str.find("IONOSPHERIC CORR", 59) != std::string::npos))
-                        {
-                            line_aux += std::string("GPSB");
-                            line_aux += std::string(1, ' ');
-                            line_aux += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(gps_iono.d_beta0, 10, 2), 12);
-                            line_aux += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(gps_iono.d_beta1, 10, 2), 12);
-                            line_aux += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(gps_iono.d_beta2, 10, 2), 12);
-                            line_aux += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(gps_iono.d_beta3, 10, 2), 12);
-                            line_aux += std::string(7, ' ');
-                            line_aux += Rinex_Printer::leftJustify("IONOSPHERIC CORR", 20);
-                            data.push_back(line_aux);
-                        }
-                    else if ((line_str.find("GPUT", 0) != std::string::npos) && (line_str.find("TIME SYSTEM CORR", 59) != std::string::npos))
-                        {
-                            line_aux += std::string("GPUT");
-                            line_aux += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(gps_utc_model.d_A0, 16, 2), 18);
-                            line_aux += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(gps_utc_model.d_A1, 15, 2), 16);
-                            line_aux += Rinex_Printer::rightJustify(boost::lexical_cast<std::string>(gps_utc_model.d_t_OT), 7);
-                            line_aux += Rinex_Printer::rightJustify(boost::lexical_cast<std::string>(gps_utc_model.i_WN_T + 1024), 5);  // valid until 2019
-                            line_aux += std::string(10, ' ');
-                            line_aux += Rinex_Printer::leftJustify("TIME SYSTEM CORR", 20);
+        // -------- Line COMMENT
+        line.clear();
+        line += Rinex_Printer::leftJustify("See http://gnss-sdr.org", 60);
+        line += Rinex_Printer::leftJustify("COMMENT", 20);
+        Rinex_Printer::lengthCheck(line);
+        out << line << std::endl;
+
+
+        // -------- Line ionospheric info 1
+        line.clear();
+        line += std::string("GAL ");
+        line += std::string(1, ' ');
+        line += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(galileo_iono.ai0_5, 10, 2), 12);
+        line += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(galileo_iono.ai1_5, 10, 2), 12);
+        line += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(galileo_iono.ai2_5, 10, 2), 12);
+        double zero = 0.0;
+        line += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(zero, 10, 2), 12);
+        line += std::string(7, ' ');
+        line += Rinex_Printer::leftJustify("IONOSPHERIC CORR", 20);
+        Rinex_Printer::lengthCheck(line);
+        out << line << std::endl;
+
+        // -------- Line ionospheric info 2
+        line.clear();
+        line += std::string("GPSA");
+        line += std::string(1, ' ');
+        line += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(gps_iono.d_alpha0, 10, 2), 12);
+        line += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(gps_iono.d_alpha1, 10, 2), 12);
+        line += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(gps_iono.d_alpha2, 10, 2), 12);
+        line += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(gps_iono.d_alpha3, 10, 2), 12);
+        line += std::string(7, ' ');
+        line += Rinex_Printer::leftJustify("IONOSPHERIC CORR", 20);
+        Rinex_Printer::lengthCheck(line);
+        out << line << std::endl;
+
+        // -------- Line system time correction
+        line.clear();
+        line += std::string("GAUT");
+        line += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(galileo_utc_model.A0_6, 16, 2), 18);
+        line += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(galileo_utc_model.A1_6, 15, 2), 16);
+        line += Rinex_Printer::rightJustify(boost::lexical_cast<std::string>(galileo_utc_model.t0t_6), 7);
+        line += Rinex_Printer::rightJustify(boost::lexical_cast<std::string>(galileo_utc_model.WNot_6), 5);
+        line += std::string(10, ' ');
+        line += Rinex_Printer::leftJustify("TIME SYSTEM CORR", 20);
+        Rinex_Printer::lengthCheck(line);
+        out << line << std::endl;
+
+        // -------- Line system time correction 2
+        line.clear();
+        line += std::string("GPGA");
+        line += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(galileo_almanac.A_0G_10, 16, 2), 18);
+        line += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(galileo_almanac.A_1G_10, 15, 2), 16);
+        line += Rinex_Printer::rightJustify(boost::lexical_cast<std::string>(galileo_almanac.t_0G_10), 7);
+        line += Rinex_Printer::rightJustify(boost::lexical_cast<std::string>(galileo_almanac.WN_0G_10), 5);
+        line += std::string(10, ' ');
+        line += Rinex_Printer::leftJustify("TIME SYSTEM CORR", 20);
+        Rinex_Printer::lengthCheck(line);
+        out << line << std::endl;
+
+        // -------- Line system time correction 3
+        line.clear();
+        line += std::string("GPUT");
+        line += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(gps_utc_model.d_A0, 16, 2), 18);
+        line += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(gps_utc_model.d_A1, 15, 2), 16);
+        line += Rinex_Printer::rightJustify(boost::lexical_cast<std::string>(gps_utc_model.d_t_OT), 7);
+        line += Rinex_Printer::rightJustify(boost::lexical_cast<std::string>(gps_utc_model.i_WN_T + 1024), 5);  // valid until 2019
+        line += std::string(10, ' ');
+        line += Rinex_Printer::leftJustify("TIME SYSTEM CORR", 20);
+        Rinex_Printer::lengthCheck(line);
+        out << line << std::endl;
+
+
+        // -------- Line 6 leap seconds
+        // For leap second information, see http://www.endruntechnologies.com/leap.htm
+        line.clear();
+        line += Rinex_Printer::rightJustify(boost::lexical_cast<std::string>(gps_utc_model.d_DeltaT_LS), 6);
+        line += Rinex_Printer::rightJustify(boost::lexical_cast<std::string>(gps_utc_model.d_DeltaT_LSF), 6);
+        line += Rinex_Printer::rightJustify(boost::lexical_cast<std::string>(gps_utc_model.i_WN_LSF), 6);
+        line += Rinex_Printer::rightJustify(boost::lexical_cast<std::string>(gps_utc_model.i_DN), 6);
+        line += std::string(36, ' ');
+        line += Rinex_Printer::leftJustify("LEAP SECONDS", 20);
+        Rinex_Printer::lengthCheck(line);
+        out << line << std::endl;
+
+        // -------- End of Header
+        line.clear();
+        line += std::string(60, ' ');
+        line += Rinex_Printer::leftJustify("END OF HEADER", 20);
+        Rinex_Printer::lengthCheck(line);
+        out << line << std::endl;
+}
+
+
+void Rinex_Printer::rinex_sbs_header(std::fstream& out)
+{
+    std::string line;
+
+    // -------- Line 1
+    line.clear();
+    line = std::string(5, ' ');
+    line += std::string("2.10");
+    line += std::string(11, ' ');
+    line += Rinex_Printer::leftJustify("B SBAS DATA",20);
+    line += std::string(20, ' ');
+    line += std::string("RINEX VERSION / TYPE");
+
+    Rinex_Printer::lengthCheck(line);
+    out << line << std::endl;
+
+    // -------- Line 2
+    line.clear();
+    line += Rinex_Printer::leftJustify("GNSS-SDR", 20);
+    std::string username;
+    char c_username[20] = {0};
+    int nGet = getlogin_r(c_username, sizeof(c_username) - 1);
+    if (nGet == 0)
+        {
+            username = c_username;
+        }
+    else
+        {
+            username = "UNKNOWN USER";
+        }
+    line += Rinex_Printer::leftJustify(username, 20);
+    // Date of file creation (dd-mmm-yy hhmm)
+    boost::local_time::time_zone_ptr zone(new boost::local_time::posix_time_zone("UTC"));
+    boost::local_time::local_date_time pt = boost::local_time::local_sec_clock::local_time(zone);
+    tm pt_tm = boost::local_time::to_tm(pt);
+    std::stringstream strYear;
+    int utc_year = pt.date().year();
+    utc_year -= 2000; //  two digits for year
+    strYear << utc_year;
+    std::stringstream strMonth;
+    int utc_month = pt.date().month().as_number();
+    if (utc_month < 10) strMonth << "0"; //  two digits for months
+    strMonth << utc_month;
+    std::stringstream strmDay;
+    int utc_day = pt.date().day().as_number();
+    if (utc_day < 10) strmDay << "0"; //  two digits for days
+    strmDay << utc_day;
+    std::stringstream strmHour;
+    int utc_hour = pt_tm.tm_hour;
+    if (utc_hour < 10) strmHour << "0"; //  two digits for hours
+    strmHour << utc_hour;
+    std::stringstream strmMin;
+    int utc_minute = pt_tm.tm_min;
+    if (utc_minute < 10) strmMin << "0"; //  two digits for minutes
+    strmMin << utc_minute;
+    std::string time_str;
+    time_str += strmDay.str();
+    time_str += "-";
+    time_str += strMonth.str();
+    time_str += "-";
+    time_str += strYear.str();
+    time_str += " ";
+    time_str += strmHour.str();
+    time_str += strmMin.str();
+    line += Rinex_Printer::leftJustify(time_str, 20);
+    line += Rinex_Printer::leftJustify("PGM / RUN BY / DATE", 20);
+    Rinex_Printer::lengthCheck(line);
+    out << line << std::endl;
+
+    // -------- Line 3
+    line.clear();
+    line += std::string(60, ' ');
+    line += Rinex_Printer::leftJustify("REC INDEX/TYPE/VERS", 20);
+    Rinex_Printer::lengthCheck(line);
+    out << line << std::endl;
+
+    // -------- Line COMMENT 1
+    line.clear();
+    line += Rinex_Printer::leftJustify("BROADCAST DATA FILE FOR GEO SV, GENERATED BY GNSS-SDR", 60);
+    line += Rinex_Printer::leftJustify("COMMENT", 20);
+    Rinex_Printer::lengthCheck(line);
+    out << line << std::endl;
+
+    // -------- Line COMMENT
+    line.clear();
+    std::string gnss_sdr_version(GNSS_SDR_VERSION);
+    line += "GNSS-SDR VERSION ";
+    line += Rinex_Printer::leftJustify(gnss_sdr_version, 43);
+    line += Rinex_Printer::leftJustify("COMMENT", 20);
+    Rinex_Printer::lengthCheck(line);
+    out << line << std::endl;
+
+    // -------- Line COMMENT 2
+    line.clear();
+    line += Rinex_Printer::leftJustify("See http://gnss-sdr.org", 60);
+    line += Rinex_Printer::leftJustify("COMMENT", 20);
+    Rinex_Printer::lengthCheck(line);
+    out << line << std::endl;
+
+    // -------- End of Header
+    line.clear();
+    line += std::string(60, ' ');
+    line += Rinex_Printer::leftJustify("END OF HEADER", 20);
+    Rinex_Printer::lengthCheck(line);
+    out << line << std::endl;
+}
+
+
+void Rinex_Printer::update_nav_header(std::fstream& out, const Galileo_Iono& galileo_iono, const Galileo_Utc_Model& utc_model, const Galileo_Almanac& galileo_almanac)
+{
+    std::vector<std::string> data;
+    std::string line_aux;
+
+    long pos = out.tellp();
+    out.seekp(0);
+    data.clear();
+
+    bool no_more_finds = false;
+    std::string line_str;
+
+    while(!out.eof())
+        {
+            std::getline(out, line_str);
+
+            if(!no_more_finds)
+                {
+                    line_aux.clear();
+
+                    if ((line_str.find("GAL", 0) != std::string::npos) && (line_str.find("IONOSPHERIC CORR", 59) != std::string::npos))
+                        {
+                            line_aux += std::string("GAL ");
+                            line_aux += std::string(1, ' ');
+                            line_aux += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(galileo_iono.ai0_5, 10, 2), 12);
+                            line_aux += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(galileo_iono.ai1_5, 10, 2), 12);
+                            line_aux += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(galileo_iono.ai2_5, 10, 2), 12);
+                            double zero = 0.0;
+                            line_aux += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(zero, 10, 2), 12);
+                            line_aux += std::string(7, ' ');
+                            line_aux += Rinex_Printer::leftJustify("IONOSPHERIC CORR", 20);
+                            data.push_back(line_aux);
+                        }
+                    else if ((line_str.find("GAUT", 0) != std::string::npos) && (line_str.find("TIME SYSTEM CORR", 59) != std::string::npos))
+                        {
+                            line_aux += std::string("GAUT");
+                            line_aux += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(utc_model.A0_6, 16, 2), 18);
+                            line_aux += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(utc_model.A1_6, 15, 2), 16);
+                            line_aux += Rinex_Printer::rightJustify(boost::lexical_cast<std::string>(utc_model.t0t_6), 7);
+                            line_aux += Rinex_Printer::rightJustify(boost::lexical_cast<std::string>(utc_model.WNot_6), 5);
+                            line_aux += std::string(10, ' ');
+                            line_aux += Rinex_Printer::leftJustify("TIME SYSTEM CORR", 20);
+                            data.push_back(line_aux);
+                        }
+                    else if ((line_str.find("GPGA", 0) != std::string::npos) && (line_str.find("TIME SYSTEM CORR", 59) != std::string::npos))
+                        {
+                            line_aux += std::string("GPGA");
+                            line_aux += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(galileo_almanac.A_0G_10, 16, 2), 18);
+                            line_aux += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(galileo_almanac.A_1G_10, 15, 2), 16);
+                            line_aux += Rinex_Printer::rightJustify(boost::lexical_cast<std::string>(galileo_almanac.t_0G_10), 7);
+                            line_aux += Rinex_Printer::rightJustify(boost::lexical_cast<std::string>(galileo_almanac.WN_0G_10), 5);
+                            line_aux += std::string(10, ' ');
+                            line_aux += Rinex_Printer::leftJustify("TIME SYSTEM CORR", 20);
+                            data.push_back(line_aux);
+                        }
+                    else if (line_str.find("LEAP SECONDS", 59) != std::string::npos)
+                        {
+                            line_aux += Rinex_Printer::rightJustify(boost::lexical_cast<std::string>(utc_model.Delta_tLS_6), 6);
+                            line_aux += Rinex_Printer::rightJustify(boost::lexical_cast<std::string>(utc_model.Delta_tLSF_6), 6);
+                            line_aux += Rinex_Printer::rightJustify(boost::lexical_cast<std::string>(utc_model.WN_LSF_6), 6);
+                            line_aux += Rinex_Printer::rightJustify(boost::lexical_cast<std::string>(utc_model.DN_6), 6);
+                            line_aux += std::string(36, ' ');
+                            line_aux += Rinex_Printer::leftJustify("LEAP SECONDS", 20);
+                            data.push_back(line_aux);
+                        }
+                    else if (line_str.find("END OF HEADER", 59) != std::string::npos)
+                        {
+                            data.push_back(line_str);
+                            no_more_finds = true;
+                        }
+                    else
+                        {
+                            data.push_back(line_str);
+                        }
+
+                }
+            else
+                {
+                    data.push_back(line_str);
+                }
+        }
+
+    out.close();
+    out.open(navGalfilename, std::ios::out | std::ios::trunc);
+    out.seekp(0);
+    for (int i = 0; i < (int) data.size() - 1; i++)
+        {
+            out << data[i] << std::endl;
+        }
+    out.close();
+    out.open(navGalfilename, std::ios::out | std::ios::app);
+    out.seekp(pos);
+    std::cout << "The RINEX Navigation file header has been updated with UTC and IONO info." << std::endl;
+}
+
+
+void Rinex_Printer::update_nav_header(std::fstream& out, const Gps_Utc_Model& utc_model, const Gps_Iono& iono)
+{
+    std::vector<std::string> data;
+    std::string line_aux;
+
+    long pos = out.tellp();
+    out.seekp(0);
+    data.clear();
+
+    bool no_more_finds = false;
+    std::string line_str;
+
+    while(!out.eof())
+        {
+            std::getline(out, line_str);
+
+            if(!no_more_finds)
+                {
+                    line_aux.clear();
+
+                    if (version == 2)
+                        {
+                            if (line_str.find("ION ALPHA", 59) != std::string::npos)
+                                {
+                                    line_aux += std::string(2, ' ');
+                                    line_aux += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(iono.d_alpha0, 10, 2), 12);
+                                    line_aux += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(iono.d_alpha1, 10, 2), 12);
+                                    line_aux += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(iono.d_alpha2, 10, 2), 12);
+                                    line_aux += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(iono.d_alpha3, 10, 2), 12);
+                                    line_aux += std::string(10, ' ');
+                                    line_aux += Rinex_Printer::leftJustify("ION ALPHA", 20);
+                                    data.push_back(line_aux);
+                                }
+                            else if (line_str.find("ION BETA", 59) != std::string::npos)
+                                {
+                                    line_aux += std::string(2, ' ');
+                                    line_aux += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(iono.d_beta0, 10, 2), 12);
+                                    line_aux += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(iono.d_beta1, 10, 2), 12);
+                                    line_aux += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(iono.d_beta2, 10, 2), 12);
+                                    line_aux += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(iono.d_beta3, 10, 2), 12);
+                                    line_aux += std::string(10, ' ');
+                                    line_aux += Rinex_Printer::leftJustify("ION BETA", 20);
+                                    data.push_back(line_aux);
+                                }
+                            else if (line_str.find("DELTA-UTC", 59) != std::string::npos)
+                                {
+                                    line_aux += std::string(3, ' ');
+                                    line_aux += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(utc_model.d_A0, 18, 2), 19);
+                                    line_aux += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(utc_model.d_A1, 18, 2), 19);
+                                    line_aux += Rinex_Printer::rightJustify(boost::lexical_cast<std::string>(utc_model.d_t_OT), 9);
+                                    line_aux += Rinex_Printer::rightJustify(boost::lexical_cast<std::string>(utc_model.i_WN_T + 1024), 9); // valid until 2019
+                                    line_aux += std::string(1, ' ');
+                                    line_aux += Rinex_Printer::leftJustify("DELTA-UTC: A0,A1,T,W", 20);
+                                    data.push_back(line_aux);
+                                }
+                            else if (line_str.find("LEAP SECONDS", 59) != std::string::npos)
+                                {
+                                    line_aux += Rinex_Printer::rightJustify(boost::lexical_cast<std::string>(utc_model.d_DeltaT_LS), 6);
+                                    line_aux += std::string(54, ' ');
+                                    line_aux += Rinex_Printer::leftJustify("LEAP SECONDS", 20);
+                                    data.push_back(line_aux);
+                                }
+                            else if (line_str.find("END OF HEADER", 59) != std::string::npos)
+                                {
+                                    data.push_back(line_str);
+                                    no_more_finds = true;
+                                }
+                            else
+                                {
+                                    data.push_back(line_str);
+                                }
+                        }
+
+                    if (version == 3)
+                        {
+                            if (line_str.find("GPSA", 0) != std::string::npos)
+                                {
+                                    line_aux += std::string("GPSA");
+                                    line_aux += std::string(1, ' ');
+                                    line_aux += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(iono.d_alpha0, 10, 2), 12);
+                                    line_aux += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(iono.d_alpha1, 10, 2), 12);
+                                    line_aux += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(iono.d_alpha2, 10, 2), 12);
+                                    line_aux += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(iono.d_alpha3, 10, 2), 12);
+                                    line_aux += std::string(7, ' ');
+                                    line_aux += Rinex_Printer::leftJustify("IONOSPHERIC CORR", 20);
+                                    data.push_back(line_aux);
+                                }
+                            else if (line_str.find("GPSB", 0) != std::string::npos)
+                                {
+                                    line_aux += std::string("GPSB");
+                                    line_aux += std::string(1, ' ');
+                                    line_aux += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(iono.d_beta0, 10, 2), 12);
+                                    line_aux += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(iono.d_beta1, 10, 2), 12);
+                                    line_aux += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(iono.d_beta2, 10, 2), 12);
+                                    line_aux += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(iono.d_beta3, 10, 2), 12);
+                                    line_aux += std::string(7, ' ');
+                                    line_aux += Rinex_Printer::leftJustify("IONOSPHERIC CORR", 20);
+                                    data.push_back(line_aux);
+                                }
+                            else if (line_str.find("GPUT", 0) != std::string::npos)
+                                {
+                                    line_aux += std::string("GPUT");
+                                    line_aux += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(utc_model.d_A0, 16, 2), 18);
+                                    line_aux += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(utc_model.d_A1, 15, 2), 16);
+                                    line_aux += Rinex_Printer::rightJustify(boost::lexical_cast<std::string>(utc_model.d_t_OT), 7);
+                                    line_aux += Rinex_Printer::rightJustify(boost::lexical_cast<std::string>(utc_model.i_WN_T + 1024), 5);  // valid until 2019
+                                    line_aux += std::string(10, ' ');
+                                    line_aux += Rinex_Printer::leftJustify("TIME SYSTEM CORR", 20);
+                                    data.push_back(line_aux);
+                                }
+                            else if (line_str.find("LEAP SECONDS", 59) != std::string::npos)
+                                {
+                                    line_aux += Rinex_Printer::rightJustify(boost::lexical_cast<std::string>(utc_model.d_DeltaT_LS), 6);
+                                    line_aux += Rinex_Printer::rightJustify(boost::lexical_cast<std::string>(utc_model.d_DeltaT_LSF), 6);
+                                    line_aux += Rinex_Printer::rightJustify(boost::lexical_cast<std::string>(utc_model.i_WN_LSF), 6);
+                                    line_aux += Rinex_Printer::rightJustify(boost::lexical_cast<std::string>(utc_model.i_DN), 6);
+                                    line_aux += std::string(36, ' ');
+                                    line_aux += Rinex_Printer::leftJustify("LEAP SECONDS", 20);
+                                    data.push_back(line_aux);
+                                }
+                            else if (line_str.find("END OF HEADER", 59) != std::string::npos)
+                                {
+                                    data.push_back(line_str);
+                                    no_more_finds = true;
+                                }
+                            else
+                                {
+                                    data.push_back(line_str);
+                                }
+                        }
+                }
+            else
+                {
+                    data.push_back(line_str);
+                }
+        }
+
+    out.close();
+    out.open(navfilename, std::ios::out | std::ios::trunc);
+    out.seekp(0);
+    for (int i = 0; i < (int) data.size() - 1; i++)
+        {
+            out << data[i] << std::endl;
+        }
+    out.close();
+    out.open(navfilename, std::ios::out | std::ios::app);
+    out.seekp(pos);
+    std::cout << "The RINEX Navigation file header has been updated with UTC and IONO info." << std::endl;
+}
+
+
+void Rinex_Printer::update_nav_header(std::fstream & out, const Gps_CNAV_Utc_Model & utc_model, const Gps_CNAV_Iono & iono )
+{
+    std::vector<std::string> data;
+    std::string line_aux;
+
+    long pos = out.tellp();
+    out.seekp(0);
+    data.clear();
+
+    bool no_more_finds = false;
+    std::string line_str;
+
+    while(!out.eof())
+        {
+            std::getline(out, line_str);
+
+            if(!no_more_finds)
+                {
+                    line_aux.clear();
+
+                    if (line_str.find("GPSA", 0) != std::string::npos)
+                        {
+                            line_aux += std::string("GPSA");
+                            line_aux += std::string(1, ' ');
+                            line_aux += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(iono.d_alpha0, 10, 2), 12);
+                            line_aux += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(iono.d_alpha1, 10, 2), 12);
+                            line_aux += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(iono.d_alpha2, 10, 2), 12);
+                            line_aux += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(iono.d_alpha3, 10, 2), 12);
+                            line_aux += std::string(7, ' ');
+                            line_aux += Rinex_Printer::leftJustify("IONOSPHERIC CORR", 20);
                             data.push_back(line_aux);
                         }
-                    else if ((line_str.find("GAUT", 0) != std::string::npos) && (line_str.find("TIME SYSTEM CORR", 59) != std::string::npos))
+                    else if (line_str.find("GPSB", 0) != std::string::npos)
                         {
-                            line_aux += std::string("GAUT");
-                            line_aux += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(galileo_utc_model.A0_6, 16, 2), 18);
-                            line_aux += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(galileo_utc_model.A1_6, 15, 2), 16);
-                            line_aux += Rinex_Printer::rightJustify(boost::lexical_cast<std::string>(galileo_utc_model.t0t_6), 7);
-                            line_aux += Rinex_Printer::rightJustify(boost::lexical_cast<std::string>(galileo_utc_model.WNot_6), 5);
-                            line_aux += std::string(10, ' ');
-                            line_aux += Rinex_Printer::leftJustify("TIME SYSTEM CORR", 20);
+                            line_aux += std::string("GPSB");
+                            line_aux += std::string(1, ' ');
+                            line_aux += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(iono.d_beta0, 10, 2), 12);
+                            line_aux += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(iono.d_beta1, 10, 2), 12);
+                            line_aux += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(iono.d_beta2, 10, 2), 12);
+                            line_aux += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(iono.d_beta3, 10, 2), 12);
+                            line_aux += std::string(7, ' ');
+                            line_aux += Rinex_Printer::leftJustify("IONOSPHERIC CORR", 20);
                             data.push_back(line_aux);
                         }
-                    else if ((line_str.find("GPGA", 0) != std::string::npos) && (line_str.find("TIME SYSTEM CORR", 59) != std::string::npos))
+                    else if (line_str.find("GPUT", 0) != std::string::npos)
                         {
-                            line_aux += std::string("GPGA");
-                            line_aux += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(galileo_almanac.A_0G_10, 16, 2), 18);
-                            line_aux += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(galileo_almanac.A_1G_10, 15, 2), 16);
-                            line_aux += Rinex_Printer::rightJustify(boost::lexical_cast<std::string>(galileo_almanac.t_0G_10), 7);
-                            line_aux += Rinex_Printer::rightJustify(boost::lexical_cast<std::string>(galileo_almanac.WN_0G_10), 5);
+                            line_aux += std::string("GPUT");
+                            line_aux += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(utc_model.d_A0, 16, 2), 18);
+                            line_aux += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(utc_model.d_A1, 15, 2), 16);
+                            line_aux += Rinex_Printer::rightJustify(boost::lexical_cast<std::string>(utc_model.d_t_OT), 7);
+                            line_aux += Rinex_Printer::rightJustify(boost::lexical_cast<std::string>(utc_model.i_WN_T + 1024), 5);  // valid until 2019
                             line_aux += std::string(10, ' ');
                             line_aux += Rinex_Printer::leftJustify("TIME SYSTEM CORR", 20);
                             data.push_back(line_aux);
                         }
                     else if (line_str.find("LEAP SECONDS", 59) != std::string::npos)
                         {
-                            line_aux += Rinex_Printer::rightJustify(boost::lexical_cast<std::string>(gps_utc_model.d_DeltaT_LS), 6);
-                            line_aux += Rinex_Printer::rightJustify(boost::lexical_cast<std::string>(gps_utc_model.d_DeltaT_LSF), 6);
-                            line_aux += Rinex_Printer::rightJustify(boost::lexical_cast<std::string>(gps_utc_model.i_WN_LSF), 6);
-                            line_aux += Rinex_Printer::rightJustify(boost::lexical_cast<std::string>(gps_utc_model.i_DN), 6);
+                            line_aux += Rinex_Printer::rightJustify(boost::lexical_cast<std::string>(utc_model.d_DeltaT_LS), 6);
+                            line_aux += Rinex_Printer::rightJustify(boost::lexical_cast<std::string>(utc_model.d_DeltaT_LSF), 6);
+                            line_aux += Rinex_Printer::rightJustify(boost::lexical_cast<std::string>(utc_model.i_WN_LSF), 6);
+                            line_aux += Rinex_Printer::rightJustify(boost::lexical_cast<std::string>(utc_model.i_DN), 6);
                             line_aux += std::string(36, ' ');
                             line_aux += Rinex_Printer::leftJustify("LEAP SECONDS", 20);
                             data.push_back(line_aux);
@@ -1252,7 +1362,6 @@ void Rinex_Printer::update_nav_header(std::fstream& out, const Gps_Iono& gps_ion
                         {
                             data.push_back(line_str);
                         }
-
                 }
             else
                 {
@@ -1261,259 +1370,147 @@ void Rinex_Printer::update_nav_header(std::fstream& out, const Gps_Iono& gps_ion
         }
 
     out.close();
-    out.open(navMixfilename, std::ios::out | std::ios::trunc);
+    out.open(navfilename, std::ios::out | std::ios::trunc);
     out.seekp(0);
     for (int i = 0; i < (int) data.size() - 1; i++)
         {
             out << data[i] << std::endl;
         }
     out.close();
-    out.open(navMixfilename, std::ios::out | std::ios::app);
+    out.open(navfilename, std::ios::out | std::ios::app);
     out.seekp(pos);
     std::cout << "The RINEX Navigation file header has been updated with UTC and IONO info." << std::endl;
 }
 
 
-void Rinex_Printer::rinex_nav_header(std::fstream& out, const Gps_Iono& gps_iono, const Gps_Utc_Model& gps_utc_model, const Galileo_Iono& galileo_iono, const Galileo_Utc_Model& galileo_utc_model, const Galileo_Almanac& galileo_almanac)
-{
-    std::string line;
-        stringVersion = "3.02";
-        version = 3;
-
-        // -------- Line 1
-        line = std::string(5, ' ');
-        line += stringVersion;
-        line += std::string(11, ' ');
-        line += std::string("N: GNSS NAV DATA");
-        line += std::string(4, ' ');
-        line += std::string("M: MIXED");
-        line += std::string(12, ' ');
-        line += std::string("RINEX VERSION / TYPE");
-        Rinex_Printer::lengthCheck(line);
-        out << line << std::endl;
-
-        // -------- Line 2
-        line.clear();
-        line += Rinex_Printer::getLocalTime();
-        line += std::string("PGM / RUN BY / DATE");
-        line += std::string(1, ' ');
-        Rinex_Printer::lengthCheck(line);
-        out << line << std::endl;
-
-        // -------- Line COMMENT
-        line.clear();
-        line += Rinex_Printer::leftJustify("GNSS NAVIGATION MESSAGE FILE GENERATED BY GNSS-SDR", 60);
-        line += Rinex_Printer::leftJustify("COMMENT", 20);
-        Rinex_Printer::lengthCheck(line);
-        out << line << std::endl;
-
-        // -------- Line COMMENT
-        line.clear();
-        std::string gnss_sdr_version(GNSS_SDR_VERSION);
-        line += "GNSS-SDR VERSION ";
-        line += Rinex_Printer::leftJustify(gnss_sdr_version, 43);
-        line += Rinex_Printer::leftJustify("COMMENT", 20);
-        Rinex_Printer::lengthCheck(line);
-        out << line << std::endl;
-
-        // -------- Line COMMENT
-        line.clear();
-        line += Rinex_Printer::leftJustify("See http://gnss-sdr.org", 60);
-        line += Rinex_Printer::leftJustify("COMMENT", 20);
-        Rinex_Printer::lengthCheck(line);
-        out << line << std::endl;
-
-
-        // -------- Line ionospheric info 1
-        line.clear();
-        line += std::string("GAL ");
-        line += std::string(1, ' ');
-        line += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(galileo_iono.ai0_5, 10, 2), 12);
-        line += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(galileo_iono.ai1_5, 10, 2), 12);
-        line += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(galileo_iono.ai2_5, 10, 2), 12);
-        double zero = 0.0;
-        line += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(zero, 10, 2), 12);
-        line += std::string(7, ' ');
-        line += Rinex_Printer::leftJustify("IONOSPHERIC CORR", 20);
-        Rinex_Printer::lengthCheck(line);
-        out << line << std::endl;
-
-        // -------- Line ionospheric info 2
-        line.clear();
-        line += std::string("GPSA");
-        line += std::string(1, ' ');
-        line += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(gps_iono.d_alpha0, 10, 2), 12);
-        line += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(gps_iono.d_alpha1, 10, 2), 12);
-        line += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(gps_iono.d_alpha2, 10, 2), 12);
-        line += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(gps_iono.d_alpha3, 10, 2), 12);
-        line += std::string(7, ' ');
-        line += Rinex_Printer::leftJustify("IONOSPHERIC CORR", 20);
-        Rinex_Printer::lengthCheck(line);
-        out << line << std::endl;
-
-        // -------- Line system time correction
-        line.clear();
-        line += std::string("GAUT");
-        line += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(galileo_utc_model.A0_6, 16, 2), 18);
-        line += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(galileo_utc_model.A1_6, 15, 2), 16);
-        line += Rinex_Printer::rightJustify(boost::lexical_cast<std::string>(galileo_utc_model.t0t_6), 7);
-        line += Rinex_Printer::rightJustify(boost::lexical_cast<std::string>(galileo_utc_model.WNot_6), 5);
-        line += std::string(10, ' ');
-        line += Rinex_Printer::leftJustify("TIME SYSTEM CORR", 20);
-        Rinex_Printer::lengthCheck(line);
-        out << line << std::endl;
-
-        // -------- Line system time correction 2
-        line.clear();
-        line += std::string("GPGA");
-        line += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(galileo_almanac.A_0G_10, 16, 2), 18);
-        line += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(galileo_almanac.A_1G_10, 15, 2), 16);
-        line += Rinex_Printer::rightJustify(boost::lexical_cast<std::string>(galileo_almanac.t_0G_10), 7);
-        line += Rinex_Printer::rightJustify(boost::lexical_cast<std::string>(galileo_almanac.WN_0G_10), 5);
-        line += std::string(10, ' ');
-        line += Rinex_Printer::leftJustify("TIME SYSTEM CORR", 20);
-        Rinex_Printer::lengthCheck(line);
-        out << line << std::endl;
-
-        // -------- Line system time correction 3
-        line.clear();
-        line += std::string("GPUT");
-        line += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(gps_utc_model.d_A0, 16, 2), 18);
-        line += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(gps_utc_model.d_A1, 15, 2), 16);
-        line += Rinex_Printer::rightJustify(boost::lexical_cast<std::string>(gps_utc_model.d_t_OT), 7);
-        line += Rinex_Printer::rightJustify(boost::lexical_cast<std::string>(gps_utc_model.i_WN_T + 1024), 5);  // valid until 2019
-        line += std::string(10, ' ');
-        line += Rinex_Printer::leftJustify("TIME SYSTEM CORR", 20);
-        Rinex_Printer::lengthCheck(line);
-        out << line << std::endl;
-
-
-        // -------- Line 6 leap seconds
-        // For leap second information, see http://www.endruntechnologies.com/leap.htm
-        line.clear();
-        line += Rinex_Printer::rightJustify(boost::lexical_cast<std::string>(gps_utc_model.d_DeltaT_LS), 6);
-        line += Rinex_Printer::rightJustify(boost::lexical_cast<std::string>(gps_utc_model.d_DeltaT_LSF), 6);
-        line += Rinex_Printer::rightJustify(boost::lexical_cast<std::string>(gps_utc_model.i_WN_LSF), 6);
-        line += Rinex_Printer::rightJustify(boost::lexical_cast<std::string>(gps_utc_model.i_DN), 6);
-        line += std::string(36, ' ');
-        line += Rinex_Printer::leftJustify("LEAP SECONDS", 20);
-        Rinex_Printer::lengthCheck(line);
-        out << line << std::endl;
-
-        // -------- End of Header
-        line.clear();
-        line += std::string(60, ' ');
-        line += Rinex_Printer::leftJustify("END OF HEADER", 20);
-        Rinex_Printer::lengthCheck(line);
-        out << line << std::endl;
-}
-
-
-void Rinex_Printer::rinex_sbs_header(std::fstream& out)
+void Rinex_Printer::update_nav_header(std::fstream& out, const Gps_Iono& gps_iono, const Gps_Utc_Model& gps_utc_model, const Galileo_Iono& galileo_iono, const Galileo_Utc_Model& galileo_utc_model, const Galileo_Almanac& galileo_almanac)
 {
-    std::string line;
-
-    // -------- Line 1
-    line.clear();
-    line = std::string(5, ' ');
-    line += std::string("2.10");
-    line += std::string(11, ' ');
-    line += Rinex_Printer::leftJustify("B SBAS DATA",20);
-    line += std::string(20, ' ');
-    line += std::string("RINEX VERSION / TYPE");
-
-    Rinex_Printer::lengthCheck(line);
-    out << line << std::endl;
+    std::vector<std::string> data;
+    std::string line_aux;
 
-    // -------- Line 2
-    line.clear();
-    line += Rinex_Printer::leftJustify("GNSS-SDR", 20);
-    std::string username;
-    char c_username[20] = {0};
-    int nGet = getlogin_r(c_username, sizeof(c_username) - 1);
-    if (nGet == 0)
-        {
-            username = c_username;
-        }
-    else
-        {
-            username = "UNKNOWN USER";
-        }
-    line += Rinex_Printer::leftJustify(username, 20);
-    // Date of file creation (dd-mmm-yy hhmm)
-    boost::local_time::time_zone_ptr zone(new boost::local_time::posix_time_zone("UTC"));
-    boost::local_time::local_date_time pt = boost::local_time::local_sec_clock::local_time(zone);
-    tm pt_tm = boost::local_time::to_tm(pt);
-    std::stringstream strYear;
-    int utc_year = pt.date().year();
-    utc_year -= 2000; //  two digits for year
-    strYear << utc_year;
-    std::stringstream strMonth;
-    int utc_month = pt.date().month().as_number();
-    if (utc_month < 10) strMonth << "0"; //  two digits for months
-    strMonth << utc_month;
-    std::stringstream strmDay;
-    int utc_day = pt.date().day().as_number();
-    if (utc_day < 10) strmDay << "0"; //  two digits for days
-    strmDay << utc_day;
-    std::stringstream strmHour;
-    int utc_hour = pt_tm.tm_hour;
-    if (utc_hour < 10) strmHour << "0"; //  two digits for hours
-    strmHour << utc_hour;
-    std::stringstream strmMin;
-    int utc_minute = pt_tm.tm_min;
-    if (utc_minute < 10) strmMin << "0"; //  two digits for minutes
-    strmMin << utc_minute;
-    std::string time_str;
-    time_str += strmDay.str();
-    time_str += "-";
-    time_str += strMonth.str();
-    time_str += "-";
-    time_str += strYear.str();
-    time_str += " ";
-    time_str += strmHour.str();
-    time_str += strmMin.str();
-    line += Rinex_Printer::leftJustify(time_str, 20);
-    line += Rinex_Printer::leftJustify("PGM / RUN BY / DATE", 20);
-    Rinex_Printer::lengthCheck(line);
-    out << line << std::endl;
+    long pos = out.tellp();
+    out.seekp(0);
+    data.clear();
 
-    // -------- Line 3
-    line.clear();
-    line += std::string(60, ' ');
-    line += Rinex_Printer::leftJustify("REC INDEX/TYPE/VERS", 20);
-    Rinex_Printer::lengthCheck(line);
-    out << line << std::endl;
+    bool no_more_finds = false;
+    std::string line_str;
 
-    // -------- Line COMMENT 1
-    line.clear();
-    line += Rinex_Printer::leftJustify("BROADCAST DATA FILE FOR GEO SV, GENERATED BY GNSS-SDR", 60);
-    line += Rinex_Printer::leftJustify("COMMENT", 20);
-    Rinex_Printer::lengthCheck(line);
-    out << line << std::endl;
+    while(!out.eof())
+        {
+            std::getline(out, line_str);
 
-    // -------- Line COMMENT
-    line.clear();
-    std::string gnss_sdr_version(GNSS_SDR_VERSION);
-    line += "GNSS-SDR VERSION ";
-    line += Rinex_Printer::leftJustify(gnss_sdr_version, 43);
-    line += Rinex_Printer::leftJustify("COMMENT", 20);
-    Rinex_Printer::lengthCheck(line);
-    out << line << std::endl;
+            if(!no_more_finds)
+                {
+                    line_aux.clear();
 
-    // -------- Line COMMENT 2
-    line.clear();
-    line += Rinex_Printer::leftJustify("See http://gnss-sdr.org", 60);
-    line += Rinex_Printer::leftJustify("COMMENT", 20);
-    Rinex_Printer::lengthCheck(line);
-    out << line << std::endl;
+                    if (line_str.find("GPSA", 0) != std::string::npos)
+                        {
+                            line_aux += std::string("GPSA");
+                            line_aux += std::string(1, ' ');
+                            line_aux += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(gps_iono.d_alpha0, 10, 2), 12);
+                            line_aux += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(gps_iono.d_alpha1, 10, 2), 12);
+                            line_aux += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(gps_iono.d_alpha2, 10, 2), 12);
+                            line_aux += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(gps_iono.d_alpha3, 10, 2), 12);
+                            line_aux += std::string(7, ' ');
+                            line_aux += Rinex_Printer::leftJustify("IONOSPHERIC CORR", 20);
+                            data.push_back(line_aux);
+                        }
+                    else if ((line_str.find("GAL", 0) != std::string::npos) && (line_str.find("IONOSPHERIC CORR", 59) != std::string::npos))
+                        {
+                            line_aux += std::string("GAL ");
+                            line_aux += std::string(1, ' ');
+                            line_aux += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(galileo_iono.ai0_5, 10, 2), 12);
+                            line_aux += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(galileo_iono.ai1_5, 10, 2), 12);
+                            line_aux += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(galileo_iono.ai2_5, 10, 2), 12);
+                            double zero = 0.0;
+                            line_aux += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(zero, 10, 2), 12);
+                            line_aux += std::string(7, ' ');
+                            line_aux += Rinex_Printer::leftJustify("IONOSPHERIC CORR", 20);
+                            data.push_back(line_aux);
+                        }
+                    else if ((line_str.find("GPSB", 0) != std::string::npos) && (line_str.find("IONOSPHERIC CORR", 59) != std::string::npos))
+                        {
+                            line_aux += std::string("GPSB");
+                            line_aux += std::string(1, ' ');
+                            line_aux += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(gps_iono.d_beta0, 10, 2), 12);
+                            line_aux += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(gps_iono.d_beta1, 10, 2), 12);
+                            line_aux += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(gps_iono.d_beta2, 10, 2), 12);
+                            line_aux += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(gps_iono.d_beta3, 10, 2), 12);
+                            line_aux += std::string(7, ' ');
+                            line_aux += Rinex_Printer::leftJustify("IONOSPHERIC CORR", 20);
+                            data.push_back(line_aux);
+                        }
+                    else if ((line_str.find("GPUT", 0) != std::string::npos) && (line_str.find("TIME SYSTEM CORR", 59) != std::string::npos))
+                        {
+                            line_aux += std::string("GPUT");
+                            line_aux += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(gps_utc_model.d_A0, 16, 2), 18);
+                            line_aux += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(gps_utc_model.d_A1, 15, 2), 16);
+                            line_aux += Rinex_Printer::rightJustify(boost::lexical_cast<std::string>(gps_utc_model.d_t_OT), 7);
+                            line_aux += Rinex_Printer::rightJustify(boost::lexical_cast<std::string>(gps_utc_model.i_WN_T + 1024), 5);  // valid until 2019
+                            line_aux += std::string(10, ' ');
+                            line_aux += Rinex_Printer::leftJustify("TIME SYSTEM CORR", 20);
+                            data.push_back(line_aux);
+                        }
+                    else if ((line_str.find("GAUT", 0) != std::string::npos) && (line_str.find("TIME SYSTEM CORR", 59) != std::string::npos))
+                        {
+                            line_aux += std::string("GAUT");
+                            line_aux += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(galileo_utc_model.A0_6, 16, 2), 18);
+                            line_aux += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(galileo_utc_model.A1_6, 15, 2), 16);
+                            line_aux += Rinex_Printer::rightJustify(boost::lexical_cast<std::string>(galileo_utc_model.t0t_6), 7);
+                            line_aux += Rinex_Printer::rightJustify(boost::lexical_cast<std::string>(galileo_utc_model.WNot_6), 5);
+                            line_aux += std::string(10, ' ');
+                            line_aux += Rinex_Printer::leftJustify("TIME SYSTEM CORR", 20);
+                            data.push_back(line_aux);
+                        }
+                    else if ((line_str.find("GPGA", 0) != std::string::npos) && (line_str.find("TIME SYSTEM CORR", 59) != std::string::npos))
+                        {
+                            line_aux += std::string("GPGA");
+                            line_aux += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(galileo_almanac.A_0G_10, 16, 2), 18);
+                            line_aux += Rinex_Printer::rightJustify(Rinex_Printer::doub2for(galileo_almanac.A_1G_10, 15, 2), 16);
+                            line_aux += Rinex_Printer::rightJustify(boost::lexical_cast<std::string>(galileo_almanac.t_0G_10), 7);
+                            line_aux += Rinex_Printer::rightJustify(boost::lexical_cast<std::string>(galileo_almanac.WN_0G_10), 5);
+                            line_aux += std::string(10, ' ');
+                            line_aux += Rinex_Printer::leftJustify("TIME SYSTEM CORR", 20);
+                            data.push_back(line_aux);
+                        }
+                    else if (line_str.find("LEAP SECONDS", 59) != std::string::npos)
+                        {
+                            line_aux += Rinex_Printer::rightJustify(boost::lexical_cast<std::string>(gps_utc_model.d_DeltaT_LS), 6);
+                            line_aux += Rinex_Printer::rightJustify(boost::lexical_cast<std::string>(gps_utc_model.d_DeltaT_LSF), 6);
+                            line_aux += Rinex_Printer::rightJustify(boost::lexical_cast<std::string>(gps_utc_model.i_WN_LSF), 6);
+                            line_aux += Rinex_Printer::rightJustify(boost::lexical_cast<std::string>(gps_utc_model.i_DN), 6);
+                            line_aux += std::string(36, ' ');
+                            line_aux += Rinex_Printer::leftJustify("LEAP SECONDS", 20);
+                            data.push_back(line_aux);
+                        }
+                    else if (line_str.find("END OF HEADER", 59) != std::string::npos)
+                        {
+                            data.push_back(line_str);
+                            no_more_finds = true;
+                        }
+                    else
+                        {
+                            data.push_back(line_str);
+                        }
 
-    // -------- End of Header
-    line.clear();
-    line += std::string(60, ' ');
-    line += Rinex_Printer::leftJustify("END OF HEADER", 20);
-    Rinex_Printer::lengthCheck(line);
-    out << line << std::endl;
+                }
+            else
+                {
+                    data.push_back(line_str);
+                }
+        }
+
+    out.close();
+    out.open(navMixfilename, std::ios::out | std::ios::trunc);
+    out.seekp(0);
+    for (int i = 0; i < (int) data.size() - 1; i++)
+        {
+            out << data[i] << std::endl;
+        }
+    out.close();
+    out.open(navMixfilename, std::ios::out | std::ios::app);
+    out.seekp(pos);
+    std::cout << "The RINEX Navigation file header has been updated with UTC and IONO info." << std::endl;
 }
 
 
@@ -2143,132 +2140,50 @@ void Rinex_Printer::log_rinex_nav(std::fstream& out, const std::map<int, Galileo
 
             if(E1B_HS == "11") LOG(WARNING) << "Signal Component currently in Test";
             if(E1B_HS == "10") LOG(WARNING) << "Signal will be out of service";
-            if(E1B_HS == "01") LOG(WARNING) << "Signal out of service";
-            E1B_HS = "00";  // *************** CHANGE THIS WHEN GALILEO SIGNAL IS VALID
-
-            std::string E1B_DVS = boost::lexical_cast<std::string>(galileo_ephemeris_iter->second.E1B_DVS_5);
-            if(E1B_DVS == "1") LOG(WARNING) << "Navigation data without guarantee";
-            E1B_DVS = "0"; // *************** CHANGE THIS WHEN GALILEO SIGNAL IS VALID
-
-            std::string SVhealth_str = E5B_HS + boost::lexical_cast<std::string>(galileo_ephemeris_iter->second.E5b_DVS_5)
-                    + "11" + "1" + E1B_DVS +  E1B_HS
-                    + boost::lexical_cast<std::string>(galileo_ephemeris_iter->second.E1B_DVS_5);
-            SVhealth_str = "000000000"; // *************** CHANGE THIS WHEN GALILEO SIGNAL IS VALID
-            int SVhealth = Rinex_Printer::toInt(SVhealth_str, 9);
-            line += Rinex_Printer::doub2for(static_cast<double>(SVhealth), 18, 2);
-            line += std::string(1, ' ');
-            line += Rinex_Printer::doub2for(galileo_ephemeris_iter->second.BGD_E1E5a_5, 18, 2);
-            line += std::string(1, ' ');
-            line += Rinex_Printer::doub2for(galileo_ephemeris_iter->second.BGD_E1E5b_5, 18, 2);
-            Rinex_Printer::lengthCheck(line);
-            out << line << std::endl;
-
-
-            // -------- BROADCAST ORBIT - 7
-            line.clear();
-            line += std::string(5, ' ');
-            line += Rinex_Printer::doub2for(galileo_ephemeris_iter->second.TOW_5, 18, 2);
-            line += std::string(1, ' ');
-            line += Rinex_Printer::doub2for(zero, 18, 2);
-            line += std::string(1, ' ');
-            line += std::string(18, ' '); // spare
-            line += std::string(1, ' ');
-            line += std::string(18, ' '); // spare
-            Rinex_Printer::lengthCheck(line);
-            out << line << std::endl;
-            line.clear();
-        }
-}
-
-
-void Rinex_Printer::log_rinex_nav(std::fstream& out, const std::map<int, Gps_Ephemeris>& gps_eph_map, const std::map<int, Galileo_Ephemeris>& galileo_eph_map)
-{
-    version = 3;
-    stringVersion = "3.02";
-    Rinex_Printer::log_rinex_nav(out, gps_eph_map);
-    Rinex_Printer::log_rinex_nav(out, galileo_eph_map);
-}
-
-void Rinex_Printer::update_obs_header(std::fstream& out, const Gps_Utc_Model& utc_model)
-{
-    std::vector<std::string> data;
-    std::string line_aux;
-
-    out.seekp(0);
-    data.clear();
-
-    bool no_more_finds = false;
-    std::string line_str;
-
-    while(!out.eof())
-        {
-            std::getline(out, line_str);
-
-            if(!no_more_finds)
-                {
-                    line_aux.clear();
-
-                    if (version == 2)
-                        {
-                            if (line_str.find("TIME OF FIRST OBS", 59) != std::string::npos) // TIME OF FIRST OBS last header annotation might change in the future
-                                {
-                                    data.push_back(line_str);
-                                    line_aux += Rinex_Printer::rightJustify(boost::lexical_cast<std::string>(utc_model.d_DeltaT_LS), 6);
-                                    line_aux += std::string(54, ' ');
-                                    line_aux += Rinex_Printer::leftJustify("LEAP SECONDS", 20);
-                                    data.push_back(line_aux);
-                                }
-                            else if (line_str.find("END OF HEADER", 59) != std::string::npos)
-                                {
-                                    data.push_back(line_str);
-                                    no_more_finds = true;
-                                }
-                            else
-                                {
-                                    data.push_back(line_str);
-                                }
-                        }
-
-                    if (version == 3)
-                        {
-                            if (line_str.find("TIME OF FIRST OBS", 59) != std::string::npos)
-                                {
-                                    data.push_back(line_str);
-                                    line_aux += Rinex_Printer::rightJustify(boost::lexical_cast<std::string>(utc_model.d_DeltaT_LS), 6);
-                                    line_aux += Rinex_Printer::rightJustify(boost::lexical_cast<std::string>(utc_model.d_DeltaT_LSF), 6);
-                                    line_aux += Rinex_Printer::rightJustify(boost::lexical_cast<std::string>(utc_model.i_WN_LSF), 6);
-                                    line_aux += Rinex_Printer::rightJustify(boost::lexical_cast<std::string>(utc_model.i_DN), 6);
-                                    line_aux += std::string(36, ' ');
-                                    line_aux += Rinex_Printer::leftJustify("LEAP SECONDS", 20);
-                                    data.push_back(line_aux);
-                                }
-                            else if (line_str.find("END OF HEADER", 59) != std::string::npos)
-                                {
-                                    data.push_back(line_str);
-                                    no_more_finds = true;
-                                }
-                            else
-                                {
-                                    data.push_back(line_str);
-                                }
-                        }
-                }
-            else
-                {
-                    data.push_back(line_str);
-                }
-        }
+            if(E1B_HS == "01") LOG(WARNING) << "Signal out of service";
+            E1B_HS = "00";  // *************** CHANGE THIS WHEN GALILEO SIGNAL IS VALID
 
-    out.close();
-    out.open(obsfilename, std::ios::out | std::ios::trunc);
-    out.seekp(0);
-    for (int i = 0; i < (int) data.size() - 1; i++)
-        {
-            out << data[i] << std::endl;
+            std::string E1B_DVS = boost::lexical_cast<std::string>(galileo_ephemeris_iter->second.E1B_DVS_5);
+            if(E1B_DVS == "1") LOG(WARNING) << "Navigation data without guarantee";
+            E1B_DVS = "0"; // *************** CHANGE THIS WHEN GALILEO SIGNAL IS VALID
+
+            std::string SVhealth_str = E5B_HS + boost::lexical_cast<std::string>(galileo_ephemeris_iter->second.E5b_DVS_5)
+                    + "11" + "1" + E1B_DVS +  E1B_HS
+                    + boost::lexical_cast<std::string>(galileo_ephemeris_iter->second.E1B_DVS_5);
+            SVhealth_str = "000000000"; // *************** CHANGE THIS WHEN GALILEO SIGNAL IS VALID
+            int SVhealth = Rinex_Printer::toInt(SVhealth_str, 9);
+            line += Rinex_Printer::doub2for(static_cast<double>(SVhealth), 18, 2);
+            line += std::string(1, ' ');
+            line += Rinex_Printer::doub2for(galileo_ephemeris_iter->second.BGD_E1E5a_5, 18, 2);
+            line += std::string(1, ' ');
+            line += Rinex_Printer::doub2for(galileo_ephemeris_iter->second.BGD_E1E5b_5, 18, 2);
+            Rinex_Printer::lengthCheck(line);
+            out << line << std::endl;
+
+
+            // -------- BROADCAST ORBIT - 7
+            line.clear();
+            line += std::string(5, ' ');
+            line += Rinex_Printer::doub2for(galileo_ephemeris_iter->second.TOW_5, 18, 2);
+            line += std::string(1, ' ');
+            line += Rinex_Printer::doub2for(zero, 18, 2);
+            line += std::string(1, ' ');
+            line += std::string(18, ' '); // spare
+            line += std::string(1, ' ');
+            line += std::string(18, ' '); // spare
+            Rinex_Printer::lengthCheck(line);
+            out << line << std::endl;
+            line.clear();
         }
-    out.close();
-    out.open(obsfilename, std::ios::out | std::ios::in | std::ios::app);
-    out.seekp(0, std::ios_base::end);
+}
+
+
+void Rinex_Printer::log_rinex_nav(std::fstream& out, const std::map<int, Gps_Ephemeris>& gps_eph_map, const std::map<int, Galileo_Ephemeris>& galileo_eph_map)
+{
+    version = 3;
+    stringVersion = "3.02";
+    Rinex_Printer::log_rinex_nav(out, gps_eph_map);
+    Rinex_Printer::log_rinex_nav(out, galileo_eph_map);
 }
 
 
@@ -2678,19 +2593,19 @@ void Rinex_Printer::rinex_obs_header(std::fstream & out, const Gps_CNAV_Ephemeri
     strm << numberTypesObservations;
     line += Rinex_Printer::rightJustify(strm.str(), 3);
     // per type of observation
-    // GPS L1 PSEUDORANGE
+    // GPS L2 PSEUDORANGE
     line += std::string(1, ' ');
     line += observationType["PSEUDORANGE"];
     line += observationCode["GPS_L2_L2CM"];
-    // GPS L1 PHASE
+    // GPS L2 PHASE
     line += std::string(1, ' ');
     line += observationType["CARRIER_PHASE"];
     line += observationCode["GPS_L2_L2CM"];
-    // GPS DOPPLER L1
+    // GPS DOPPLER L2
     line += std::string(1, ' ');
     line += observationType["DOPPLER"];
     line += observationCode["GPS_L2_L2CM"];
-    // GPS L1 CA SIGNAL STRENGTH
+    // GPS L2 SIGNAL STRENGTH
     line += std::string(1, ' ');
     line += observationType["SIGNAL_STRENGTH"];
     line += observationCode["GPS_L2_L2CM"];
@@ -2743,63 +2658,229 @@ void Rinex_Printer::rinex_obs_header(std::fstream & out, const Gps_CNAV_Ephemeri
 }
 
 
-void Rinex_Printer::update_obs_header(std::fstream& out, const Galileo_Utc_Model& galileo_utc_model)
+void Rinex_Printer::rinex_obs_header(std::fstream & out, const Gps_Ephemeris & eph, const Gps_CNAV_Ephemeris & eph_cnav, const double d_TOW_first_observation)
 {
-    std::vector<std::string> data;
-    std::string line_aux;
+    std::string line;
 
-    out.seekp(0);
-    data.clear();
+    // -------- Line 1
+    line = std::string(5, ' ');
+    line += stringVersion;
+    line += std::string(11, ' ');
+    line += Rinex_Printer::leftJustify("OBSERVATION DATA", 20);
+    line += satelliteSystem["GPS"];
+    line += std::string(19, ' ');
+    line += std::string("RINEX VERSION / TYPE");
+    Rinex_Printer::lengthCheck(line);
+    out << line << std::endl;
 
-    bool no_more_finds = false;
-    std::string line_str;
+    // -------- Line 2
+    line.clear();
+    line += Rinex_Printer::leftJustify("G = GPS  R = GLONASS  E = GALILEO  S = GEO  M = MIXED", 60);
+    line += Rinex_Printer::leftJustify("COMMENT", 20);
+    Rinex_Printer::lengthCheck(line);
+    out << line << std::endl;
 
-    while(!out.eof())
+    // -------- Line 3
+    line.clear();
+    line += Rinex_Printer::getLocalTime();
+    line += std::string("PGM / RUN BY / DATE");
+    line += std::string(1, ' ');
+    Rinex_Printer::lengthCheck(line);
+    out << line << std::endl;
+
+    // -------- Line COMMENT
+    line.clear();
+    line += Rinex_Printer::leftJustify("GPS OBSERVATION DATA FILE GENERATED BY GNSS-SDR", 60);
+    line += Rinex_Printer::leftJustify("COMMENT", 20);
+    Rinex_Printer::lengthCheck(line);
+    out << line << std::endl;
+
+    // -------- Line COMMENT
+    line.clear();
+    std::string gnss_sdr_version(GNSS_SDR_VERSION);
+    line += "GNSS-SDR VERSION ";
+    line += Rinex_Printer::leftJustify(gnss_sdr_version, 43);
+    line += Rinex_Printer::leftJustify("COMMENT", 20);
+    Rinex_Printer::lengthCheck(line);
+    out << line << std::endl;
+
+    // -------- Line COMMENT
+    line.clear();
+    line += Rinex_Printer::leftJustify("See http://gnss-sdr.org", 60);
+    line += Rinex_Printer::leftJustify("COMMENT", 20);
+    Rinex_Printer::lengthCheck(line);
+    out << line << std::endl;
+
+    // -------- Line MARKER NAME
+    line.clear();
+    line += Rinex_Printer::leftJustify("DEFAULT MARKER NAME", 60); // put a flag or a property,
+    line += Rinex_Printer::leftJustify("MARKER NAME", 20);
+    Rinex_Printer::lengthCheck(line);
+    out << line << std::endl;
+
+    // -------- Line MARKER TYPE
+    //line.clear();
+    //line += Rinex_Printer::leftJustify("GROUND_CRAFT", 20); // put a flag or a property
+    //line += std::string(40, ' ');
+    //line += Rinex_Printer::leftJustify("MARKER TYPE", 20);
+    //Rinex_Printer::lengthCheck(line);
+    //out << line << std::endl;
+
+    // -------- Line OBSERVER / AGENCY
+    line.clear();
+    std::string username;
+    char c_username[20] = {0};
+    int nGet = getlogin_r(c_username, sizeof(c_username) - 1);
+    if (nGet == 0)
         {
-            std::getline(out, line_str);
+            username = c_username;
+        }
+    else
+        {
+            username = "UNKNOWN USER";
+        }
+    line += leftJustify(username, 20);
+    line += Rinex_Printer::leftJustify("CTTC", 40); // add flag and property
+    line += Rinex_Printer::leftJustify("OBSERVER / AGENCY", 20);
+    Rinex_Printer::lengthCheck(line);
+    out << line << std::endl;
 
-            if(!no_more_finds)
-                {
-                    line_aux.clear();
+    // -------- Line  REC / TYPE VERS
+    line.clear();
+    line += Rinex_Printer::leftJustify("GNSS-SDR", 20); // add flag and property
+    line += Rinex_Printer::leftJustify("Software Receiver", 20); // add flag and property
+    //line += Rinex_Printer::leftJustify(google::VersionString(), 20); // add flag and property
+    if(gnss_sdr_version.length() > 20) gnss_sdr_version.resize(9, ' ');
+    line += Rinex_Printer::leftJustify(gnss_sdr_version, 20);
+    line += Rinex_Printer::leftJustify("REC # / TYPE / VERS", 20);
+    lengthCheck(line);
+    out << line << std::endl;
 
-                    if (line_str.find("TIME OF FIRST OBS", 59) != std::string::npos)
-                        {
-                            data.push_back(line_str);
-                            line_aux += Rinex_Printer::rightJustify(boost::lexical_cast<std::string>(galileo_utc_model.Delta_tLS_6), 6);
-                            line_aux += Rinex_Printer::rightJustify(boost::lexical_cast<std::string>(galileo_utc_model.Delta_tLSF_6), 6);
-                            line_aux += Rinex_Printer::rightJustify(boost::lexical_cast<std::string>(galileo_utc_model.WN_LSF_6), 6);
-                            line_aux += Rinex_Printer::rightJustify(boost::lexical_cast<std::string>(galileo_utc_model.DN_6), 6);
-                            line_aux += std::string(36, ' ');
-                            line_aux += Rinex_Printer::leftJustify("LEAP SECONDS", 20);
-                            data.push_back(line_aux);
-                        }
-                    else if (line_str.find("END OF HEADER", 59) != std::string::npos)
-                        {
-                            data.push_back(line_str);
-                            no_more_finds = true;
-                        }
-                    else
-                        {
-                            data.push_back(line_str);
-                        }
+    // -------- ANTENNA TYPE
+    line.clear();
+    line += Rinex_Printer::leftJustify("Antenna number", 20);  // add flag and property
+    line += Rinex_Printer::leftJustify("Antenna type", 20);  // add flag and property
+    line += std::string(20, ' ');
+    line += Rinex_Printer::leftJustify("ANT # / TYPE", 20);
+    Rinex_Printer::lengthCheck(line);
+    out << line << std::endl;
+
+    // -------- APPROX POSITION  (optional for moving platforms)
+    // put here real data!
+    double antena_x = 0.0;
+    double antena_y = 0.0;
+    double antena_z = 0.0;
+    line.clear();
+    line += Rinex_Printer::rightJustify(Rinex_Printer::asString(antena_x, 4), 14);
+    line += Rinex_Printer::rightJustify(Rinex_Printer::asString(antena_y, 4), 14);
+    line += Rinex_Printer::rightJustify(Rinex_Printer::asString(antena_z, 4), 14);
+    line += std::string(18, ' ');
+    line += Rinex_Printer::leftJustify("APPROX POSITION XYZ", 20);
+    Rinex_Printer::lengthCheck(line);
+    out << line << std::endl;
+
+    // -------- ANTENNA: DELTA H/E/N
+    // put here real data!
+    double antena_h = 0.0;
+    double antena_e = 0.0;
+    double antena_n = 0.0;
+    line.clear();
+    line += Rinex_Printer::rightJustify(Rinex_Printer::asString(antena_h, 4), 14);
+    line += Rinex_Printer::rightJustify(Rinex_Printer::asString(antena_e, 4), 14);
+    line += Rinex_Printer::rightJustify(Rinex_Printer::asString(antena_n, 4), 14);
+    line += std::string(18, ' ');
+    line += Rinex_Printer::leftJustify("ANTENNA: DELTA H/E/N", 20);
+    Rinex_Printer::lengthCheck(line);
+    out << line << std::endl;
+
+    // -------- SYS / OBS TYPES
+    // one line per available system
+    line.clear();
+    line += satelliteSystem["GPS"];
+    line += std::string(2, ' ');
+    std::stringstream strm;
+    numberTypesObservations = 8;
+    strm << numberTypesObservations;
+    line += Rinex_Printer::rightJustify(strm.str(), 3);
+    // per type of observation
+    // GPS L1 PSEUDORANGE
+    line += std::string(1, ' ');
+    line += observationType["PSEUDORANGE"];
+    line += observationCode["GPS_L1_CA"];
+    // GPS L1 PHASE
+    line += std::string(1, ' ');
+    line += observationType["CARRIER_PHASE"];
+    line += observationCode["GPS_L1_CA"];
+    // GPS DOPPLER L1
+    line += std::string(1, ' ');
+    line += observationType["DOPPLER"];
+    line += observationCode["GPS_L1_CA"];
+    // GPS L1 CA SIGNAL STRENGTH
+    line += std::string(1, ' ');
+    line += observationType["SIGNAL_STRENGTH"];
+    line += observationCode["GPS_L1_CA"];
+    // GPS L2 PSEUDORANGE
+    line += std::string(1, ' ');
+    line += observationType["PSEUDORANGE"];
+    line += observationCode["GPS_L2_L2CM"];
+    // GPS L2 PHASE
+    line += std::string(1, ' ');
+    line += observationType["CARRIER_PHASE"];
+    line += observationCode["GPS_L2_L2CM"];
+    // GPS DOPPLER L2
+    line += std::string(1, ' ');
+    line += observationType["DOPPLER"];
+    line += observationCode["GPS_L2_L2CM"];
+    // GPS L2 SIGNAL STRENGTH
+    line += std::string(1, ' ');
+    line += observationType["SIGNAL_STRENGTH"];
+    line += observationCode["GPS_L2_L2CM"];
+
+    line += std::string(60-line.size(), ' ');
+    line += Rinex_Printer::leftJustify("SYS / # / OBS TYPES", 20);
+    Rinex_Printer::lengthCheck(line);
+    out << line << std::endl;
 
-                }
-            else
-                {
-                    data.push_back(line_str);
-                }
-        }
+    // -------- Signal Strength units
+    line.clear();
+    line += Rinex_Printer::leftJustify("DBHZ", 20);
+    line += std::string(40, ' ');
+    line += Rinex_Printer::leftJustify("SIGNAL STRENGTH UNIT", 20);
+    Rinex_Printer::lengthCheck(line);
+    out << line << std::endl;
 
-    out.close();
-    out.open(obsfilename, std::ios::out | std::ios::trunc);
-    out.seekp(0);
-    for (int i = 0; i < (int) data.size() - 1; i++)
-        {
-            out << data[i] << std::endl;
-        }
-    out.close();
-    out.open(obsfilename, std::ios::out | std::ios::in |std::ios::app);
-    out.seekp(0, std::ios_base::end);
+
+    // -------- TIME OF FIRST OBS
+    line.clear();
+    boost::posix_time::ptime p_gps_time = Rinex_Printer::compute_GPS_time(eph,d_TOW_first_observation);
+    std::string timestring = boost::posix_time::to_iso_string(p_gps_time);
+    std::string year (timestring, 0, 4);
+    std::string month (timestring, 4, 2);
+    std::string day (timestring, 6, 2);
+    std::string hour (timestring, 9, 2);
+    std::string minutes (timestring, 11, 2);
+    double gps_t = d_TOW_first_observation;
+    double seconds = fmod(gps_t, 60);
+    line += Rinex_Printer::rightJustify(year, 6);
+    line += Rinex_Printer::rightJustify(month, 6);
+    line += Rinex_Printer::rightJustify(day, 6);
+    line += Rinex_Printer::rightJustify(hour, 6);
+    line += Rinex_Printer::rightJustify(minutes, 6);
+    line += Rinex_Printer::rightJustify(asString(seconds, 7), 13);
+    line += Rinex_Printer::rightJustify(std::string("GPS"), 8);
+    line += std::string(9, ' ');
+    line += Rinex_Printer::leftJustify("TIME OF FIRST OBS", 20);
+    Rinex_Printer::lengthCheck(line);
+    out << line << std::endl;
+
+    // -------- SYS /PHASE SHIFTS
+
+    // -------- end of header
+    line.clear();
+    line += std::string(60, ' ');
+    line += Rinex_Printer::leftJustify("END OF HEADER", 20);
+    Rinex_Printer::lengthCheck(line);
+    out << line << std::endl;
 }
 
 
@@ -3173,65 +3254,267 @@ void Rinex_Printer::rinex_obs_header(std::fstream& out, const Gps_Ephemeris& gps
     Rinex_Printer::lengthCheck(line);
     out << line << std::endl;
 
-    line.clear();
-    line += satelliteSystem["Galileo"];
-    line += std::string(2, ' ');
-    line += Rinex_Printer::rightJustify("4", 3);
-    line += std::string(1, ' ');
-    line += observationType["PSEUDORANGE"];
-    line += observationCode["GALILEO_E1_B"];
-    line += std::string(1, ' ');
-    line += observationType["CARRIER_PHASE"];
-    line += observationCode["GALILEO_E1_B"];
-    line += std::string(1, ' ');
-    line += observationType["DOPPLER"];
-    line += observationCode["GALILEO_E1_B"];
-    line += std::string(1, ' ');
-    line += observationType["SIGNAL_STRENGTH"];
-    line += observationCode["GALILEO_E1_B"];
-    line += std::string(60-line.size(), ' ');
-    line += Rinex_Printer::leftJustify("SYS / # / OBS TYPES", 20);
-    Rinex_Printer::lengthCheck(line);
-    out << line << std::endl;
+    line.clear();
+    line += satelliteSystem["Galileo"];
+    line += std::string(2, ' ');
+    line += Rinex_Printer::rightJustify("4", 3);
+    line += std::string(1, ' ');
+    line += observationType["PSEUDORANGE"];
+    line += observationCode["GALILEO_E1_B"];
+    line += std::string(1, ' ');
+    line += observationType["CARRIER_PHASE"];
+    line += observationCode["GALILEO_E1_B"];
+    line += std::string(1, ' ');
+    line += observationType["DOPPLER"];
+    line += observationCode["GALILEO_E1_B"];
+    line += std::string(1, ' ');
+    line += observationType["SIGNAL_STRENGTH"];
+    line += observationCode["GALILEO_E1_B"];
+    line += std::string(60-line.size(), ' ');
+    line += Rinex_Printer::leftJustify("SYS / # / OBS TYPES", 20);
+    Rinex_Printer::lengthCheck(line);
+    out << line << std::endl;
+
+
+    // -------- Signal Strength units
+    line.clear();
+    line += Rinex_Printer::leftJustify("DBHZ", 20);
+    line += std::string(40, ' ');
+    line += Rinex_Printer::leftJustify("SIGNAL STRENGTH UNIT", 20);
+    Rinex_Printer::lengthCheck(line);
+    out << line << std::endl;
+
+    // -------- TIME OF FIRST OBS
+    line.clear();
+    boost::posix_time::ptime p_gps_time = Rinex_Printer::compute_GPS_time(gps_eph, d_TOW_first_observation);
+    std::string timestring=boost::posix_time::to_iso_string(p_gps_time);
+    std::string year (timestring, 0, 4);
+    std::string month (timestring, 4, 2);
+    std::string day (timestring, 6, 2);
+    std::string hour (timestring, 9, 2);
+    std::string minutes (timestring, 11, 2);
+    double gps_t = d_TOW_first_observation;
+    double seconds = fmod(gps_t, 60);
+    line += Rinex_Printer::rightJustify(year, 6);
+    line += Rinex_Printer::rightJustify(month, 6);
+    line += Rinex_Printer::rightJustify(day, 6);
+    line += Rinex_Printer::rightJustify(hour, 6);
+    line += Rinex_Printer::rightJustify(minutes, 6);
+    line += Rinex_Printer::rightJustify(asString(seconds, 7), 13);
+    line += Rinex_Printer::rightJustify(std::string("GPS"), 8);
+    line += std::string(9, ' ');
+    line += Rinex_Printer::leftJustify("TIME OF FIRST OBS", 20);
+    Rinex_Printer::lengthCheck(line);
+    out << line << std::endl;
+
+    // -------- end of header
+    line.clear();
+    line += std::string(60, ' ');
+    line += Rinex_Printer::leftJustify("END OF HEADER", 20);
+    Rinex_Printer::lengthCheck(line);
+    out << line << std::endl;
+}
+
+
+void Rinex_Printer::update_obs_header(std::fstream& out, const Gps_Utc_Model& utc_model)
+{
+    std::vector<std::string> data;
+    std::string line_aux;
+
+    out.seekp(0);
+    data.clear();
+
+    bool no_more_finds = false;
+    std::string line_str;
+
+    while(!out.eof())
+        {
+            std::getline(out, line_str);
+
+            if(!no_more_finds)
+                {
+                    line_aux.clear();
+
+                    if (version == 2)
+                        {
+                            if (line_str.find("TIME OF FIRST OBS", 59) != std::string::npos) // TIME OF FIRST OBS last header annotation might change in the future
+                                {
+                                    data.push_back(line_str);
+                                    line_aux += Rinex_Printer::rightJustify(boost::lexical_cast<std::string>(utc_model.d_DeltaT_LS), 6);
+                                    line_aux += std::string(54, ' ');
+                                    line_aux += Rinex_Printer::leftJustify("LEAP SECONDS", 20);
+                                    data.push_back(line_aux);
+                                }
+                            else if (line_str.find("END OF HEADER", 59) != std::string::npos)
+                                {
+                                    data.push_back(line_str);
+                                    no_more_finds = true;
+                                }
+                            else
+                                {
+                                    data.push_back(line_str);
+                                }
+                        }
+
+                    if (version == 3)
+                        {
+                            if (line_str.find("TIME OF FIRST OBS", 59) != std::string::npos)
+                                {
+                                    data.push_back(line_str);
+                                    line_aux += Rinex_Printer::rightJustify(boost::lexical_cast<std::string>(utc_model.d_DeltaT_LS), 6);
+                                    line_aux += Rinex_Printer::rightJustify(boost::lexical_cast<std::string>(utc_model.d_DeltaT_LSF), 6);
+                                    line_aux += Rinex_Printer::rightJustify(boost::lexical_cast<std::string>(utc_model.i_WN_LSF), 6);
+                                    line_aux += Rinex_Printer::rightJustify(boost::lexical_cast<std::string>(utc_model.i_DN), 6);
+                                    line_aux += std::string(36, ' ');
+                                    line_aux += Rinex_Printer::leftJustify("LEAP SECONDS", 20);
+                                    data.push_back(line_aux);
+                                }
+                            else if (line_str.find("END OF HEADER", 59) != std::string::npos)
+                                {
+                                    data.push_back(line_str);
+                                    no_more_finds = true;
+                                }
+                            else
+                                {
+                                    data.push_back(line_str);
+                                }
+                        }
+                }
+            else
+                {
+                    data.push_back(line_str);
+                }
+        }
+
+    out.close();
+    out.open(obsfilename, std::ios::out | std::ios::trunc);
+    out.seekp(0);
+    for (int i = 0; i < (int) data.size() - 1; i++)
+        {
+            out << data[i] << std::endl;
+        }
+    out.close();
+    out.open(obsfilename, std::ios::out | std::ios::in | std::ios::app);
+    out.seekp(0, std::ios_base::end);
+}
+
+
+void Rinex_Printer::update_obs_header(std::fstream& out, const Gps_CNAV_Utc_Model& utc_model)
+{
+    std::vector<std::string> data;
+    std::string line_aux;
+
+    out.seekp(0);
+    data.clear();
+
+    bool no_more_finds = false;
+    std::string line_str;
+
+    while(!out.eof())
+        {
+            std::getline(out, line_str);
+
+            if(!no_more_finds)
+                {
+                    line_aux.clear();
+                    if (line_str.find("TIME OF FIRST OBS", 59) != std::string::npos)
+                        {
+                            data.push_back(line_str);
+                            line_aux += Rinex_Printer::rightJustify(boost::lexical_cast<std::string>(utc_model.d_DeltaT_LS), 6);
+                            line_aux += Rinex_Printer::rightJustify(boost::lexical_cast<std::string>(utc_model.d_DeltaT_LSF), 6);
+                            line_aux += Rinex_Printer::rightJustify(boost::lexical_cast<std::string>(utc_model.i_WN_LSF), 6);
+                            line_aux += Rinex_Printer::rightJustify(boost::lexical_cast<std::string>(utc_model.i_DN), 6);
+                            line_aux += std::string(36, ' ');
+                            line_aux += Rinex_Printer::leftJustify("LEAP SECONDS", 20);
+                            data.push_back(line_aux);
+                        }
+                    else if (line_str.find("END OF HEADER", 59) != std::string::npos)
+                        {
+                            data.push_back(line_str);
+                            no_more_finds = true;
+                        }
+                    else
+                        {
+                            data.push_back(line_str);
+                        }
+
+                }
+            else
+                {
+                    data.push_back(line_str);
+                }
+        }
+
+    out.close();
+    out.open(obsfilename, std::ios::out | std::ios::trunc);
+    out.seekp(0);
+    for (int i = 0; i < (int) data.size() - 1; i++)
+        {
+            out << data[i] << std::endl;
+        }
+    out.close();
+    out.open(obsfilename, std::ios::out | std::ios::in | std::ios::app);
+    out.seekp(0, std::ios_base::end);
+}
+
 
+void Rinex_Printer::update_obs_header(std::fstream& out, const Galileo_Utc_Model& galileo_utc_model)
+{
+    std::vector<std::string> data;
+    std::string line_aux;
 
-    // -------- Signal Strength units
-    line.clear();
-    line += Rinex_Printer::leftJustify("DBHZ", 20);
-    line += std::string(40, ' ');
-    line += Rinex_Printer::leftJustify("SIGNAL STRENGTH UNIT", 20);
-    Rinex_Printer::lengthCheck(line);
-    out << line << std::endl;
+    out.seekp(0);
+    data.clear();
 
-    // -------- TIME OF FIRST OBS
-    line.clear();
-    boost::posix_time::ptime p_gps_time = Rinex_Printer::compute_GPS_time(gps_eph, d_TOW_first_observation);
-    std::string timestring=boost::posix_time::to_iso_string(p_gps_time);
-    std::string year (timestring, 0, 4);
-    std::string month (timestring, 4, 2);
-    std::string day (timestring, 6, 2);
-    std::string hour (timestring, 9, 2);
-    std::string minutes (timestring, 11, 2);
-    double gps_t = d_TOW_first_observation;
-    double seconds = fmod(gps_t, 60);
-    line += Rinex_Printer::rightJustify(year, 6);
-    line += Rinex_Printer::rightJustify(month, 6);
-    line += Rinex_Printer::rightJustify(day, 6);
-    line += Rinex_Printer::rightJustify(hour, 6);
-    line += Rinex_Printer::rightJustify(minutes, 6);
-    line += Rinex_Printer::rightJustify(asString(seconds, 7), 13);
-    line += Rinex_Printer::rightJustify(std::string("GPS"), 8);
-    line += std::string(9, ' ');
-    line += Rinex_Printer::leftJustify("TIME OF FIRST OBS", 20);
-    Rinex_Printer::lengthCheck(line);
-    out << line << std::endl;
+    bool no_more_finds = false;
+    std::string line_str;
 
-    // -------- end of header
-    line.clear();
-    line += std::string(60, ' ');
-    line += Rinex_Printer::leftJustify("END OF HEADER", 20);
-    Rinex_Printer::lengthCheck(line);
-    out << line << std::endl;
+    while(!out.eof())
+        {
+            std::getline(out, line_str);
+
+            if(!no_more_finds)
+                {
+                    line_aux.clear();
+
+                    if (line_str.find("TIME OF FIRST OBS", 59) != std::string::npos)
+                        {
+                            data.push_back(line_str);
+                            line_aux += Rinex_Printer::rightJustify(boost::lexical_cast<std::string>(galileo_utc_model.Delta_tLS_6), 6);
+                            line_aux += Rinex_Printer::rightJustify(boost::lexical_cast<std::string>(galileo_utc_model.Delta_tLSF_6), 6);
+                            line_aux += Rinex_Printer::rightJustify(boost::lexical_cast<std::string>(galileo_utc_model.WN_LSF_6), 6);
+                            line_aux += Rinex_Printer::rightJustify(boost::lexical_cast<std::string>(galileo_utc_model.DN_6), 6);
+                            line_aux += std::string(36, ' ');
+                            line_aux += Rinex_Printer::leftJustify("LEAP SECONDS", 20);
+                            data.push_back(line_aux);
+                        }
+                    else if (line_str.find("END OF HEADER", 59) != std::string::npos)
+                        {
+                            data.push_back(line_str);
+                            no_more_finds = true;
+                        }
+                    else
+                        {
+                            data.push_back(line_str);
+                        }
+
+                }
+            else
+                {
+                    data.push_back(line_str);
+                }
+        }
+
+    out.close();
+    out.open(obsfilename, std::ios::out | std::ios::trunc);
+    out.seekp(0);
+    for (int i = 0; i < (int) data.size() - 1; i++)
+        {
+            out << data[i] << std::endl;
+        }
+    out.close();
+    out.open(obsfilename, std::ios::out | std::ios::in |std::ios::app);
+    out.seekp(0, std::ios_base::end);
 }
 
 
@@ -3478,6 +3761,215 @@ void Rinex_Printer::log_rinex_obs(std::fstream& out, const Gps_Ephemeris& eph, c
 }
 
 
+void  Rinex_Printer::log_rinex_obs(std::fstream & out, const Gps_Ephemeris & eph, const Gps_CNAV_Ephemeris & eph_cnav, double obs_time, const std::map<int, Gnss_Synchro> & pseudoranges)
+{
+    // RINEX observations timestamps are GPS timestamps.
+    std::string line;
+
+    boost::posix_time::ptime p_gps_time = Rinex_Printer::compute_GPS_time(eph, obs_time);
+    std::string timestring = boost::posix_time::to_iso_string(p_gps_time);
+    //double utc_t = nav_msg.utc_time(nav_msg.sv_clock_correction(obs_time));
+    //double gps_t = eph.sv_clock_correction(obs_time);
+    double gps_t = obs_time;
+
+    std::string month (timestring, 4, 2);
+    std::string day (timestring, 6, 2);
+    std::string hour (timestring, 9, 2);
+    std::string minutes (timestring, 11, 2);
+
+    std::string year (timestring, 0, 4);
+    line += std::string(1, '>');
+    line += std::string(1, ' ');
+    line += year;
+    line += std::string(1, ' ');
+    line += month;
+    line += std::string(1, ' ');
+    line += day;
+    line += std::string(1, ' ');
+    line += hour;
+    line += std::string(1, ' ');
+    line += minutes;
+
+    line += std::string(1, ' ');
+    double seconds = fmod(gps_t, 60);
+    // Add extra 0 if seconds are < 10
+    if (seconds < 10)
+        {
+            line += std::string(1, '0');
+        }
+    line += Rinex_Printer::asString(seconds, 7);
+    line += std::string(2, ' ');
+    // Epoch flag 0: OK     1: power failure between previous and current epoch   <1: Special event
+    line += std::string(1, '0');
+
+    //Number of satellites observed in current epoch
+
+    //Get maps with GPS L1 and L2 observations
+    std::map<int, Gnss_Synchro> pseudorangesL1;
+    std::map<int, Gnss_Synchro> pseudorangesL2;
+    std::map<int, Gnss_Synchro>::const_iterator pseudoranges_iter;
+    std::map<int, Gnss_Synchro>::const_iterator pseudoranges_iter2;
+
+    for(pseudoranges_iter = pseudoranges.begin();
+            pseudoranges_iter != pseudoranges.end();
+            pseudoranges_iter++)
+        {
+            std::string system_(&pseudoranges_iter->second.System, 1);
+            std::string sig_(pseudoranges_iter->second.Signal);
+            if((system_.compare("G") == 0) && (sig_.compare("1C") == 0))
+                {
+                    pseudorangesL1.insert(std::pair<int, Gnss_Synchro>(pseudoranges_iter->first, pseudoranges_iter->second));
+                }
+            if((system_.compare("G") == 0) && (sig_.compare("2S") == 0))
+                {
+                    pseudorangesL2.insert(std::pair<int, Gnss_Synchro>(pseudoranges_iter->first, pseudoranges_iter->second));
+                }
+        }
+
+    // Get common observables
+    std::vector< std::pair< Gnss_Synchro, Gnss_Synchro > >  common_pseudoranges;
+    std::vector< std::pair< Gnss_Synchro, Gnss_Synchro > >::const_iterator common_pseudoranges_iter;
+    std::map<int, Gnss_Synchro> pseudorangesL1_with_L2;
+
+    for(pseudoranges_iter = pseudorangesL1.begin();
+            pseudoranges_iter != pseudorangesL1.end();
+            pseudoranges_iter++)
+        {
+            unsigned int prn_ = pseudoranges_iter->second.PRN;
+            for(pseudoranges_iter2 = pseudorangesL2.begin();
+                    pseudoranges_iter2 != pseudorangesL2.end();
+                    pseudoranges_iter2++)
+                {
+                    if(pseudoranges_iter2->second.PRN == prn_)
+                        {
+                            std::pair<Gnss_Synchro, Gnss_Synchro> p;
+                            Gnss_Synchro pr1 = pseudoranges_iter->second;
+                            Gnss_Synchro pr2 = pseudoranges_iter2->second;
+                            p = std::make_pair(pr1, pr2);
+                            common_pseudoranges.push_back(p);
+                            pseudorangesL1_with_L2.insert(std::pair<int, Gnss_Synchro>(pseudoranges_iter->first, pseudoranges_iter->second));
+                        }
+                }
+        }
+
+    int numSatellitesObserved = common_pseudoranges.size();
+    line += Rinex_Printer::rightJustify(boost::lexical_cast<std::string>(numSatellitesObserved), 3);
+
+    // Receiver clock offset (optional)
+    //line += rightJustify(asString(clockOffset, 12), 15);
+
+    line += std::string(80 - line.size(), ' ');
+    Rinex_Printer::lengthCheck(line);
+    out << line << std::endl;
+
+    for(common_pseudoranges_iter = common_pseudoranges.begin();
+            common_pseudoranges_iter != common_pseudoranges.end();
+            common_pseudoranges_iter++)
+        {
+            std::string lineObs;
+            lineObs.clear();
+            lineObs += satelliteSystem["GPS"];
+            if (static_cast<int>(std::get<0>(*common_pseudoranges_iter).PRN) < 10) lineObs += std::string(1, '0');
+            lineObs += boost::lexical_cast<std::string>(static_cast<int>(std::get<0>(*common_pseudoranges_iter).PRN));
+            //lineObs += std::string(2, ' ');
+            // GPS L1 CA PSEUDORANGE
+            lineObs += Rinex_Printer::rightJustify(asString(std::get<0>(*common_pseudoranges_iter).Pseudorange_m, 3), 14);
+
+            //Loss of lock indicator (LLI)
+            int lli = 0; // Include in the observation!!
+            if (lli == 0)
+                {
+                    lineObs += std::string(1, ' ');
+                }
+            else
+                {
+                    lineObs += Rinex_Printer::rightJustify(Rinex_Printer::asString<short>(lli), 1);
+                }
+
+            // Signal Strength Indicator (SSI)
+            int ssi = Rinex_Printer::signalStrength(std::get<0>(*common_pseudoranges_iter).CN0_dB_hz);
+            lineObs += Rinex_Printer::rightJustify(Rinex_Printer::asString<int>(ssi), 1);
+
+            // GPS L1 CA PHASE
+            lineObs += Rinex_Printer::rightJustify(asString(std::get<0>(*common_pseudoranges_iter).Carrier_phase_rads / GPS_TWO_PI, 3), 14);
+            if (lli == 0)
+                {
+                    lineObs += std::string(1, ' ');
+                }
+            else
+                {
+                    lineObs += Rinex_Printer::rightJustify(Rinex_Printer::asString<short>(lli), 1);
+                }
+            lineObs += Rinex_Printer::rightJustify(Rinex_Printer::asString<int>(ssi), 1);
+
+            // GPS L1 CA DOPPLER
+            lineObs += Rinex_Printer::rightJustify(asString(std::get<0>(*common_pseudoranges_iter).Carrier_Doppler_hz, 3), 14);
+            if (lli == 0)
+                {
+                    lineObs += std::string(1, ' ');
+                }
+            else
+                {
+                    lineObs += Rinex_Printer::rightJustify(Rinex_Printer::asString<short>(lli), 1);
+                }
+
+            lineObs += Rinex_Printer::rightJustify(Rinex_Printer::asString<int>(ssi), 1);
+
+            //GPS L1 SIGNAL STRENGTH
+            lineObs += Rinex_Printer::rightJustify(asString(std::get<0>(*common_pseudoranges_iter).CN0_dB_hz, 3), 14);
+
+            // GPS L2 PSEUDORANGE
+            lineObs += Rinex_Printer::rightJustify(asString(std::get<1>(*common_pseudoranges_iter).Pseudorange_m, 3), 14);
+
+            //Loss of lock indicator (LLI)
+            int lli_2 = 0; // Include in the observation!!
+            if (lli_2 == 0)
+                {
+                    lineObs += std::string(1, ' ');
+                }
+            else
+                {
+                    lineObs += Rinex_Printer::rightJustify(Rinex_Printer::asString<short>(lli_2), 1);
+                }
+
+            // Signal Strength Indicator (SSI)
+            int ssi_2 = Rinex_Printer::signalStrength(std::get<1>(*common_pseudoranges_iter).CN0_dB_hz);
+            lineObs += Rinex_Printer::rightJustify(Rinex_Printer::asString<int>(ssi_2), 1);
+
+            // GPS L2 PHASE
+            lineObs += Rinex_Printer::rightJustify(asString(std::get<0>(*common_pseudoranges_iter).Carrier_phase_rads / GPS_TWO_PI, 3), 14);
+            if (lli_2 == 0)
+                {
+                    lineObs += std::string(1, ' ');
+                }
+            else
+                {
+                    lineObs += Rinex_Printer::rightJustify(Rinex_Printer::asString<short>(lli_2), 1);
+                }
+            lineObs += Rinex_Printer::rightJustify(Rinex_Printer::asString<int>(ssi_2), 1);
+
+            // GPS L2 DOPPLER
+            lineObs += Rinex_Printer::rightJustify(asString(std::get<1>(*common_pseudoranges_iter).Carrier_Doppler_hz, 3), 14);
+            if (lli_2 == 0)
+                {
+                    lineObs += std::string(1, ' ');
+                }
+            else
+                {
+                    lineObs += Rinex_Printer::rightJustify(Rinex_Printer::asString<short>(lli_2), 1);
+                }
+
+            lineObs += Rinex_Printer::rightJustify(Rinex_Printer::asString<int>(ssi_2), 1);
+
+            //GPS L2 SIGNAL STRENGTH
+            lineObs += Rinex_Printer::rightJustify(asString(std::get<1>(*common_pseudoranges_iter).CN0_dB_hz, 3), 14);
+
+            if (lineObs.size() < 80) lineObs += std::string(80 - lineObs.size(), ' ');
+            out << lineObs << std::endl;
+        }
+}
+
+
 void Rinex_Printer::log_rinex_obs(std::fstream& out, const Galileo_Ephemeris& eph, double obs_time, const std::map<int,Gnss_Synchro>& pseudoranges)
 {
     // RINEX observations timestamps are Galileo timestamps.
diff --git a/src/algorithms/PVT/libs/rinex_printer.h b/src/algorithms/PVT/libs/rinex_printer.h
index cafd713..8ed3e47 100644
--- a/src/algorithms/PVT/libs/rinex_printer.h
+++ b/src/algorithms/PVT/libs/rinex_printer.h
@@ -121,6 +121,10 @@ public:
      */
     void rinex_obs_header(std::fstream & out, const Gps_CNAV_Ephemeris & eph, const double d_TOW_first_observation);
 
+    /*!
+     *  \brief Generates the dual frequency GPS L1 & L2 Observation data header
+     */
+    void rinex_obs_header(std::fstream & out, const Gps_Ephemeris & eph, const Gps_CNAV_Ephemeris & eph_cnav, const double d_TOW_first_observation);
 
     /*!
      *  \brief Generates the Galileo Observation data header
@@ -167,7 +171,6 @@ public:
      */
     void log_rinex_nav(std::fstream & out, const std::map<int, Gps_CNAV_Ephemeris> & eph_map);
 
-
     /*!
      *  \brief Writes data from the Galileo navigation message into the RINEX file
      */
@@ -184,12 +187,17 @@ public:
     void log_rinex_obs(std::fstream & out, const Gps_Ephemeris & eph, double obs_time, const std::map<int, Gnss_Synchro> & pseudoranges);
 
     /*!
+     *  \brief Writes dual frequency GPS L1 and L2 observables into the RINEX file
+     */
+    void log_rinex_obs(std::fstream & out, const Gps_Ephemeris & eph, const Gps_CNAV_Ephemeris & eph_cnav, double obs_time, const std::map<int, Gnss_Synchro> & pseudoranges);
+
+    /*!
      *  \brief Writes Galileo observables into the RINEX file
      */
     void log_rinex_obs(std::fstream & out, const Galileo_Ephemeris & eph, double obs_time, const std::map<int, Gnss_Synchro> & pseudoranges);
 
     /*!
-     *  \brief Writes Galileo observables into the RINEX file
+     *  \brief Writes Mixed GPS / Galileo observables into the RINEX file
      */
     void log_rinex_obs(std::fstream & out, const Gps_Ephemeris & gps_eph, const Galileo_Ephemeris & galileo_eph, const double gps_obs_time, const std::map<int, Gnss_Synchro> & pseudoranges);
 
@@ -213,6 +221,8 @@ public:
 
     void update_obs_header(std::fstream & out, const Gps_Utc_Model & utc_model);
 
+    void update_obs_header(std::fstream & out, const Gps_CNAV_Utc_Model & utc_model);
+
     void update_obs_header(std::fstream & out, const Galileo_Utc_Model & galileo_utc_model);
 
     std::map<std::string,std::string> satelliteSystem; //<! GPS, GLONASS, SBAS payload, Galileo or Compass

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-hamradio/gnss-sdr.git



More information about the pkg-hamradio-commits mailing list