1
0
mirror of https://github.com/gnss-sdr/gnss-sdr synced 2025-09-01 02:17:59 +00:00

Merge branch 'MathieuFavreau-refactor/cleanup-rinex-printer' into next

This commit is contained in:
Carles Fernandez
2025-08-08 20:31:16 +02:00
3 changed files with 2392 additions and 6706 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -170,13 +170,10 @@ public:
private:
const std::unordered_map<std::string, std::string> satelliteSystem = {
{"GPS", "G"},
{"GLONASS", "R"},
{"SBAS payload", "S"},
{"Galileo", "E"},
{"Beidou", "C"},
{"Mixed", "M"}}; // RINEX v3.02 codes
// Not the best, but reorder params to select the correct constructor
explicit Rinex_Printer(const std::string& base_name,
const std::string& base_rinex_path,
int version);
/*
* Generates the GPS Observation data header
@@ -727,211 +724,13 @@ private:
*/
int signalStrength(double snr) const;
/* Creates RINEX file names according to the naming convention
*
* See ftp://igs.org/pub/data/format/rinex301.pdf
* Section 4, page 6
*
* \param[in] type of RINEX file. Can be:
* "RINEX_FILE_TYPE_OBS" - Observation file.
* "RINEX_FILE_TYPE_GPS_NAV" - GPS navigation message file.
* "RINEX_FILE_TYPE_MET" - Meteorological data file.
* "RINEX_FILE_TYPE_GLO_NAV" - GLONASS navigation file.
* "RINEX_FILE_TYPE_GAL_NAV" - Galileo navigation message file.
* "RINEX_FILE_TYPE_MIXED_NAV" - Mixed GNSS navigation message file.
* "RINEX_FILE_TYPE_GEO_NAV" - SBAS Payload navigation message file.
* "RINEX_FILE_TYPE_SBAS" - SBAS broadcast data file.
* "RINEX_FILE_TYPE_CLK" - Clock file.
*/
std::string createFilename(const std::string& type, const std::string& base_name) const;
/*
* Generates the data for the PGM / RUN BY / DATE line
*/
std::string getLocalTime() const;
/*
* Checks that the line is 80 characters length
*/
void lengthCheck(const std::string& line) const;
/*
* If the string is bigger than length, truncate it from the right.
* otherwise, add pad characters to its right.
*
* Left-justifies the input in a string of the specified
* length. If the new length (\a length) is larger than the
* current length, the string is extended by the pad
* character (\a pad). The default pad character is a
* blank.
* \param[in] s string to be modified.
* \param[in] length new desired length of string.
* \param[in] pad character to pad string with (blank by default).
* \return a reference to \a s. */
inline std::string& leftJustify(std::string& s,
std::string::size_type length,
char pad = ' ') const;
/*
* If the string is bigger than length, truncate it from the right.
* otherwise, add pad characters to its right.
*
* Left-justifies the receiver in a string of the specified
* length (const version). If the new length (\a length) is larger
* than the current length, the string is extended by the pad
* character (\a pad). The default pad character is a
* blank.
* \param[in] s string to be modified.
* \param[in] length new desired length of string.
* \param[in] pad character to pad string with (blank by default).
* \return a reference to \a s. */
inline std::string leftJustify(const std::string& s,
std::string::size_type length,
char pad = ' ') const
{
std::string t(s);
return leftJustify(t, length, pad);
}
/*
* Right-justifies the receiver in a string of the specified
* length. If the receiver's data is shorter than the
* requested length (\a length), it is padded on the left with
* the pad character (\a pad). The default pad
* character is a blank. */
inline std::string& rightJustify(std::string& s,
std::string::size_type length,
char pad = ' ') const;
/*
* Right-justifies the receiver in a string of the specified
* length (const version). If the receiver's data is shorter than the
* requested length (\a length), it is padded on the left with
* the pad character (\a pad). The default pad
* character is a blank.*/
inline std::string rightJustify(const std::string& s,
std::string::size_type length,
char pad = ' ') const
{
std::string t(s);
return rightJustify(t, length, pad);
}
/*
* Convert a double to a scientific notation number.
* @param d the double to convert
* @param length length (in characters) of output, including exponent
* @param expLen length (in characters) of the exponent, with sign
* @param showSign if true, reserves 1 character for +/- sign
* @param checkSwitch if true, keeps the exponential sanity check for
* exponentials above three characters in length. If false, it removes
* that check.
*/
inline std::string doub2sci(double d,
std::string::size_type length,
std::string::size_type expLen,
bool showSign = true,
bool checkSwitch = true) const;
/*
* Convert scientific notation to FORTRAN notation.
* As an example, the string "1.5636E5" becomes " .15636D6".
* Note that the first character of the string will be '-' if
* the number is negative or ' ' if the first character is positive.
* @param aStr string with number to convert
* @param startPos start position of number in string
* @param length length (in characters) of number, including exponent.
* @param expLen length (in characters of exponent, not including sign.
* @param checkSwitch will keep the method running as originally programmed
* when set to true. If false, the method will always resize exponentials,
* produce an exponential with an E instead of a D, and always have a leading
* zero. For example -> 0.87654E-0004 or -0.1234E00005.
*/
inline std::string& sci2for(std::string& aStr,
std::string::size_type startPos = 0,
std::string::size_type length = std::string::npos,
std::string::size_type expLen = 3,
bool checkSwitch = true) const;
/*
* 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(double d,
std::string::size_type length,
std::string::size_type expLen,
bool checkSwitch = true) const;
/*
* 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) const
{
return strtod(s.c_str(), nullptr);
}
inline int toInt(const std::string& bitString, int sLength) const;
/*
* Convert a string to an integer.
* @param s string containing a number.
* @return int64_t integer representation of string.
*/
inline int64_t asInt(const std::string& s) const
{
return strtol(s.c_str(), nullptr, 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(double x,
std::string::size_type precision = 17) const;
/*
* 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(long double x,
std::string::size_type precision = 21) const;
/*
* 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 <class X>
inline std::string asString(const X x) const;
inline std::string asFixWidthString(int x, int width, char fill_digit) const;
std::map<std::string, std::string> observationType; // PSEUDORANGE, CARRIER_PHASE, DOPPLER, SIGNAL_STRENGTH
std::map<std::string, std::string> observationCode; // GNSS observation descriptors
const std::map<std::string, std::string> observationType; // PSEUDORANGE, CARRIER_PHASE, DOPPLER, SIGNAL_STRENGTH
const std::map<std::string, std::string> observationCode; // GNSS observation descriptors
std::fstream obsFile; // Output file stream for RINEX observation file
std::fstream navFile; // Output file stream for RINEX navigation data file
@@ -941,277 +740,25 @@ private:
std::fstream navBdsFile; // Output file stream for RINEX Beidou navigation data file
std::fstream navMixFile; // Output file stream for RINEX Mixed navigation data file
std::string navfilename; // Name of RINEX navigation file for GPS L1
std::string obsfilename; // Name of RINEX observation file
std::string sbsfilename; // Name of RINEX SBAS file
std::string navGalfilename; // Name of RINEX navigation file for Galileo
std::string navGlofilename; // Name of RINEX navigation file for Glonass
std::string navBdsfilename; // Name of RINEX navigation file for BeiDou
std::string navMixfilename; // Name of RINEX navigation file for fixed signals
const std::string navfilename; // Name of RINEX navigation file for GPS L1
const std::string obsfilename; // Name of RINEX observation file
const std::string sbsfilename; // Name of RINEX SBAS file
const std::string navGalfilename; // Name of RINEX navigation file for Galileo
const std::string navGlofilename; // Name of RINEX navigation file for Glonass
const std::string navBdsfilename; // Name of RINEX navigation file for BeiDou
const std::string navMixfilename; // Name of RINEX navigation file for fixed signals
std::vector<std::string> output_navfilename; // Name of output RINEX navigation file(s)
std::string d_stringVersion; // RINEX version (2.10/2.11 or 3.01/3.02)
double d_fake_cnav_iode;
int d_version; // RINEX version (2 for 2.10/2.11 and 3 for 3.01)
int d_numberTypesObservations; // Number of available types of observable in the system. Should be public?
int d_version; // RINEX version (2 for 2.10/2.11 and 3 for 3.01)
bool d_rinex_header_updated;
bool d_rinex_header_written;
bool d_pre_2009_file;
};
// Implementation of inline functions (modified versions from GNSSTk https://github.com/SGL-UT/gnsstk)
inline std::string& Rinex_Printer::leftJustify(std::string& s,
std::string::size_type length,
char pad) const
{
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,
std::string::size_type length,
char pad) const
{
if (length < s.length())
{
s = s.substr(s.length() - length, std::string::npos);
}
else
{
s.insert(static_cast<std::string::size_type>(0), length - s.length(), pad);
}
return s;
}
inline std::string Rinex_Printer::doub2for(double d,
std::string::size_type length,
std::string::size_type expLen,
bool checkSwitch) const
{
int16_t 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(double d,
std::string::size_type length,
std::string::size_type expLen,
bool showSign,
bool checkSwitch) const
{
std::string toReturn;
int16_t 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,
std::string::size_type startPos,
std::string::size_type length,
std::string::size_type expLen,
bool checkSwitch) const
{
std::string::size_type idx = aStr.find('.', startPos);
int expAdd = 0;
std::string exp;
int64_t 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)))
{
// Error: no decimal point in string
return aStr;
}
// 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)
{
// Error: no 'e' or 'E' in string";
}
}
// 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(static_cast<std::string::size_type>(0), 1, ' ');
}
// If checkSwitch is false, add on one leading zero to the string
if (!checkSwitch)
{
aStr.insert(static_cast<std::string::size_type>(1), 1, '0');
}
return aStr;
} // end sci2for
inline std::string asString(long double x, std::string::size_type precision)
{
std::ostringstream ss;
ss << std::fixed << std::setprecision(precision) << x;
return ss.str();
}
inline std::string Rinex_Printer::asString(double x, std::string::size_type precision) const
{
std::ostringstream ss;
ss << std::fixed << std::setprecision(precision) << x;
return ss.str();
}
inline std::string Rinex_Printer::asFixWidthString(int x, int width, char fill_digit) const
{
std::ostringstream ss;
ss << std::setfill(fill_digit) << std::setw(width) << x;
return ss.str().substr(ss.str().size() - width);
}
inline int64_t asInt(const std::string& s)
{
return strtol(s.c_str(), nullptr, 10);
}
inline int Rinex_Printer::toInt(const std::string& bitString, int sLength) const
{
int tempInt;
int num = 0;
for (int i = 0; i < sLength; i++)
{
tempInt = bitString[i] - '0';
num |= (1 << (sLength - 1 - i)) * tempInt;
}
return num;
}
template <class X>
inline std::string Rinex_Printer::asString(const X x) const
{
std::ostringstream ss;
ss << x;
return ss.str();
}
/** \} */
/** \} */
#endif // GNSS_SDR_RINEX_PRINTER_H

View File

@@ -2264,7 +2264,7 @@ int stropen(stream_t *stream, int type, int mode, const char *path)
stream->port = openserial(path, mode, stream->msg);
break;
case STR_FILE:
stream->port = openfile(path, mode, stream->msg);
stream->port = openfile(std::string(path), mode, stream->msg);
break;
case STR_TCPSVR:
stream->port = opentcpsvr(path, stream->msg);