/// <summary> /// Changes the channel units /// </summary> /// <param name="UnitFrom">Unit name to change from. If no match, channel is not changing</param> /// <param name="UnitTo">Unit name to change to</param> /// <param name="gain">Conversion gain</param> /// <param name="offset">Conversion offset</param> public override bool ChangeUnits(string UnitFrom, string UnitTo, double gain, double offset) { if (this.Unit != UnitFrom) { return(false); } this.Unit = UnitTo; string filename = m_Parent.LogDataName; if (!File.Exists(filename)) { return(false); } FileStream reader_writer = File.Open(filename, FileMode.Open, System.IO.FileAccess.ReadWrite, FileShare.Read); long startPosition = m_Parent.DataStartPosition + (long)((this.LogColumnStart + 1) << 2); reader_writer.Seek(startPosition, SeekOrigin.Begin); byte[] buffer = new byte[LogDimension << 2]; long step = (long)(LogDimension << 2); NumberUnion nu = new NumberUnion(); long totallength = (reader_writer.Length - m_Parent.DataStartPosition) / m_Parent.RecordWidth; for (long k = 0; k < totallength; k++) { int i = reader_writer.Read(buffer, 0, buffer.Length); if (i < buffer.Length) { break; } for (int j = 0; j < step; j += 4) { double d = Convert.ToDouble(BufferConverter.GetBytesFloat(buffer, nu, j)); if (d <= -1.0e30) { continue; } d = d * gain + offset; BufferConverter.SetBytesFloat(buffer, nu, Convert.ToSingle(d), j); } reader_writer.Seek(-step, SeekOrigin.Current); reader_writer.Write(buffer, 0, buffer.Length); reader_writer.Seek(m_Parent.RecordWidth - step, SeekOrigin.Current); } reader_writer.Close(); if (!Double.IsNaN(this.Average)) { this.Average = this.Average * gain + offset; } if (!Double.IsNaN(this.MinValue)) { this.MinValue = this.MinValue * gain + offset; } if (!Double.IsNaN(this.MaxValue)) { this.MaxValue = this.MaxValue * gain + offset; } return(true); }
private void FloatBufferSaveProcessor(FileStream writer, int dimension) { long startPosition = m_Parent.DataStartPosition + (long)((this.LogColumnStart + dimension + 1) << 2); writer.Seek(startPosition, SeekOrigin.Begin); byte[] buffer = new byte[4]; NumberUnion nu = new NumberUnion(); for (int i = 0; i < Data.Count; i++) { double d = Data[i]; if (Double.IsNaN(d)) { d = -1.0e30; } BufferConverter.SetBytesFloat(buffer, nu, Convert.ToSingle(d), 0); writer.Write(buffer, 0, buffer.Length); writer.Seek(m_Parent.RecordWidth - 4, SeekOrigin.Current); } }