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:

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:

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!: