|
@@ -12,37 +12,17 @@ namespace Ips.Eph.ResolveUtil
|
|
|
{
|
|
|
public static Tle ParseTle(string tleLine1, string tleLine2, string tleName = null)
|
|
|
{
|
|
|
- int satCl = 0;
|
|
|
- string noradId;
|
|
|
- int startYear = 0;
|
|
|
- int startNumber = 0;
|
|
|
- string intDes = "--";
|
|
|
+ int count = 0;
|
|
|
int epochYear;
|
|
|
double epochDay;
|
|
|
|
|
|
- double firstMeanMotion;
|
|
|
- double secondMeanMotion;
|
|
|
- double dragTerm;
|
|
|
- double ephemeris;
|
|
|
- int setNumber = 0;
|
|
|
- int checksum1;
|
|
|
- int count = 0;
|
|
|
-
|
|
|
- //bool valid1 = isValid(tleLine1);
|
|
|
- //bool valid2 = isValid(tleLine2);
|
|
|
-
|
|
|
- //if (!valid1 || !valid2)
|
|
|
- //{
|
|
|
- // throw new InvalidDataException($"The data contained checksum error(s) in {((valid1) ? "" : "line1")} {((valid2) ? "" : "line2")}. ");
|
|
|
- //}
|
|
|
-
|
|
|
Tle ret;
|
|
|
try
|
|
|
{
|
|
|
+ string[] line1 = new string[9];
|
|
|
try
|
|
|
{
|
|
|
string[] s1 = tleLine1.Split(' ');
|
|
|
- string[] line1 = new string[9];
|
|
|
|
|
|
for (int i = 0; i < s1.Length; i++)
|
|
|
{
|
|
@@ -52,112 +32,10 @@ namespace Ips.Eph.ResolveUtil
|
|
|
count++;
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- string sclass = line1[1].Substring(line1[1].Length - 1);
|
|
|
- if (sclass == "U")
|
|
|
- {
|
|
|
- satCl = 0x0;
|
|
|
- }
|
|
|
- if (sclass == "C")
|
|
|
- {
|
|
|
- satCl = 0x1;
|
|
|
- }
|
|
|
- if (sclass == "S")
|
|
|
- {
|
|
|
- satCl = 0x2;
|
|
|
- }
|
|
|
-
|
|
|
- noradId = line1[1].Remove(line1[1].Length - 1);
|
|
|
-
|
|
|
int noID = 0;
|
|
|
- if (count == 8)
|
|
|
- {
|
|
|
- noID = -1;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- startYear = Convert.ToInt32(line1[2].Substring(0, 2));
|
|
|
- startNumber = Convert.ToInt32(line1[2].Substring(2, 3));
|
|
|
- intDes = line1[2].Substring(5);
|
|
|
- }
|
|
|
-
|
|
|
epochYear = Convert.ToInt32(line1[3 + noID].Substring(0, 2));
|
|
|
string epDay = line1[3 + noID].Substring(2);
|
|
|
epochDay = double.Parse(epDay, CultureInfo.GetCultureInfo("en-US"));
|
|
|
-
|
|
|
- firstMeanMotion = double.Parse(line1[4 + noID], CultureInfo.GetCultureInfo("en-US"));
|
|
|
-
|
|
|
- int zeros = Convert.ToInt32(line1[5 + noID].Substring(line1[5].Length - 1));
|
|
|
- if (line1[5 + noID].Equals("00000+0"))
|
|
|
- {
|
|
|
- line1[5 + noID] = line1[5 + noID].Substring(0, line1[5 + noID].IndexOf('+'));
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- line1[5 + noID] = line1[5 + noID].Substring(0, line1[5 + noID].IndexOf('-'));
|
|
|
- }
|
|
|
- if (line1[5 + noID].Length > 0)
|
|
|
- {
|
|
|
- if (line1[5 + noID][0] == '+' || line1[5 + noID][0] == '-')
|
|
|
- {
|
|
|
- line1[5 + noID] = line1[5 + noID].Insert(1, ".");
|
|
|
- for (int i = 0; i < zeros; i++)
|
|
|
- line1[5 + noID] = line1[5 + noID].Insert(2, "0");
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- line1[5 + noID] = line1[5 + noID].Insert(0, ".");
|
|
|
- for (int i = 0; i < zeros; i++)
|
|
|
- line1[5 + noID] = line1[5 + noID].Insert(1, "0");
|
|
|
- }
|
|
|
- secondMeanMotion = double.Parse(line1[5 + noID], CultureInfo.GetCultureInfo("en-US"));
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- secondMeanMotion = 0.0;
|
|
|
- }
|
|
|
-
|
|
|
- zeros = Convert.ToInt32(line1[6 + noID].Substring(line1[6 + noID].Length - 1));
|
|
|
- if (line1[6 + noID][line1[6 + noID].Length - 2] == '-')
|
|
|
- {
|
|
|
- line1[6 + noID] = line1[6 + noID].Substring(0, line1[6 + noID].IndexOf('-'));
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- line1[6 + noID] = line1[6 + noID].Substring(0, line1[6 + noID].IndexOf('+'));
|
|
|
- }
|
|
|
- if (line1[6 + noID].Length > 0)
|
|
|
- {
|
|
|
- if (line1[6 + noID][0] == '+' || line1[6 + noID][0] == '-')
|
|
|
- {
|
|
|
- line1[6 + noID] = line1[6 + noID].Insert(1, ".");
|
|
|
- for (int i = 0; i < zeros; i++)
|
|
|
- line1[6 + noID] = line1[6 + noID].Insert(2, "0");
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- line1[6 + noID] = line1[6 + noID].Insert(0, ".");
|
|
|
- for (int i = 0; i < zeros; i++)
|
|
|
- line1[6 + noID] = line1[6 + noID].Insert(1, "0");
|
|
|
- }
|
|
|
- dragTerm = double.Parse(line1[6 + noID], CultureInfo.GetCultureInfo("en-US"));
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- dragTerm = 0.0;
|
|
|
- }
|
|
|
-
|
|
|
- ephemeris = double.Parse(line1[7 + noID], CultureInfo.GetCultureInfo("en-US"));
|
|
|
-
|
|
|
- if (line1[8 + noID].Length > 1)
|
|
|
- {
|
|
|
- setNumber = Convert.ToInt32(line1[8 + noID].Substring(0, line1[8 + noID].Length - 1));
|
|
|
- checksum1 = Convert.ToInt32(line1[8 + noID].Substring(line1[8 + noID].Length - 1));
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- checksum1 = Convert.ToInt32(line1[8 + noID]);
|
|
|
- }
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
@@ -165,15 +43,6 @@ namespace Ips.Eph.ResolveUtil
|
|
|
}
|
|
|
|
|
|
int satNumber = 0;
|
|
|
- double inclination = 0;
|
|
|
- double rightAscension = 0;
|
|
|
- double eccentricity = 0;
|
|
|
- double perigee = 0;
|
|
|
- double meanAnomoly = 0;
|
|
|
- double meanMotion = 0;
|
|
|
- double relevationNumber = 0;
|
|
|
- int checksum2 = 0;
|
|
|
-
|
|
|
//Start Line2
|
|
|
try
|
|
|
{
|
|
@@ -190,47 +59,16 @@ namespace Ips.Eph.ResolveUtil
|
|
|
}
|
|
|
|
|
|
satNumber = Convert.ToInt32(line2[1]);
|
|
|
- inclination = double.Parse(line2[2], CultureInfo.GetCultureInfo("en-US"));
|
|
|
- rightAscension = double.Parse(line2[3], CultureInfo.GetCultureInfo("en-US"));
|
|
|
- line2[4] = line2[4].Insert(0, ".");
|
|
|
- eccentricity = double.Parse(line2[4], CultureInfo.GetCultureInfo("en-US"));
|
|
|
- perigee = double.Parse(line2[5], CultureInfo.GetCultureInfo("en-US"));
|
|
|
- meanAnomoly = double.Parse(line2[6], CultureInfo.GetCultureInfo("en-US"));
|
|
|
- if (line2[8] != null)
|
|
|
- {
|
|
|
- meanMotion = double.Parse(line2[7], CultureInfo.GetCultureInfo("en-US"));
|
|
|
- checksum2 = Convert.ToInt32(line2[8].Substring(line2[8].Length - 1));
|
|
|
- relevationNumber = double.Parse(line2[8].Substring(0, line2[8].Length - 1),
|
|
|
- CultureInfo.GetCultureInfo("en-US"));
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- checksum2 = Convert.ToInt32(line2[7].Substring(line2[7].Length - 1));
|
|
|
- meanMotion = double.Parse(line2[7].Substring(0, 11),
|
|
|
- CultureInfo.GetCultureInfo("en-US"));
|
|
|
- relevationNumber = double.Parse(line2[7].Substring(11, 5),
|
|
|
- CultureInfo.GetCultureInfo("en-US"));
|
|
|
- }
|
|
|
-
|
|
|
- if (tleName == null)
|
|
|
- {
|
|
|
- tleName = startYear.ToString() + startNumber.ToString() + intDes;
|
|
|
- }
|
|
|
- if (tleName[0] == '0' && tleName[1] == ' ')
|
|
|
- {
|
|
|
- tleName = tleName.Remove(0, 2);
|
|
|
- }
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
throw new InvalidDataException("Could not parse Line 2.", ex);
|
|
|
}
|
|
|
|
|
|
- ret = new Tle(tleName, noradId, (Tle.Enum.SatClass)satCl, startYear, startNumber, intDes,
|
|
|
- epochYear, epochDay, firstMeanMotion, secondMeanMotion, dragTerm,
|
|
|
- ephemeris, setNumber, checksum1, satNumber, inclination, rightAscension,
|
|
|
- eccentricity, perigee, meanAnomoly, meanMotion, relevationNumber, checksum2);
|
|
|
- ret.TleName = tleName;
|
|
|
+ ret = new Tle(tleName, satNumber, epochYear, epochDay);
|
|
|
+ ret.TleName = tleName.Trim();
|
|
|
+ if (ret.TleName.StartsWith("0 "))
|
|
|
+ ret.TleName = ret.TleName.Substring(2);
|
|
|
ret.Line1 = tleLine1;
|
|
|
ret.Line2 = tleLine2;
|
|
|
}
|
|
@@ -267,6 +105,7 @@ namespace Ips.Eph.ResolveUtil
|
|
|
}
|
|
|
if (lineNr == "2" && (line1 != null))
|
|
|
{
|
|
|
+ if (name.Contains("TBA")) continue;//TBA表示还未发射的卫星
|
|
|
results.Add(ParseTle(line1, line, name));
|
|
|
}
|
|
|
}
|
|
@@ -274,30 +113,5 @@ namespace Ips.Eph.ResolveUtil
|
|
|
}
|
|
|
return results;
|
|
|
}
|
|
|
-
|
|
|
- private static bool isValid(string line1)
|
|
|
- {
|
|
|
- int sum1 = 0;
|
|
|
- for (int i = 0; i < line1.Count() - 1; i++)
|
|
|
- {
|
|
|
- if (char.IsNumber(line1[i]))
|
|
|
- {
|
|
|
- sum1 = sum1 + (int)Char.GetNumericValue(line1[i]);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- if (line1[i] == '-')
|
|
|
- {
|
|
|
- sum1++;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- int result = sum1 % 10;
|
|
|
- int checksum = (int)Char.GetNumericValue(line1[line1.Count() - 1]);
|
|
|
- if (result == checksum)
|
|
|
- return true;
|
|
|
- else
|
|
|
- return false;
|
|
|
- }
|
|
|
}
|
|
|
}
|