about summary refs log tree commit diff
path: root/convert.go
diff options
context:
space:
mode:
authorEmile <hanemile@protonmail.com>2019-09-02 19:44:37 +0200
committerEmile <hanemile@protonmail.com>2019-09-02 19:44:37 +0200
commit4b62c8b6e537fbc2a9b14bf01d7884d99e82fb97 (patch)
tree5a2643a4d71d5c61d99e8e33d168dfd1e17ff516 /convert.go
parent5b3a61bcf9780e1e2f0ae9ed2978e3c0ad420392 (diff)
moved the parsing of line two into an own function
Diffstat (limited to 'convert.go')
-rw-r--r--convert.go163
1 files changed, 87 insertions, 76 deletions
diff --git a/convert.go b/convert.go
index ffb3a13..5d6d276 100644
--- a/convert.go
+++ b/convert.go
@@ -18,71 +18,9 @@ func NewTLE(RawTLE string) (TLE, error) {
 		fmt.Println(err)
 	}
 
-	////////////////////////////////////////////////////////////////////////////
-	// Line Two
-	////////////////////////////////////////////////////////////////////////////
-
-	// parse the line number
-	LineTwoLinenumber, err := strconv.Atoi(string(SplitTLE[2][0]))
+	lineTwo, err := parseLineTwo(SplitTLE)
 	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)
+		fmt.Println(err)
 	}
 
 	// fill the generatedTLE struct
@@ -91,18 +29,7 @@ func NewTLE(RawTLE string) (TLE, error) {
 			Satname: fmt.Sprintf("%-24s", SplitTLE[0][0:24]),
 		},
 		LineOne: lineOne,
-		LineTwo: LineTwo{
-			Linenumber:                       LineTwoLinenumber,
-			SatelliteNumber:                  lineOne.SatelliteNumber,
-			Inclination:                      Inclination,
-			RightAscensionOfTheAscendingNode: RightAscensionOfTheAscendingNode,
-			Eccentricity:                     Eccentricity,
-			ArgumentOfPerigee:                ArgumentOfPerigee,
-			MeanAnomaly:                      MeanAnomaly,
-			MeanMotion:                       MeanMotion,
-			RevolutionNumberAtEpoch:          RevolutionNumberAtEpoch,
-			Checksum:                         ChecksumLineTwo,
-		},
+		LineTwo: lineTwo,
 	}
 
 	return generatedTLE, nil
@@ -235,3 +162,87 @@ func parseLineOne(SplitTLE []string) (LineOne, error) {
 
 	return newLineOne, nil
 }
+
+func parseLineTwo(SplitTLE []string) (LineTwo, error) {
+
+	// parse the line number
+	LineTwoLinenumber, err := strconv.Atoi(string(SplitTLE[2][0]))
+	if err != nil {
+		return LineTwo{}, fmt.Errorf("%s: %#v\n%v", "Could not parse the line number", SplitTLE[2][0], err)
+	}
+
+	// Parse the Satellite Number
+	SatelliteNumber, err := strconv.Atoi(SplitTLE[1][2:7])
+	if err != nil {
+		return LineTwo{}, fmt.Errorf("%s: %#v\n%v", "Could not parse the Satellite Number", SplitTLE[1][2:7], err)
+	}
+
+	// Parse the Inclination
+	RawInclination := strings.TrimSpace(SplitTLE[2][9:16])
+	Inclination, err := strconv.ParseFloat(RawInclination, 64)
+	if err != nil {
+		return LineTwo{}, 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 LineTwo{}, 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 LineTwo{}, 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 LineTwo{}, 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 LineTwo{}, 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 LineTwo{}, 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 LineTwo{}, 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 LineTwo{}, fmt.Errorf("%s: %#v\n%v", "Could not parse the checksum", SplitTLE[2][68], err)
+	}
+
+	newLineTwo := LineTwo{
+		Linenumber:                       LineTwoLinenumber,
+		SatelliteNumber:                  SatelliteNumber,
+		Inclination:                      Inclination,
+		RightAscensionOfTheAscendingNode: RightAscensionOfTheAscendingNode,
+		Eccentricity:                     Eccentricity,
+		ArgumentOfPerigee:                ArgumentOfPerigee,
+		MeanAnomaly:                      MeanAnomaly,
+		MeanMotion:                       MeanMotion,
+		RevolutionNumberAtEpoch:          RevolutionNumberAtEpoch,
+		Checksum:                         ChecksumLineTwo,
+	}
+
+	return newLineTwo, nil
+}