Increase precision of sample data in .GC file format

Three related issues fixes; firstly lat/lon values lose precision when
being read from .tcx files by Qt's QString::toDouble(). This
has been replaced with the stdc strtod() function in TcxParser.

Secondly, when writing to .gc format precision was also lost, this
has been fixed for lat/lon values.

Thirdly, when writing to .gc format precision of seconds was lost,
this is particularly relevant to Powertap files which have a sample
rate of 1.26 seconds.

Fixes #83.
This commit is contained in:
Mark Liversedge
2010-05-22 19:44:07 +01:00
committed by Sean Rhea
parent c4f82e19b6
commit 51784f64f6
2 changed files with 16 additions and 5 deletions

View File

@@ -158,10 +158,15 @@ GcFileReader::openRideFile(QFile &file, QStringList &errors) const
return rideFile;
}
// normal precision (Qt defaults)
#define add_sample(name) \
if (present->name) \
sample.setAttribute(#name, QString("%1").arg(point->name));
// high precision (6 decimals)
#define add_sample_hp(name) \
if (present->name) \
sample.setAttribute(#name, QString("%1").arg(point->name, 0, 'g', 11));
void
GcFileReader::writeRideFile(const RideFile *ride, QFile &file) const
{
@@ -242,7 +247,7 @@ GcFileReader::writeRideFile(const RideFile *ride, QFile &file) const
QDomElement sample = doc.createElement("sample");
samples.appendChild(sample);
assert(present->secs);
add_sample(secs);
add_sample_hp(secs);
add_sample(cad);
add_sample(hr);
add_sample(km);
@@ -250,8 +255,8 @@ GcFileReader::writeRideFile(const RideFile *ride, QFile &file) const
add_sample(nm);
add_sample(watts);
add_sample(alt);
add_sample(lon);
add_sample(lat);
add_sample_hp(lon);
add_sample_hp(lat);
sample.setAttribute("len", QString("%1").arg(ride->recIntSecs()));
}
}

View File

@@ -18,10 +18,14 @@
*/
#include <QString>
#include <QDebug>
#include "TcxParser.h"
#include "TimeUtils.h"
// use stc strtod to bypass Qt toDouble() issues
#include <stdlib.h>
TcxParser::TcxParser (RideFile* rideFile)
: rideFile(rideFile)
{
@@ -91,11 +95,13 @@ TcxParser::endElement( const QString&, const QString&, const QString& qName)
}
else if (qName == "LongitudeDegrees")
{
lon = buffer.toDouble();
char *p;
lon = strtod(buffer.toLatin1(), &p);
}
else if (qName == "LatitudeDegrees")
{
lat = buffer.toDouble();
char *p;
lat = strtod(buffer.toLatin1(), &p);
}
else if (qName == "Trackpoint")
{