diff options
author | Emile <hanemile@protonmail.com> | 2019-08-19 17:35:02 +0200 |
---|---|---|
committer | Emile <hanemile@protonmail.com> | 2019-08-19 17:35:02 +0200 |
commit | 3fd00f20af5e0a9e2a4e30a2b74c038b87445587 (patch) | |
tree | c7ca575dd1f02ebde4d312c016f5ab8f8bcac279 | |
parent | 61c0058b12c1bb65d6c4b7b4070abcd38d9db6bf (diff) |
line 1
-rw-r--r-- | convert.go | 115 |
1 files changed, 98 insertions, 17 deletions
diff --git a/convert.go b/convert.go index c0515d8..fb41fd9 100644 --- a/convert.go +++ b/convert.go @@ -2,6 +2,7 @@ package TLE import ( "fmt" + "math" "strconv" "strings" ) @@ -11,40 +12,120 @@ func NewTLE(RawTLE string) (TLE, error) { // split the TLE var SplitTLE []string = strings.Split(RawTLE, "\n") - //fmt.Printf("%#v", SplitTLE) - fmt.Printf("Line one, first char: %v", SplitTLE[1][0]) - // Line One // parse the line number LineOneLinenumber, err := strconv.Atoi(string(SplitTLE[1][0])) if err != nil { - return TLE{}, fmt.Errorf("%s: %#v", "Could not parse the line number", SplitTLE[0][1]) + return TLE{}, fmt.Errorf("%s: %#v\n%v", "Could not parse the line number", SplitTLE[1][1], err) + } + + // Parse the Satellite Number + SatelliteNumber, err := strconv.Atoi(SplitTLE[1][2:7]) + if err != nil { + return TLE{}, fmt.Errorf("%s: %#v\n%v", "Could not parse the Satellite Number", SplitTLE[1][2:7], err) + } + + // Parse the launch year + LaunchYear, err := strconv.Atoi(SplitTLE[1][9:11]) + if err != nil { + return TLE{}, fmt.Errorf("%s: %#v\n%v", "Could not parse the Launch Year", SplitTLE[1][9:11], err) + } + + // Parse the launch number + LaunchNumber, err := strconv.Atoi(SplitTLE[1][11:14]) + if err != nil { + return TLE{}, fmt.Errorf("%s: %#v\n%v", "Could not parse the Launch Number", SplitTLE[1][11:14], err) + } + + // Parse the epoch year + EpochYear, err := strconv.Atoi(SplitTLE[1][18:20]) + if err != nil { + return TLE{}, fmt.Errorf("%s: %#v\n%v", "Could not parse the Epoch Year", SplitTLE[1][18:20], err) + } + + // Parse the epoch day fraction + EpochDayFraction, err := strconv.ParseFloat(SplitTLE[1][20:32], 64) + if err != nil { + return TLE{}, fmt.Errorf("%s: %#v\n%v", "Could not parse the Epoch Day Fraction", SplitTLE[1][20:32], err) + } + + // Parse the First Time Derivative of the Mean Motion + RawFirstDeriv := strings.TrimSpace(SplitTLE[1][33:43]) + FirstDeriv, err := strconv.ParseFloat(RawFirstDeriv, 64) + if err != nil { + return TLE{}, fmt.Errorf("%s: %#v\n%v", "Could not parse the First Time Derivative of the Mean Motion", SplitTLE[1][33:43], err) + } + + /* + Parse the Second Time Derivative of the Mean Motion + */ + RawSecondDerivBase := strings.TrimSpace(SplitTLE[1][44:50]) + SecondDerivBase, err := strconv.Atoi(RawSecondDerivBase) + if err != nil { + return TLE{}, fmt.Errorf("%s: %#v\n%v", "Could not parse the Second Time Derivative of the Mean Motion Base", SplitTLE[1][44:50], err) + } + + RawSecondDerivPower := strings.TrimSpace(SplitTLE[1][50:52]) + SecondDerivPower, err := strconv.Atoi(RawSecondDerivPower) + if err != nil { + return TLE{}, fmt.Errorf("%s: %#v\n%v", "Could not parse the Second Time Derivative of the Mean Motion Power", SplitTLE[1][50:52], err) + } + + // This converts the following format: (67960-4 = 0.000067960) + // Also: (00000-0 = 0.00000) + SecondDeriv := float64(SecondDerivBase) / math.Pow(10, (-1*float64(SecondDerivPower))+5) + + /* + Parse the Second Time Derivative of the Mean Motion + */ + RawBSTARBase := strings.TrimSpace(SplitTLE[1][53:59]) + BSTARBase, err := strconv.Atoi(RawBSTARBase) + if err != nil { + return TLE{}, fmt.Errorf("%s: %#v\n%v", "Could not parse the BSTAR Drag Term Base", SplitTLE[1][53:59], err) + } + + RawBSTARPower := strings.TrimSpace(SplitTLE[1][59:61]) + BSTARPower, err := strconv.Atoi(RawBSTARPower) + if err != nil { + return TLE{}, fmt.Errorf("%s: %#v\n%v", "Could not parse the BSTAR Drag Term Power", SplitTLE[1][59:61], err) + } + + // This converts the following format: (67960-4 = 0.000067960) + // Also: (00000-0 = 0.00000) + BSTAR := float64(BSTARBase) / math.Pow(10, (-1*float64(BSTARPower))+5) + + // Parse the Element set number + RawElementSetNumber := strings.TrimSpace(SplitTLE[1][64:68]) + ElementSetNumber, err := strconv.Atoi(RawElementSetNumber) + if err != nil { + return TLE{}, fmt.Errorf("%s: %#v\n%v", "Could not parse the Element set number", SplitTLE[1][64:68], err) } + // fill the generatedTLE struct var generatedTLE TLE = TLE{ TitleLine: TitleLine{ Satname: fmt.Sprintf("%-25s", SplitTLE[0][0:24]), }, LineOne: LineOne{ Linenumber: int8(LineOneLinenumber), - SatelliteNumber: 0, - Classification: 0, + SatelliteNumber: SatelliteNumber, + Classification: rune(SplitTLE[1][7]), InternationalDesignator: InternationalDesignator{ - Launchyear: 0, - Launchnumber: 0, - Launchpiece: 0, + Launchyear: int8(LaunchYear), + Launchnumber: LaunchNumber, + Launchpiece: rune(SplitTLE[1][14]), }, Epoch: Epoch{ - Year: 0, - Dayfraction: 0, + Year: int8(EpochYear), + Dayfraction: EpochDayFraction, }, - Firstderiv: 0, - Secondderiv: 0, - BSTAR: 0, - Numberzero: 0, - ElementSetNumber: 0, - Checksum: 0, + Firstderiv: FirstDeriv, + Secondderiv: SecondDeriv, + BSTAR: BSTAR, + Numberzero: int8(SplitTLE[1][62]), + ElementSetNumber: ElementSetNumber, + Checksum: int8(SplitTLE[1][68]), }, LineTwo: LineTwo{}, } |