/// <summary> /// Создать временный файл по постоянному файлу /// </summary> public static FileInfo CreateTemporaryFile(IGprFileInfo fileInfo, long headerLength) { short fileVersion = -1; var fi = new FileInfo("filename1"); if (fileInfo == null || fileInfo.StatFileInfo == null) throw new NullReferenceException(Strings.ErrNoStatFileInfo); var tempfile = GetTemporaryFileName(); FileStreamManager.Instance.TurnOnReading(fileInfo.StatFileInfo.FullName); fileVersion = FileStreamManager.Instance.Reader.ReadInt16(); FileStreamManager.Instance.CloseStreams(); switch (fileVersion) { case 1: fi = CreateTemporaryFileFV1(fileInfo, headerLength); break; case 2: fi = CreateTemporaryFileFV2(fileInfo, headerLength); break; case 3: fi = CreateTemporaryFileFV3(fileInfo, headerLength); break; } timeCreated = DateTime.Now; return fi; }
/// <summary> /// Скопировать TempFileInfo из fileInfoFrom в fileInfoTo /// </summary> public void CopyTempFileInfo(IGprFileInfo fileInfoFrom, IGprFileInfo fileInfoTo) { if (fileInfoTo.pythonSettings == null) fileInfoTo.pythonSettings = new PythonSettings(); // Copy RshMemory fileInfoTo.pythonSettings.startType = fileInfoFrom.pythonSettings.startType; fileInfoTo.pythonSettings.bufferSize = fileInfoFrom.pythonSettings.bufferSize; fileInfoTo.pythonSettings.frequency = fileInfoFrom.pythonSettings.frequency; fileInfoTo.pythonSettings.controlSynchro = fileInfoFrom.pythonSettings.controlSynchro; fileInfoTo.pythonSettings.startDelay = fileInfoFrom.pythonSettings.startDelay; fileInfoTo.pythonSettings.preHistory = fileInfoFrom.pythonSettings.preHistory; fileInfoTo.pythonSettings.threshold = fileInfoFrom.pythonSettings.threshold; fileInfoTo.pythonSettings.hysteresis = fileInfoFrom.pythonSettings.hysteresis; fileInfoTo.pythonSettings.waitTime = fileInfoFrom.pythonSettings.waitTime; fileInfoTo.pythonSettings.channels = new RshChannel[fileInfoFrom.pythonSettings.channels.Length]; for (int i = 0; i < fileInfoTo.pythonSettings.channels.Length; i++) { fileInfoTo.pythonSettings.channels[i] = new RshChannel(); fileInfoTo.pythonSettings.channels[i].control = fileInfoFrom.pythonSettings.channels[i].control; fileInfoTo.pythonSettings.channels[i].delta = fileInfoFrom.pythonSettings.channels[i].delta; fileInfoTo.pythonSettings.channels[i].gain = fileInfoFrom.pythonSettings.channels[i].gain; } // Copy RshPort fileInfoTo.pythonSettings.digitalPort = fileInfoFrom.pythonSettings.digitalPort; // other fileInfoTo.AscanLengths = new List<int>(); foreach (int len in fileInfoFrom.AscanLengths) fileInfoTo.AscanLengths.Add(len); }
public FormProperties(IGprFileInfo gprFileInfo, dSaveDefaultSettings saveDefaultSettings) { logger = LogManager.GetLogger("FormProperties"); InitializeComponent(); propsTfl = new GprFileInfo(); CopyTempFileInfo(gprFileInfo, propsTfl); SaveDefaultSettings = saveDefaultSettings; InitializeTxt(); InitializeGroundTypes(); InitializeMainProps(); AcceptButton = this.buttonOk; CancelButton = this.buttonCancel; InitDigitalPort(); tabPageRawProcessor.Controls.Add(new RawDataProcessingTab() { Dock = DockStyle.Fill, NumAscans = ConnectionWrapper.Instance.NumberAscansToProcess, Scenario = ConnectionWrapper.Instance.Processor.Scenario.Select(x => x.Name).ToList() }); // mode.FormProps = this; // mode.SetPropMode(mode.Mode); }
/// <summary> /// Получить RshInitMemory, созданный на основе передаваемого GprFileInfo /// </summary> public static RshInitMemory GetRshInitMemory(IGprFileInfo fileInfo) { var rshMemory = new RshInitMemory(); rshMemory.startType = fileInfo.pythonSettings.startType; rshMemory.bufferSize = fileInfo.pythonSettings.bufferSize; rshMemory.frequency = fileInfo.pythonSettings.frequency; rshMemory.controlSynchro = fileInfo.pythonSettings.controlSynchro; rshMemory.startDelay = fileInfo.pythonSettings.startDelay; rshMemory.beforeHistory = fileInfo.pythonSettings.preHistory; rshMemory.threshold = fileInfo.pythonSettings.threshold; rshMemory.hysteresis = fileInfo.pythonSettings.hysteresis; rshMemory.channels = new RshChannel[fileInfo.pythonSettings.channels.Length]; for (int i = 0; i < fileInfo.pythonSettings.channels.Length; i++) { rshMemory.channels[i] = new RshChannel(); rshMemory.channels[i].control = fileInfo.pythonSettings.channels[i].control; rshMemory.channels[i].delta = fileInfo.pythonSettings.channels[i].delta; rshMemory.channels[i].gain = fileInfo.pythonSettings.channels[i].gain; } return rshMemory; }
/// <summary> /// Получить RshInitPort, созданный на основе передаваемого GprFileInfo /// </summary> public static RshInitPort GetRshInitPort(IGprFileInfo fileInfo) { var rshPort = new RshInitPort(); rshPort.operationType = RshInitPort.OperationTypeBit.Write; if (Settings.Instance.BPI != null) rshPort.portAddress = Settings.Instance.BPI.ports[0].address; rshPort.portValue = fileInfo.pythonSettings.digitalPort; return rshPort; }
/// <summary> /// Создать временный файл по постоянному файлу c fileVersion==1 /// </summary> public static FileInfo CreateTemporaryFileFV1(IGprFileInfo fileInfo, long headerLength) { if (fileInfo == null || fileInfo.StatFileInfo == null) throw new NullReferenceException(Strings.ErrNoStatFileInfo); var tempfile = GetTemporaryFileName(); FileStreamManager.Instance.TurnOnCreating(fileInfo.StatFileInfo.FullName, tempfile, headerLength); var Reader = FileStreamManager.Instance.Reader; var Writer = FileStreamManager.Instance.Writer; for (int i = 0; i < fileInfo.BscanLength(); i++) { Reader.ReadInt32(); for (int j = 0; j < fileInfo.AscanLengths[i]; j++) Writer.Write(Reader.ReadInt16()); } FileStreamManager.Instance.CloseStreams(); timeCreated = DateTime.Now; return new FileInfo(tempfile); }
private void SaveTxtFileHeader(StreamWriter fswrite, IGprFileInfo gprFileInfo) { fswrite.WriteLine(gprFileInfo.fileVersion.ToString()); fswrite.WriteLine(gprFileInfo.BscanLength().ToString()); // python fswrite.WriteLine(gprFileInfo.pythonSettings.startType.ToString()); fswrite.WriteLine(gprFileInfo.pythonSettings.bufferSize.ToString()); fswrite.WriteLine(gprFileInfo.pythonSettings.frequency.ToString()); fswrite.WriteLine(gprFileInfo.pythonSettings.control.ToString()); fswrite.WriteLine(gprFileInfo.pythonSettings.preHistory.ToString()); fswrite.WriteLine(gprFileInfo.pythonSettings.startDelay.ToString()); fswrite.WriteLine(gprFileInfo.pythonSettings.hysteresis.ToString()); fswrite.WriteLine(gprFileInfo.pythonSettings.packetNumber.ToString()); fswrite.WriteLine(gprFileInfo.pythonSettings.threshold.ToString()); fswrite.WriteLine(gprFileInfo.pythonSettings.controlSynchro.ToString()); fswrite.WriteLine(gprFileInfo.pythonSettings.waitTime.ToString()); fswrite.WriteLine(gprFileInfo.pythonSettings.channels.Length.ToString()); for (int i = 0; i < gprFileInfo.pythonSettings.channels.Length; i++) { fswrite.WriteLine(gprFileInfo.pythonSettings.channels[i].control.ToString()); fswrite.WriteLine(gprFileInfo.pythonSettings.channels[i].delta.ToString()); fswrite.WriteLine(gprFileInfo.pythonSettings.channels[i].gain.ToString()); } fswrite.WriteLine(gprFileInfo.pythonSettings.digitalPort.ToString()); fswrite.WriteLine(((Settings.Instance.TestMode) ? 0 : 0));//AConnectionWrapper.Instance.Voltage()).ToString()); // survey fswrite.WriteLine(Settings.Instance.Dt.ToString()); fswrite.WriteLine(Settings.Instance.Dx.ToString()); fswrite.WriteLine(Settings.Instance.Permittivity.ToString()); fswrite.WriteLine(PictureCoords.Zoom.ToString()); fswrite.WriteLine(Settings.Instance.Palette.ToString()); fswrite.WriteLine(Settings.Instance.RepetitionRate.ToString()); // marks //fswrite.WriteLine(gprFileInfo.MarksMgr.Count.ToString()); //foreach (int mark in gprFileInfo.MarksMgr.Keys) //{ // fswrite.WriteLine(mark.ToString()); // fswrite.WriteLine(gprFileInfo.MarksMgr[mark].ToString()); //} }
private void SaveTxtFileData(BinaryReader bReader, StreamWriter sWriter, IGprFileInfo gprFileInfo) { for (int i = 0; i < gprFileInfo.BscanLength(); i++) { sWriter.WriteLine(gprFileInfo.AscanLengths[i].ToString()); sWriter.WriteLine(gprFileInfo.AscansGPS[i]); sWriter.WriteLine(gprFileInfo.AscansTime[i]); if (gprFileInfo.MarksMgr.Contains(i)) sWriter.WriteLine(Convert.ToInt32(gprFileInfo.MarksMgr[i]).ToString()); else sWriter.WriteLine((-1).ToString()); var str = ""; for (int j = 0; j < gprFileInfo.AscanLengths[i]; j++) str += bReader.ReadInt16().ToString() + " "; sWriter.Write(str); } }
public void SubtractAverage(IGprFileInfo gprFileInfo) { // count average in temporary // subtract // that's it var newTempFile = GetTemporaryFileName(); var bscanLength = gprFileInfo.BscanLength(); var avgAscan = new List<double>(); // get average ascan for (int i = 0; i < gprFileInfo.AscanLengths.Max(); i++) avgAscan.Add(0); for (int i = 0; i < bscanLength; i++) { var ascan = ReadTempFilePart(gprFileInfo, i, 1); for (int j = 0; j < ascan[0].Length; j++) avgAscan[j] += ((double)ascan[0][j]) / bscanLength; } // subtract it and write to file FileStreamManager.Instance.TurnOnCreating(gprFileInfo.TempFileInfo.FullName, newTempFile); for (int i = 0; i < gprFileInfo.BscanLength(); i++) { var ascan = new short[gprFileInfo.AscanLengths[i]]; for (int j = 0; j < ascan.Length; j++) { ascan[j] = FileStreamManager.Instance.Reader.ReadInt16(); FileStreamManager.Instance.Writer.Write(Convert.ToInt16( avgAscan[j] == 0 ? 0 : Math.Sign(ascan[j]) * (Math.Abs((double)ascan[j]) - Math.Abs(avgAscan[j])))); } } FileStreamManager.Instance.CloseStreams(); gprFileInfo.TempFileInfo = new FileInfo(newTempFile); }
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /// <summary> /// Сохранить текстовый файл /// </summary> public void SaveTxtFile(FileInfo fi, IGprFileInfo gprFileInfo) { FileStreamManager.Instance.TurnOnTxtCreating(gprFileInfo.TempFileInfo.FullName, fi.FullName); SaveTxtFileHeader(FileStreamManager.Instance.TxtWriter, gprFileInfo); SaveTxtFileData(FileStreamManager.Instance.Reader, FileStreamManager.Instance.TxtWriter, gprFileInfo); }
// /// <summary> // /// Сохранить текстовый файл // /// </summary> // public void ReadTxtFile(FileInfo fi, GprFileInfo gprFileInfo) // { // using (var fsread = new FileStream(gprFileInfo.TempFileInfo.FullName, FileMode.Open)) // { // using (var sReader = new StreamReader(fsread)) // { // ReadTxtFileHeader(sReader, gprFileInfo); // ReadTxtFileData(sReader, gprFileInfo); // } // } // } /// <summary> /// Сохранить Excel файл /// </summary> public void SaveExcelFile(FileInfo fi, IGprFileInfo gprFileInfo) { var workBook = new Workbook(); if (fi.Exists) workBook.Open(fi.FullName); if (!fi.Exists) workBook.Worksheets.RemoveAt(0); // удалить автоматически создавшийся первый пустой лист var indexChannel1 = workBook.Worksheets.Add(); var sheetChannel1 = workBook.Worksheets[indexChannel1]; var indexChannel2 = workBook.Worksheets.Add(); var sheetChannel2 = workBook.Worksheets[indexChannel2]; sheetChannel1.Name = "Канал 1"; sheetChannel2.Name = "Канал 2"; // Записываем данные FileStreamManager.Instance.TurnOnReading(gprFileInfo.TempFileInfo.FullName); var Reader = FileStreamManager.Instance.Reader; var numAscans = Math.Min(gprFileInfo.BscanLength(), MaxBscanLengthExcel); ProgressBarManager.Instance.InitProgressBar("Выгрузка в Excel...", numAscans); for (int i = 0; i < numAscans; i++) { ProgressBarManager.Instance.SetProcessName("а-скан " + (i+1).ToString() + " из " + numAscans); for (int j = 0; j < gprFileInfo.AscanLengths[i]; j++) { if (gprFileInfo.pythonSettings.channels.Length == 1) sheetChannel1.Cells[GetRange(j, i)].Value = Reader.ReadInt16().ToString(); else if (gprFileInfo.pythonSettings.channels.Length == 2) if (j%2 == 0) sheetChannel1.Cells[GetRange(j/2, i)].Value = Reader.ReadInt16().ToString(); else sheetChannel2.Cells[GetRange(j/2, i)].Value = Reader.ReadInt16().ToString(); } ProgressBarManager.Instance.MoveForward(); } ProgressBarManager.Instance.CloseProgressBar(); FileStreamManager.Instance.CloseStreams(); if (gprFileInfo.pythonSettings.channels.Length == 1) workBook.Worksheets.RemoveAt(indexChannel2); workBook.Save(fi.FullName); }
/// <summary> /// Считать кусок временного файла, начиная с такого-то аскана столько-то асканов /// </summary> public List<short[]> ReadTempFilePart(IGprFileInfo gprFileInfo, int startAscan, int length) { if (startAscan + length > gprFileInfo.BscanLength()) throw new NullReferenceException("Trying to read ascans that don't exist"); var bscan = new List<short[]>(); // count the offset var skip = 0; for (int i = 0; i < startAscan; i++) skip += gprFileInfo.AscanLengths[i] * 2; // 2 bytes for each value // read data bscan.Clear(); if (File.Exists(gprFileInfo.TempFileInfo.FullName)) { FileStreamManager.Instance.TurnOnReading(gprFileInfo.TempFileInfo.FullName, skip); for (int i = 0; i < length; i++) { short[] ascan = new short[gprFileInfo.AscanLengths[startAscan + i]]; for (int j = 0; j < ascan.Length; j++) ascan[j] = FileStreamManager.Instance.Reader.ReadInt16(); bscan.Add(ascan); } } return bscan; }
/// <summary> /// Добавить аскан /// </summary> public void AddAscan(short[] ascan, IGprFileInfo gprFileInfo) { if (ascan != null && ascan.Length != 0) { foreach (short val in ascan) FileStreamManager.Instance.Writer.Write(val); gprFileInfo.AscanLengths.Add(ascan.Length); } }