12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- using System;
- using System.Collections.Generic;
- using System.Diagnostics;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace XdCxRhDW.App.Api.星历推算
- {
- /// <summary>
- /// 星历推算
- /// </summary>
- public static class Tle2XYZ
- {
- public static double[] GetXyz(String tle, DateTime dt)
- {
- var lines = tle.Split(';');
- var dz = new DateTime(1970, 1, 1, 8, 0, 0);
- Process p = new Process();
- p.StartInfo.FileName = Path.Combine(p.StartInfo.WorkingDirectory, "API\\星历推算\\Tle2XYZ.exe");
- //-a "1 23467U 95003A 22364.32362671 -.00000025 00000+0 00000+0 0 9992" -b "2 23467 9.8007 17.1777 0001795 205.8937 164.3833 1.00270390102276"
- ////-t 1672718400 -p 1 -c 1
- p.StartInfo.Arguments = $"-a \"{lines[0]}\" -b \"{lines[1]}\" -t {(dt-dz).TotalSeconds} -p 1 -c 1";
- p.StartInfo.CreateNoWindow = true;
- p.StartInfo.RedirectStandardError = true;
- p.StartInfo.RedirectStandardOutput = true;
- p.StartInfo.UseShellExecute = false;
- p.Start();
- p.WaitForExit();//WaitForExit加了超时时间的话进程退出后不能保证异步流已经读取完成,这是.NET框架的BUG
- var str = p.StandardOutput.ReadToEnd();
- //解析
- //23467,1672357561,1672718400,-41542540.907490,5369494.210104,-4850802.865098,-44.255811,10.624541,386.892634;
- str = str.Replace(';', ' ').Trim();
- var result = str.Split(',');
- double[] res = new double[6];
- for (int idx = 0; idx < 6; ++idx)
- {
- res[idx] = Convert.ToDouble(result[idx + 3]);
- }
- return res;
- }
- }
- }
|