float[] GetSecondLead(string fileName) { IECGFormat format = null; var fmt = "SCP-ECG"; IECGReader reader = ECGConverter.Instance.getReader(fmt); ECGConfig cfg = ECGConverter.Instance.getConfig(fmt); format = reader.Read(fileName, 0, cfg); Signals _CurrentSignal; format.Signals.getSignals(out _CurrentSignal); if (_CurrentSignal != null) { for (int i = 0, en = _CurrentSignal.NrLeads; i < en; i++) { ECGTool.NormalizeSignal(_CurrentSignal[i].Rhythm, _CurrentSignal.RhythmSamplesPerSecond); } } Signals sig = _CurrentSignal.CalculateTwelveLeads(); return(Array.ConvertAll(sig.GetLeads()[1].Rhythm, x => (float)(x))); }
public void Run() { try { if (_NoArgs) { Help(); } else if (_BadArgs) { Error(); Help(); } else { if (_InType != null) { converter.waitForLoadingAllPlugins(); } IECGReader reader = _InType == null ? new UnknownECGReader() : converter.getReader(_InType); if (reader == null) { Console.Error.WriteLine("Error: no reader provided by input type!"); return; } ECGConfig config1 = ECGConverter.Instance.getConfig(_InType); if (config1 != null) { for (int i = 0; i < _Config.Count; i++) { config1[(string)_Config.GetKey(i)] = (string)_Config.GetByIndex(i); } } IECGFormat src = reader.Read(_InFile, _InFileOffset, config1); if (src == null || !src.Works()) { Console.Error.WriteLine("Error: {0}", reader.getErrorMessage()); return; } if ((_BufferedSecondsToLoad > 0) || (_BufferedOffsetToLoad > 0)) { ECGConversion.ECGSignals.Signals sigs = null; if ((src.Signals.getSignals(out sigs) == 0) && sigs.IsBuffered) { ECGConversion.ECGSignals.BufferedSignals bs = (ECGConversion.ECGSignals.BufferedSignals)sigs; int start = 0, end = 0; start = bs.RealRhythmStart + (_BufferedOffsetToLoad * bs.RhythmSamplesPerSecond); end = (_BufferedSecondsToLoad == int.MaxValue) ? _BufferedSecondsToLoad : start + (_BufferedSecondsToLoad * bs.RhythmSamplesPerSecond); if (start > bs.RealRhythmEnd) { start = bs.RealRhythmEnd; } if (end > bs.RealRhythmEnd) { end = bs.RealRhythmEnd; } if (start < end) { bs.LoadSignal(start, end); src.Signals.setSignals(bs); } } } IECGManagementSystem manSys = _OutFile == null ? null : converter.getECGManagementSystem(_OutType); config1 = ECGConverter.Instance.getConfig(manSys == null ? _OutType : manSys.FormatName); ECGConfig config2 = manSys == null ? null : manSys.Config; for (int i = 0; i < _Config.Count; i++) { if (config1 != null) { config1[(string)_Config.GetKey(i)] = (string)_Config.GetByIndex(i); } if (config2 != null) { config2[(string)_Config.GetKey(i)] = (string)_Config.GetByIndex(i); } } if ((config1 != null) && !config1.ConfigurationWorks()) { Console.Error.WriteLine("Error: Bad Configuration for ECG Format!"); return; } if ((config2 != null) && !config2.ConfigurationWorks()) { Console.Error.WriteLine("Error: Bad Configuration for ECG Management System!"); return; } if (manSys == null) { IECGFormat dst = src.GetType() == ECGConverter.Instance.getType(_OutType) ? src : null; if (dst == null) { if ((src.Demographics != null) && (src.Demographics.PatientID == null)) { src.Demographics.PatientID = _PatientId; } ECGConverter.Instance.Convert(src, _OutType, config1, out dst); } if ((dst == null) || !dst.Works()) { Console.Error.WriteLine("Error: Conversion Failed!"); return; } if (_Anonymize) { dst.Anonymous(); } if ((_PatientId != null) && (dst.Demographics != null)) { dst.Demographics.PatientID = _PatientId; } ECGWriter.Write(dst, _OutFile, true); if (ECGWriter.getLastError() != 0) { Console.Error.WriteLine("Error: {0}", ECGWriter.getLastErrorMessage()); } } else { if (manSys.ConfiguredToSave()) { if (_Anonymize) { src.Anonymous(); } manSys.SaveECG(src, _PatientId, config1); } else { Console.Error.WriteLine("Error: Not configured to store!"); } } } } catch (Exception ex) { Console.Error.WriteLine("Error: {0}", ex.ToString()); } }