XcorrUtils.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. using System;
  2. using System.Diagnostics;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Reflection;
  6. using System.Threading.Tasks;
  7. using System.Windows.Forms;
  8. using XdCxRhDW.App.CpuCgTools;
  9. using System.Collections;
  10. using System.Collections.Generic;
  11. namespace XdCxRhDW.App.CorTools
  12. {
  13. class XcorrStruct
  14. {
  15. public String file1 { get; set; }
  16. public String file2 { get; set; }
  17. public int smpStart { get; set; } //开始样点
  18. public int smpCount { get; set; } //样点数
  19. public double samplingRate { get; set; } //采样率
  20. public double dtCenter { get; set; } //时差中心
  21. public double dtRange { get; set; } //时差范围
  22. public double dfRange { get; set; } //频差范围
  23. public double snrThreshold { get; set; } //信噪比门限
  24. }
  25. class XcorrUtils
  26. {
  27. static Process p = new Process();
  28. // D:/data/test/r1.dat D:/data/test/r4.dat 1562500 -250000 20 16384 100000 1048576 11
  29. public static async Task<CafResult> Calc(XcorrStruct xs)
  30. {
  31. CafResult res = new CafResult();
  32. await Task.Run(() =>
  33. {
  34. p.StartInfo.FileName = Path.Combine(p.StartInfo.WorkingDirectory, "xcorr\\XcorrCpu.exe");
  35. p.StartInfo.Arguments = $"\"{xs.file1}\" \"{xs.file2}\" {(Int64)(xs.samplingRate)} {xs.dtCenter} {xs.dtRange} {xs.dfRange} {xs.smpStart} {xs.smpCount} {xs.snrThreshold}";
  36. p.StartInfo.CreateNoWindow = true;
  37. p.StartInfo.RedirectStandardError = true;
  38. p.StartInfo.RedirectStandardOutput = true;
  39. p.StartInfo.UseShellExecute = false;
  40. p.Start();
  41. Stopwatch stopWatch = new Stopwatch();
  42. stopWatch.Start();
  43. p.WaitForExit();
  44. stopWatch.Stop();
  45. TimeSpan ts = stopWatch.Elapsed;
  46. var str = p.StandardOutput.ReadToEnd();
  47. res.FromLine(str);
  48. res.file1 = xs.file1;
  49. res.file2 = xs.file2;
  50. res.tm = stopWatch.Elapsed.TotalSeconds;
  51. res.smpstart = xs.smpStart;
  52. res.smplen = xs.smpCount;
  53. });
  54. return res;
  55. }
  56. public static async Task<IEnumerable<DmcResult>> DmcCheckAsync(string fileName, double fs)
  57. {
  58. return await Task.Run(() =>
  59. {
  60. p.StartInfo.FileName = Path.Combine(p.StartInfo.WorkingDirectory, "xcorr\\dmc.exe");
  61. p.StartInfo.Arguments = $"all \"{fileName}\" -f {fs} -c --dmfirst";
  62. p.StartInfo.CreateNoWindow = true;
  63. p.StartInfo.RedirectStandardError = true;
  64. p.StartInfo.RedirectStandardOutput = true;
  65. p.StartInfo.UseShellExecute = false;
  66. p.Start();
  67. Stopwatch stopWatch = new Stopwatch();
  68. stopWatch.Start();
  69. p.WaitForExit();
  70. stopWatch.Stop();
  71. TimeSpan ts = stopWatch.Elapsed;
  72. var str = p.StandardOutput.ReadToEnd();
  73. return ConvertDmcResult(str);
  74. });
  75. }
  76. public static IEnumerable<DmcResult> ConvertDmcResult(string res)
  77. {
  78. var lines = res.Split(Environment.NewLine.ToArray(), StringSplitOptions.RemoveEmptyEntries);
  79. foreach (var line in lines)
  80. {
  81. var items = line.Split('\t');
  82. if (items.Length < 2) continue;
  83. int start = int.Parse(items[0]);
  84. int length = int.Parse(items[1]);
  85. string userName = "";
  86. if (items.Length >= 3)
  87. userName = items[2];
  88. yield return new DmcResult(start, length, userName);
  89. }
  90. }
  91. public static void Stop()
  92. {
  93. try
  94. {
  95. p.Kill();
  96. }
  97. catch (Exception)
  98. {
  99. }
  100. }
  101. }
  102. }