From 2e6fec600de9292296858daa544e0d2316424e68 Mon Sep 17 00:00:00 2001 From: Adam Snodgrass Date: Mon, 15 May 2017 18:58:37 -0400 Subject: [PATCH] Sets valid content for the name and desc fields Affects GPX output. Replaces placeholder values. The basename of the input file is used for the name field, such that: /path/to/foo.bar.baz.gps becomes: foo.bar.baz --- cmd/gpx.go | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/cmd/gpx.go b/cmd/gpx.go index b72eef4..fafbb56 100644 --- a/cmd/gpx.go +++ b/cmd/gpx.go @@ -22,6 +22,8 @@ import ( "os" "fmt" "log" + "path" + "strings" "time" "io" "io/ioutil" @@ -69,7 +71,8 @@ var gpxCmd = &cobra.Command{ trkpts = append(trkpts, recordToTrackPoint(rec)) } - gpxData := generateGPX(trkpts) + name := filenamePrefix(inFile) + gpxData := generateGPX(trkpts, name) if outFile != "" { ioutil.WriteFile(outFile, gpxData, 0644) } else { @@ -154,14 +157,14 @@ func recordToTrackPoint(rec v1000.Record) (trackPoint) { return tp } -func generateGPX(trkpts []trackPoint) []byte { +func generateGPX(trkpts []trackPoint, name string) []byte { trksegs := make([]trackSegment, 1) trksegs[0].TrackPoints = trkpts trk := track{ TrackSegments: trksegs, - Name: "please fix me", - Description: "and this too", + Name: name, + Description: "V1000 gps tracklog data", } bounds := gpxBounds{ @@ -244,3 +247,13 @@ func maximumLongitude(trkpts []trackPoint) latLong { } return high } + +func filenamePrefix(filename string) string { + f := path.Base(filename) + pos := strings.LastIndex(f, ".") + if pos == -1 { + return f + } else { + return f[:pos] + } +}