/*!
* \file rinex_printer.h
* \brief Interface of a RINEX 2.11 / 3.01 printer
* See http://igscb.jpl.nasa.gov/igscb/data/format/rinex301.pdf
*
* Receiver Independent EXchange Format (RINEX):
* The first proposal for the Receiver Independent Exchange Format RINEX
* was developed by the Astronomical Institute of the University of Berne
* for the easy exchange of the GPS data to be collected during the large
* European GPS campaign EUREF 89, which involved more than 60 GPS receivers
* of 4 different manufacturers.
* The governing aspect during the development was the fact that most geodetic
* processing software for GPS data use a well-defined set of observables:
* 1) The carrier-phase measurement at one or both carriers (actually being a
* measurement on the beat frequency between the received carrier of the
* satellite signal and a receiver-generated reference frequency).
* 2) The pseudorange (code) measuremen , equivalent to the difference
* of the time of reception (expressed in the time frame of the receiver)
* and the time of transmission (expressed in the time frame of the satellite)
* of a distinct satellite signal.
* 3) The observation time being the reading of the receiver clock at the
* instant of validity of the carrier-phase and/or the code measurements.
* Note: A collection of the formats currently used by the IGS can be found
* here: http://igscb.jpl.nasa.gov/components/formats.html
* \author Carles Fernandez Prades, 2011. cfernandez(at)cttc.es
* -------------------------------------------------------------------------
*
* Copyright (C) 2010-2012 (see AUTHORS file for a list of contributors)
*
* GNSS-SDR is a software defined Global Navigation
* Satellite Systems receiver
*
* This file is part of GNSS-SDR.
*
* GNSS-SDR is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* at your option) any later version.
*
* GNSS-SDR is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNSS-SDR. If not, see .
*
* -------------------------------------------------------------------------
*/
#ifndef GNSS_SDR_RINEX_PRINTER_H_
#define GNSS_SDR_RINEX_PRINTER_H_
#include
#include
#include
#include // for stringstream
#include // for setprecision
#include "gps_navigation_message.h"
#include "boost/date_time/posix_time/posix_time.hpp"
#include "GPS_L1_CA.h"
/*!
* \brief Class that handles the generation of Receiver
* INdependent EXchange format (RINEX) files
*/
class Rinex_Printer
{
public:
/*!
* \brief Default constructor. Creates GPS Navigation and Observables RINEX files and their headers
*/
Rinex_Printer();
/*!
* \brief Default destructor. Closes GPS Navigation and Observables RINEX files
*/
~Rinex_Printer();
std::ofstream obsFile ; // nav_msg);
/*!
* \brief Writes observables into the RINEX file
*/
void log_rinex_obs(std::ofstream& out, Gps_Navigation_Message nav_msg, std::map pseudoranges);
std::map satelliteSystem; // observationType; // observationCode; // 0.87654E-0004 or -0.1234E00005.
*/
inline std::string& sci2for(std::string& aStr,
const std::string::size_type startPos = 0,
const std::string::size_type length = std::string::npos,
const std::string::size_type expLen = 3,
const bool checkSwitch = true);
/*
* Convert double precision floating point to a string
* containing the number in FORTRAN notation.
* As an example, the number 156360 becomes ".15636D6".
* @param d number to convert.
* @param length length (in characters) of number, including exponent.
* @param expLen length (in characters of exponent, including sign.
* @param checkSwitch if true, keeps the exponential sanity check for
* exponentials above three characters in length. If false, it removes
* that check.
* @return a string containing \a d in FORTRAN notation.
*/
inline std::string doub2for(const double& d,
const std::string::size_type length,
const std::string::size_type expLen,
const bool checkSwitch = true);
/*
* Convert a string to a double precision floating point number.
* @param s string containing a number.
* @return double representation of string.
*/
inline double asDouble(const std::string& s)
{ return strtod(s.c_str(), 0); }
/*
* Convert a string to an integer.
* @param s string containing a number.
* @return long integer representation of string.
*/
inline long asInt(const std::string& s)
{ return strtol(s.c_str(), 0, 10); }
/*
* Convert a double to a string in fixed notation.
* @param x double.
* @param precision the number of decimal places you want displayed.
* @return string representation of \a x.
*/
inline std::string asString(const double x,
const std::string::size_type precision = 17);
/*
* Convert a long double to a string in fixed notation.
* @param x long double.
* @param precision the number of decimal places you want displayed.
* @return string representation of \a x.
*/
inline std::string asString(const long double x,
const std::string::size_type precision = 21);
/*
* Convert any old object to a string.
* The class must have stream operators defined.
* @param x object to turn into a string.
* @return string representation of \a x.
*/
template
inline std::string asString(const X x);
};
// Implementation of inline functions (modified versions from GPSTk http://www.gpstk.org)
inline std::string& Rinex_Printer::leftJustify(std::string& s,
const std::string::size_type length,
const char pad)
{
if(length < s.length())
{
s = s.substr(0, length);
}
else
{
s.append(length-s.length(), pad);
}
return s;
}
// if the string is bigger than length, truncate it from the left.
// otherwise, add pad characters to its left.
inline std::string& Rinex_Printer::rightJustify(std::string& s,
const std::string::size_type length,
const char pad)
{
if(length < s.length())
{
s = s.substr(s.length()-length, std::string::npos);
}
else
{
s.insert((std::string::size_type)0, length-s.length(), pad);
}
return s;
}
inline std::string Rinex_Printer::doub2for(const double& d,
const std::string::size_type length,
const std::string::size_type expLen,
const bool checkSwitch)
{
short exponentLength = expLen;
/* Validate the assumptions regarding the input arguments */
if (exponentLength < 0) exponentLength = 1;
if (exponentLength > 3 && checkSwitch) exponentLength = 3;
std::string toReturn = doub2sci(d, length, exponentLength, true, checkSwitch);
sci2for(toReturn, 0, length, exponentLength, checkSwitch);
return toReturn;
}
inline std::string Rinex_Printer::doub2sci(const double& d,
const std::string::size_type length,
const std::string::size_type expLen,
const bool showSign,
const bool checkSwitch)
{
std::string toReturn;
short exponentLength = expLen;
/* Validate the assumptions regarding the input arguments */
if (exponentLength < 0) exponentLength = 1;
if (exponentLength > 3 && checkSwitch) exponentLength = 3;
std::stringstream c;
c.setf(std::ios::scientific, std::ios::floatfield);
// length - 3 for special characters ('.', 'e', '+' or '-')
// - exponentlength (e04)
// - 1 for the digit before the decimal (2.)
// and if showSign == true,
// an extra -1 for '-' or ' ' if it's positive or negative
int expSize = 0;
if (showSign)
expSize = 1;
c.precision(length - 3 - exponentLength - 1 - expSize);
c << d;
c >> toReturn;
return toReturn;
}
inline std::string& Rinex_Printer::sci2for(std::string& aStr,
const std::string::size_type startPos,
const std::string::size_type length,
const std::string::size_type expLen,
const bool checkSwitch)
{
std::string::size_type idx = aStr.find('.', startPos);
int expAdd = 0;
std::string exp;
long iexp;
//If checkSwitch is false, always redo the exponential. Otherwise,
//set it to false.
bool redoexp=!checkSwitch;
// Check for decimal place within specified boundaries
if ((idx == 0) || (idx >= (startPos + length - expLen - 1)))
{
//StringException e("sci2for: no decimal point in string");
}
// Here, account for the possibility that there are
// no numbers to the left of the decimal, but do not
// account for the possibility of non-scientific
// notation (more than one digit to the left of the
// decimal)
if (idx > startPos)
{
redoexp = true;
// Swap digit and decimal.
aStr[idx] = aStr[idx-1];
aStr[idx-1] = '.';
// Only add one to the exponent if the number is non-zero
if (asDouble(aStr.substr(startPos, length)) != 0.0)
expAdd = 1;
}
idx = aStr.find('e', startPos);
if (idx == std::string::npos)
{
idx = aStr.find('E', startPos);
if (idx == std::string::npos)
{
//StringException e("sci2for:no 'e' or 'E' in string");
//GPSTK_THROW(e);
}
}
// Change the exponent character to D normally, or E of checkSwitch is false.
if (checkSwitch)
aStr[idx] = 'D';
else
aStr[idx] = 'E';
// Change the exponent itself
if (redoexp)
{
exp = aStr.substr(idx + 1, std::string::npos);
iexp = asInt(exp);
iexp += expAdd;
aStr.erase(idx + 1);
if (iexp < 0)
{
aStr += "-";
iexp -= iexp*2;
}
else
aStr += "+";
aStr += Rinex_Printer::rightJustify(asString(iexp),expLen,'0');
}
// if the number is positive, append a space
// (if it's negative, there's a leading '-'
if (aStr[0] == '.')
{
aStr.insert((std::string::size_type)0, 1, ' ');
}
//If checkSwitch is false, add on one leading zero to the string
if (!checkSwitch)
{
aStr.insert((std::string::size_type)1, 1, '0');
}
return aStr;
} // end sci2for
inline std::string asString(const long double x, const std::string::size_type precision)
{
std::ostringstream ss;
ss << std::fixed << std::setprecision(precision) << x ;
return ss.str();
}
inline std::string Rinex_Printer::asString(const double x, const std::string::size_type precision)
{
std::ostringstream ss;
ss << std::fixed << std::setprecision(precision) << x;
return ss.str();
}
template
inline std::string Rinex_Printer::asString(const X x)
{
std::ostringstream ss;
ss << x;
return ss.str();
}
#endif