| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194 | 
							- using DevExpress.Charts.Native;
 
- using DevExpress.XtraPrinting;
 
- using System;
 
- using System.Collections.Generic;
 
- using System.Diagnostics;
 
- using System.IO;
 
- using System.Linq;
 
- using System.Text;
 
- using System.Threading.Tasks;
 
- namespace PosResAnalysis
 
- {
 
-     /// <summary>
 
-     /// 星历推算帮助类.该类调用了Tle2XYZ.exe进程
 
-     /// </summary>
 
-     public static class EphHelper
 
-     {
 
-         private static readonly DateTime dtZero = new DateTime(1970, 1, 1, 0, 0, 0, 0);
 
-         private static string exePath= "星历推算";
 
-         private const string exeName = "Tle2XYZ.exe";
 
-         /// <summary>
 
-         /// 设置【Tle2XYZ.exe】文件所在路径,支持相对路径
 
-         /// </summary>
 
-         public static void SetExePath(string path)
 
-         {
 
-             if (string.IsNullOrWhiteSpace(path)) return;
 
-             if (path.StartsWith("\\"))//相对路径要么开头不带\,要么是 .\
 
-                 path = path.Remove(0, 1);
 
-             exePath = path;
 
-         }
 
-         /// <summary>
 
-         /// 推算双行星历
 
-         /// </summary>
 
-         /// <param name="tleStr">双行根数</param>
 
-         /// <param name="dt">指定时刻(北京时间)</param>
 
-         /// <returns></returns>
 
-         public static SatEphDto Calc(string tleStr, DateTime dt)
 
-         {
 
-             if (string.IsNullOrWhiteSpace(exePath))
 
-                 throw new Exception($"请先调用SetExePath指定{exeName}进程所在路径,支持相对路径");
 
-             if (!Directory.Exists(exePath))
 
-                 throw new Exception($"路径[{exePath}]不存在");
 
-             var exeFile = Path.Combine(exePath, exeName);
 
-             if (!File.Exists(exeFile))
 
-                 throw new Exception($"文件[{exeFile}]不存在");
 
-             tleStr = tleStr.Replace(";", ";");
 
-             if (tleStr.EndsWith(";"))
 
-                 tleStr = tleStr.Substring(0, tleStr.Length - 1);
 
-             tleStr = tleStr.Replace(";", ";");
 
-             var line1 = tleStr.Split(';')[0];
 
-             var line2 = tleStr.Split(';')[1];
 
-             var dtUtc = dt.AddHours(-8);
 
-             var timeSpan = (long)(dtUtc - dtZero).TotalSeconds;
 
-             Process p = new Process();
 
-             p.StartInfo.WorkingDirectory = exePath;
 
-             p.StartInfo.FileName = exeFile;
 
-             p.StartInfo.Arguments = $"-a \"{line1}\" -b \"{line2}\" -t {timeSpan} -p 1 -c 1";
 
-             p.StartInfo.CreateNoWindow = true;
 
-             p.StartInfo.RedirectStandardError = true;
 
-             p.StartInfo.RedirectStandardOutput = true;
 
-             p.StartInfo.UseShellExecute = false;
 
-             p.Start();
 
-             var succeed = p.WaitForExit(10000);
 
-             if (!succeed)
 
-             {
 
-                 throw new Exception($"进程[{exeName}]超时未完成!");
 
-             }
 
-             return ParseOneResult(p.StandardOutput.ReadToEnd());
 
-         }
 
-         /// <summary>
 
-         /// 批量推算双行星历
 
-         /// </summary>
 
-         /// <param name="tleStr">双行根数</param>
 
-         /// <param name="start">起始时刻(北京)</param>
 
-         /// <param name="end">结束(北京)</param>
 
-         /// <param name="spanSeconds">推算间隔(秒)</param>
 
-         /// <returns></returns>
 
-         public static List<SatEphDto> CalcMult(string tleStr, DateTime start, DateTime end, int spanSeconds)
 
-         {
 
-             if (string.IsNullOrWhiteSpace(exePath))
 
-                 throw new Exception($"请先调用SetExePath指定{exeName}进程所在路径,支持相对路径");
 
-             if (!Directory.Exists(exePath))
 
-                 throw new Exception($"路径[{exePath}]不存在");
 
-             var exeFile = Path.Combine(exePath, exeName);
 
-             if (!File.Exists(exeFile))
 
-                 throw new Exception($"文件[{exeFile}]不存在");
 
-             tleStr = tleStr.Replace(";", ";");
 
-             if (tleStr.EndsWith(";"))
 
-                 tleStr = tleStr.Substring(0, tleStr.Length - 1);
 
-             tleStr = tleStr.Replace(";", ";");
 
-             var line1 = tleStr.Split(';')[0];
 
-             var line2 = tleStr.Split(';')[1];
 
-             var dtUtc = start.AddHours(-8);
 
-             var timeSpan = (long)(dtUtc - dtZero).TotalSeconds;
 
-             var c = (end - start).TotalSeconds / spanSeconds;
 
-             Process p = new Process();
 
-             var binPath = AppDomain.CurrentDomain.BaseDirectory;
 
-             p.StartInfo.WorkingDirectory = exePath;
 
-             p.StartInfo.FileName = exeFile;
 
-             p.StartInfo.Arguments = $"-a \"{line1}\" -b \"{line2}\" -t {timeSpan} -p {spanSeconds} -c {c + 1}";
 
-             p.StartInfo.CreateNoWindow = true;
 
-             p.StartInfo.RedirectStandardError = true;
 
-             p.StartInfo.RedirectStandardOutput = true;
 
-             p.StartInfo.UseShellExecute = false;
 
-             StringBuilder sb = new StringBuilder();
 
-             p.OutputDataReceived += (sender, e) => sb.Append(e.Data);
 
-             p.Start();
 
-             p.BeginOutputReadLine();
 
-             p.WaitForExit();//WaitForExit加了超时时间的话进程退出后不能保证异步流已经读取完成,这是.NET框架的BUG
 
-             return ParseResult(sb.ToString());
 
-         }
 
-         static List<SatEphDto> ParseResult(string result)
 
-         {
 
-             if (string.IsNullOrWhiteSpace(result))
 
-             {
 
-                 throw new Exception("星历推算出现未知错误!");
 
-             }
 
-             var array = result.Split(";".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
 
-             List<SatEphDto> list = new List<SatEphDto>();
 
-             foreach (var item in array)
 
-             {
 
-                 var arrayItem = item.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
 
-                 for (int i = 0; i < arrayItem.Length; i++)
 
-                 {
 
-                     var dto = new SatEphDto
 
-                     {
 
-                         SatId = Convert.ToInt32(arrayItem[i++]),
 
-                         TleTime = dtZero.AddSeconds(Convert.ToInt64(arrayItem[i++])).AddHours(16),//内部有BUG需要多加8h
 
-                         SatTime = dtZero.AddSeconds(Convert.ToInt64(arrayItem[i++])).AddHours(8),//utc to beijing
 
-                         X = Math.Round(Convert.ToDouble(arrayItem[i++]), 3),
 
-                         Y = Math.Round(Convert.ToDouble(arrayItem[i++]), 3),
 
-                         Z = Math.Round(Convert.ToDouble(arrayItem[i++]), 3),
 
-                         VX = Math.Round(Convert.ToDouble(arrayItem[i++]), 3),
 
-                         VY = Math.Round(Convert.ToDouble(arrayItem[i++]), 3),
 
-                         VZ = Math.Round(Convert.ToDouble(arrayItem[i]), 3)
 
-                     };
 
-                     list.Add(dto);
 
-                 }
 
-             }
 
-             return list;
 
-         }
 
-         static SatEphDto ParseOneResult(string result)
 
-         {
 
-             if (string.IsNullOrWhiteSpace(result))
 
-             {
 
-                 throw new Exception("星历推算出现未知错误!");
 
-             }
 
-             result = result.Replace(";", "");
 
-             var array = result.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
 
-             int i = 0;
 
-             var dto = new SatEphDto
 
-             {
 
-                 SatId = Convert.ToInt32(array[i++]),
 
-                 TleTime = dtZero.AddSeconds(Convert.ToInt64(array[i++])).AddHours(16),//内部有BUG需要多加8h
 
-                 SatTime = dtZero.AddSeconds(Convert.ToInt64(array[i++])).AddHours(8),//utc to beijing
 
-                 X = Math.Round(Convert.ToDouble(array[i++]), 3),
 
-                 Y = Math.Round(Convert.ToDouble(array[i++]), 3),
 
-                 Z = Math.Round(Convert.ToDouble(array[i++]), 3),
 
-                 VX = Math.Round(Convert.ToDouble(array[i++]), 3),
 
-                 VY = Math.Round(Convert.ToDouble(array[i++]), 3),
 
-                 VZ = Math.Round(Convert.ToDouble(array[i++]), 3)
 
-             };
 
-             return dto;
 
-         }
 
-     }
 
-     public class SatEphDto
 
-     {
 
-         public int SatId { get; set; }
 
-         public DateTime SatTime { get; set; }
 
-         public DateTime TleTime { get; set; }
 
-         public double X { get; set; }
 
-         public double Y { get; set; }
 
-         public double Z { get; set; }
 
-         public double VX { get; set; }
 
-         public double VY { get; set; }
 
-         public double VZ { get; set; }
 
-         public override string ToString()
 
-         {
 
-             return $"{X},{Y},{Z},{VX},{VY},{VZ}";
 
-         }
 
-     }
 
- }
 
 
  |