about summary refs log tree commit diff
path: root/convert.go
diff options
context:
space:
mode:
authorEmile <hanemile@protonmail.com>2019-08-30 14:53:06 +0200
committerEmile <hanemile@protonmail.com>2019-08-30 14:53:06 +0200
commit26de707af673c99eafbe00584f1ac5a29757f6d3 (patch)
tree1c0fb78cf32fcfb4e5f6be2c7cbdff9e62c27bdc /convert.go
parent1e7b8f716261aee4105edadecc01acdb884c63a3 (diff)
fixed the git errors
Diffstat (limited to 'convert.go')
-rw-r--r--convert.go110
1 files changed, 103 insertions, 7 deletions
diff --git a/convert.go b/convert.go
index e8000e6..7e76f93 100644
--- a/convert.go
+++ b/convert.go
@@ -1,4 +1,4 @@
-package TLE
+package tle
 
 import (
 	"fmt"
@@ -7,12 +7,15 @@ import (
 	"strings"
 )
 
+// NewTLE creates a new TLE object from a given TLE string
 func NewTLE(RawTLE string) (TLE, error) {
 
 	// split the TLE
-	var SplitTLE []string = strings.Split(RawTLE, "\n")
+	var SplitTLE = strings.Split(RawTLE, "\n")
 
+	////////////////////////////////////////////////////////////////////////////
 	// Line One
+	////////////////////////////////////////////////////////////////////////////
 
 	// parse the line number
 	LineOneLinenumber, err := strconv.Atoi(string(SplitTLE[1][0]))
@@ -38,6 +41,9 @@ func NewTLE(RawTLE string) (TLE, error) {
 		return TLE{}, fmt.Errorf("%s: %#v\n%v", "Could not parse the Launch Number", SplitTLE[1][11:14], err)
 	}
 
+	// Parse the launch number
+	LaunchPiece := strings.TrimSpace(SplitTLE[1][14:16])
+
 	// Parse the epoch year
 	EpochYear, err := strconv.Atoi(SplitTLE[1][18:20])
 	if err != nil {
@@ -102,10 +108,89 @@ func NewTLE(RawTLE string) (TLE, error) {
 		return TLE{}, fmt.Errorf("%s: %#v\n%v", "Could not parse the Element set number", SplitTLE[1][64:68], err)
 	}
 
+	// Parse the Number Zero
+	NumberZero, err := strconv.Atoi(string(SplitTLE[1][62]))
+	if err != nil {
+		return TLE{}, fmt.Errorf("%s: %#v\n%v", "Could not parse the number zero", SplitTLE[1][62], err)
+	}
+
+	// Parse the Checksum
+	Checksum, err := strconv.Atoi(string(SplitTLE[1][68]))
+	if err != nil {
+		return TLE{}, fmt.Errorf("%s: %#v\n%v", "Could not parse the checksum", SplitTLE[1][68], err)
+	}
+
+	////////////////////////////////////////////////////////////////////////////
+	// Line Two
+	////////////////////////////////////////////////////////////////////////////
+
+	// parse the line number
+	LineTwoLinenumber, err := strconv.Atoi(string(SplitTLE[2][0]))
+	if err != nil {
+		return TLE{}, fmt.Errorf("%s: %#v\n%v", "Could not parse the line number", SplitTLE[2][0], err)
+	}
+
+	// SatelliteNumber
+	// (Parsed before in line one)
+
+	// Parse the Inclination
+	RawInclination := strings.TrimSpace(SplitTLE[2][9:16])
+	Inclination, err := strconv.ParseFloat(RawInclination, 64)
+	if err != nil {
+		return TLE{}, fmt.Errorf("%s: %#v\n%v", "Could not parse the Inclination", SplitTLE[2][6:19], err)
+	}
+
+	// Parse the RightAscensionOfTheAscendingNode
+	RawRightAscensionOfTheAscendingNode := strings.TrimSpace(SplitTLE[2][17:25])
+	RightAscensionOfTheAscendingNode, err := strconv.ParseFloat(RawRightAscensionOfTheAscendingNode, 64)
+	if err != nil {
+		return TLE{}, fmt.Errorf("%s: %#v\n%v", "Could not parse the RightAscensionOfTheAscendingNode", SplitTLE[2][17:25], err)
+	}
+
+	// Parse the Eccentricity
+	RawEccentricity := strings.TrimSpace(SplitTLE[2][26:33])
+	Eccentricity, err := strconv.ParseFloat(RawEccentricity, 64)
+	if err != nil {
+		return TLE{}, fmt.Errorf("%s: %#v\n%v", "Could not parse the Eccentricity", SplitTLE[2][26:33], err)
+	}
+
+	// Parse the ArgumentOfPerigee
+	RawArgumentOfPerigee := strings.TrimSpace(SplitTLE[2][34:42])
+	ArgumentOfPerigee, err := strconv.ParseFloat(RawArgumentOfPerigee, 64)
+	if err != nil {
+		return TLE{}, fmt.Errorf("%s: %#v\n%v", "Could not parse the ArgumentOfPerigee", SplitTLE[2][34:42], err)
+	}
+
+	// Parse the MeanAnomaly
+	RawMeanAnomaly := strings.TrimSpace(SplitTLE[2][43:51])
+	MeanAnomaly, err := strconv.ParseFloat(RawMeanAnomaly, 64)
+	if err != nil {
+		return TLE{}, fmt.Errorf("%s: %#v\n%v", "Could not parse the MeanAnomaly", SplitTLE[2][43:51], err)
+	}
+
+	// Parse the MeanMotion
+	RawMeanMotion := strings.TrimSpace(SplitTLE[2][52:63])
+	MeanMotion, err := strconv.ParseFloat(RawMeanMotion, 64)
+	if err != nil {
+		return TLE{}, fmt.Errorf("%s: %#v\n%v", "Could not parse the MeanMotion", SplitTLE[2][52:63], err)
+	}
+
+	// Parse the RevolutionNumberAtEpoch
+	RevolutionNumberAtEpoch, err := strconv.Atoi(SplitTLE[2][63:68])
+	if err != nil {
+		return TLE{}, fmt.Errorf("%s: %#v\n%v", "Could not parse the MeanMotion", SplitTLE[2][63:68], err)
+	}
+
+	// Parse the Checksum
+	ChecksumLineTwo, err := strconv.Atoi(string(SplitTLE[2][68]))
+	if err != nil {
+		return TLE{}, fmt.Errorf("%s: %#v\n%v", "Could not parse the checksum", SplitTLE[2][68], err)
+	}
+
 	// fill the generatedTLE struct
 	var generatedTLE TLE = TLE{
 		TitleLine: TitleLine{
-			Satname: fmt.Sprintf("%-25s", SplitTLE[0][0:24]),
+			Satname: fmt.Sprintf("%-24s", SplitTLE[0][0:24]),
 		},
 		LineOne: LineOne{
 			Linenumber:      LineOneLinenumber,
@@ -114,7 +199,7 @@ func NewTLE(RawTLE string) (TLE, error) {
 			InternationalDesignator: InternationalDesignator{
 				Launchyear:   LaunchYear,
 				Launchnumber: LaunchNumber,
-				Launchpiece:  string(SplitTLE[1][14]),
+				Launchpiece:  LaunchPiece,
 			},
 			Epoch: Epoch{
 				Year:        EpochYear,
@@ -123,11 +208,22 @@ func NewTLE(RawTLE string) (TLE, error) {
 			Firstderiv:       FirstDeriv,
 			Secondderiv:      SecondDeriv,
 			BSTAR:            BSTAR,
-			Numberzero:       int8(SplitTLE[1][62]),
+			Numberzero:       NumberZero,
 			ElementSetNumber: ElementSetNumber,
-			Checksum:         int8(SplitTLE[1][68]),
+			Checksum:         Checksum,
+		},
+		LineTwo: LineTwo{
+			Linenumber:                       LineTwoLinenumber,
+			SatelliteNumber:                  SatelliteNumber,
+			Inclination:                      Inclination,
+			RightAscensionOfTheAscendingNode: RightAscensionOfTheAscendingNode,
+			Eccentricity:                     Eccentricity,
+			ArgumentOfPerigee:                ArgumentOfPerigee,
+			MeanAnomaly:                      MeanAnomaly,
+			MeanMotion:                       MeanMotion,
+			RevolutionNumberAtEpoch:          RevolutionNumberAtEpoch,
+			Checksum:                         ChecksumLineTwo,
 		},
-		LineTwo: LineTwo{},
 	}
 
 	return generatedTLE, nil