Using TextWrangler to edit Garmin, Zwift, Tacx and other .fit, .tcx and .gpx files

On the lost ride retrieval topic, I haven’t yet found a way to locate any surviving Tacx data from my iPad, but I have several times had cause to edit a Garmin ride file which wouldn’t upload to Strava.

Typically this has been because the ride data file has been corrupted, albeit quite innocently. On one occasion I paused my Garmin 705 and paused/unpaused it several times too rapidly to make sure I was hearing the right chirp or multiple chirp which indicates it is running (or not). This cause the file to be mis-recorded – I’ll come to that in a moment.

The most recent occasion was with my Garmin 520, which just switched itself off mid-ride. I turned it back on, and the ride appeared to be recorded normally, but would also not upload to Strava. On the 520, as with the more modern Garmin devices, it looks to an iPhone using the Garmin Connect app and bluetooth, and this ride would not synchronise to the phone either.

On both occasions I was able to repair the file using TextWrangler, an advance text editing application (on my MacBook Pro) that I use to create and edit web pages. It handles a file structure called “XML”, a structure that on a line by line basis creates tagged files that contain data in a repeating pattern enclosed by an open and closing tag for each data item such as heart rate, latitude and longitude and so on. Here is an example of two successive “Trackpoints” that the Garmin records every second or two during a ride:

<Trackpoint>
<Time>2017-02-08T11:36:54.000Z</Time>
<Position>
<LatitudeDegrees>45.81380844116211</LatitudeDegrees>
<LongitudeDegrees>9.084691047668457</LongitudeDegrees>
</Position>
<DistanceMeters>0.0</DistanceMeters>
<HeartRateBpm>
<Value>80</Value>
</HeartRateBpm>
<Extensions>
<ns2:TPX/>
</Extensions>
</Trackpoint>
<Trackpoint>
<Time>2017-02-08T11:36:55.000Z</Time>
<DistanceMeters>0.1</DistanceMeters>
<HeartRateBpm>
<Value>80</Value>
</HeartRateBpm>
<Cadence>24</Cadence>
<Extensions>
<ns2:TPX>
<ns2:Speed>0.054688</ns2:Speed>
</ns2:TPX>
</Extensions>
</Trackpoint>

The problem with the Garmin 705 failure was just that ONE of the opening tags <Trackpoint> was missing for one timestamp, so that the file was formatted incorrectly. Strava is VERY strict on accepting only correctly formatted files, so until I added this tag back in (there are thousands of them in any ride, 20,000 in that particular ride) Strava wouldn’t accept it; but even replacing just that one missing one meant that I could use the file for Strava.

On the second occasion with the 520, one timestamp at the point that the Garmin 520 turned itself off suddenly changed its date to a completely different day, and all the rest of the dates were similarly wrong for the rest of the file. Here are the two successive timestamps in question, with a sudden jump from 2016-11-27 to 2019-04-07! This was at line 23857 out of 84192 in the file altogether:

<trkpt lat=”55.931874252855777740478515625″ lon=”-4.27179764024913311004638671875″>
<ele>46.40000152587890625</ele>
<time>2016-11-27T09:42:42.000Z</time>
<extensions>
<ns3:TrackPointExtension>
<ns3:atemp>2.0</ns3:atemp>
<ns3:hr>146</ns3:hr>
</ns3:TrackPointExtension>
</extensions>
</trkpt>
<trkpt lat=”55.9292156808078289031982421875″ lon=”-4.27936230786144733428955078125″>
<ele>34.40000152587890625</ele>
<time>2019-04-07T09:43:34.000Z</time>
<extensions>
<ns3:TrackPointExtension>
<ns3:atemp>3.0</ns3:atemp>
<ns3:hr>137</ns3:hr>
</ns3:TrackPointExtension>
</extensions>
</trkpt>

This time, a simple global edit to make all of those (10,000) subsequent dates the same as the first 5,000 or so meant that the file was once more readable by Strava. In this case, Garmin Express on the MacBook WAS able to read the original file, as no doubt Garmin’s software is better at second guessing their own software glitches than Strava is, or is bothered to be! In general I find Garmin’s software leaves a lot to be desired, both on the Mac and also in their devices, but the 520/820 series are a lot better than previous models.

One final point: .fit files that are created and used by those more modern Garmin devices are not alphanumeric, so they aren’t easily correctable other than wth Garmin’s own web-based available software, which just tends to truncate any part of the file that has an error. But if you can read the file with the laptop applications Garmin Express or Garmin Basecamp, you can the export a .tcx or.gpx file from them which IS the tagged file structure you can edit in an application like TextWrangler. The .fit files don’t look very amenable in Textwrangler – ouch!:

 Tˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇ†ˇˇˇˇˇˇˇˇ #Eù2∫~√’ÁÈ͸/3Ù
öı
 S¬≥ˇˇˇˇˇˇ@ˇˇˇˇˇˇˇˇ %Eù2√’XˆÍ¸∂9Ô

 Qˇˇˇˇˇˇˇˇ¿ˇˇˇˇˇˇˇˇmˇˇˇˇˇˇˇˇ (Eù2ë√’hθ0CÈ
È
 P ˇˇˇˇˇˇ )Eù2°√’/θ7FÁ
ôÁ
 Pöˇˇˇˇˇˇˇˇ—ˇˇˇˇˇˇˇˇ +Eù2…~√’ θzL·
.‚
 P¥ˇˇˇˇˇˇˇˇÄˇˇˇˇˇˇˇˇ -Eù2B}√’ï%θ±R€

Leave a Reply

Your email address will not be published. Required fields are marked *

*
*
Website