예제 #1
0
        /// <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);
        }
예제 #2
0
        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());
            //}
        }
예제 #3
0
 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);
     }
 }
예제 #4
0
        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);
        }
예제 #5
0
        //        /// <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);
        }
예제 #6
0
        /// <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;
        }