Skip to content

Commit

Permalink
Giovanni Zilli adds slope handling to subrip format.
Browse files Browse the repository at this point in the history
  • Loading branch information
robertlipe committed Jun 20, 2015
1 parent 760700c commit 56518df
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 0 deletions.
1 change: 1 addition & 0 deletions gpsbabel/defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -867,6 +867,7 @@ double waypt_time(const Waypoint* wpt);
double waypt_speed(const Waypoint* A, const Waypoint* B);
double waypt_speed_ex(const Waypoint* A, const Waypoint* B);
double waypt_vertical_speed(const Waypoint* A, const Waypoint* B);
double waypt_gradient(const Waypoint* A, const Waypoint* B);
double waypt_course(const Waypoint* A, const Waypoint* B);
double waypt_distance(const Waypoint* A, const Waypoint* B);
double waypt_distance_ex(const Waypoint* A, const Waypoint* B);
Expand Down
6 changes: 6 additions & 0 deletions gpsbabel/subrip.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ static int stnum;
static gbfile* fout;
static const Waypoint* prevwpp;
static double vspeed;
static double gradient;

/* internal helper functions */

Expand Down Expand Up @@ -110,6 +111,9 @@ subrip_prevwp_pr(const Waypoint* waypointp)
case 'v':
gbfprintf(fout, "%2.2f", vspeed);
break;
case 'g':
gbfprintf(fout, "%2.1f%%", gradient);
break;
case 't':
{
QTime t = prevwpp->GetCreationTime().toUTC().time();
Expand Down Expand Up @@ -183,6 +187,7 @@ subrip_trkpt_pr(const Waypoint* waypointp)
if (prevwpp) {
subrip_prevwp_pr(waypointp);
vspeed = waypt_vertical_speed(waypointp, prevwpp);
gradient = waypt_gradient(waypointp, prevwpp);
}
prevwpp = waypointp;
}
Expand All @@ -201,6 +206,7 @@ subrip_wr_init(const char* fname)

prevwpp = NULL;
vspeed = 0;
gradient = 0;

if ((opt_gpstime != NULL) && (opt_gpsdate != NULL)) {
time(&gpstime_t);
Expand Down
23 changes: 23 additions & 0 deletions gpsbabel/waypt.cc
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,29 @@ waypt_vertical_speed(const Waypoint* A, const Waypoint* B)
}
}

/*
* Returns "Road Gradient" between A and B as a percentage of slope.
* If there is no distance or either A or B have unknown altitude, return 0.
*/
double
waypt_gradient(const Waypoint* A, const Waypoint* B)
{
double dist, altitude, gradient;
dist = waypt_distance(A, B);
if (dist == 0) {
return 0;
}

altitude = A->altitude - B->altitude;
if (altitude == 0 ||
A->altitude == unknown _alt || B->altitude == unknown_alt) {
return 0;
}

gradient = (altitude / dist) * 100;
return (gradient);
}

/*
* Calculates "Course True" from A to B
*/
Expand Down
4 changes: 4 additions & 0 deletions gpsbabel/xmldoc/formats/options/subrip-format.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@
<entry>%h</entry>
<entry>heart rate</entry>
</row>
<row>
<entry>%g</entry>
<entry>road gradient</entry>
</row>
<row>
<entry>\n</entry>
<entry>newline</entry>
Expand Down

0 comments on commit 56518df

Please sign in to comment.