Exemplo n.º 1
0
        /// <summary>
        /// Sets value in the trace header
        /// </summary>
        /// <param name="val">value as string</param>
        /// <param name="position">position in the header as per Zebra convention</param>
        /// <param name="buffer">buffer to get data from</param>
        public static void SetValue(string val, int position, byte[] buffer)
        {
            position--;
            NumberUnion nu = new NumberUnion();

            if (c_Sizes[position] == 2)
            {
                short t = 0;
                try
                {
                    t = Convert.ToInt16(val);
                }
                catch (Exception) { }
                BufferConverter.SetBytesInt16_BE(buffer, nu, t, c_Offsets[position]);
            }
            if (c_Sizes[position] == 4)
            {
                int t = 0;
                try
                {
                    t = Convert.ToInt32(val);
                }
                catch (Exception) { }
                BufferConverter.SetBytesInt32_BE(buffer, nu, t, c_Offsets[position]);
            }
        }
Exemplo n.º 2
0
        private byte[] PrepareEBCDIC()
        {
            byte[]      EBCDICHeader = new byte[3200];
            NumberUnion fu           = new NumberUnion();

            for (int i = 0; i < 40; i++)
            {
                string s = dataGridView1.Rows[i].Cells[1].Value.ToString();
                if (s == null)
                {
                    s = "                                                                                ";
                }
                if (s.Length > 80)
                {
                    s = s.Substring(0, 80);
                }
                if (s.Length < 80)
                {
                    s = s.PadRight(80);
                }
                myFile.Parameters[i].Value = s;
                BufferConverter.SetEBCDICBytesString(EBCDICHeader, fu, s, 80, 80 * i);
            }
            return(EBCDICHeader);
        }
Exemplo n.º 3
0
        private void FloatBufferLoadProcessor(FileStream reader, int dimension)
        {
            long startPosition = m_Parent.DataStartPosition;
            int  recordWidth   = (int)m_Parent.RecordWidth;
            int  offset        = (this.LogColumnStart + dimension + 1) << 2;

            reader.Seek(startPosition, SeekOrigin.Begin);
            byte[]      buffer = new byte[recordWidth];
            NumberUnion nu     = new NumberUnion();

            while (true)
            {
                int i = reader.Read(buffer, 0, buffer.Length);
                if (i < buffer.Length)
                {
                    break;
                }
                double d = Convert.ToDouble(BufferConverter.GetBytesFloat(buffer, nu, offset));
                if (d <= -1.0e30)
                {
                    d = Double.NaN;
                }
                Data.Add(d);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Creates the constant from the string input
        /// </summary>
        /// <param name="input">string as in SEG-Y EBCDIC Header file</param>
        public SEGY_Constant(string name, string unit, int location, int type, byte[] input, string description)
        {
            this.Name        = name;
            this.Unit        = unit;
            this.Location    = location;
            this.Type        = type;
            this.Description = description;
            NumberUnion nu = new NumberUnion();

            switch (type)
            {
            case SEGY_Constant.Int16:
                this.Value = BufferConverter.GetBytesInt16_BE(input, nu, location).ToString();
                break;

            case SEGY_Constant.UInt16:
                this.Value = BufferConverter.GetBytesUInt16_BE(input, nu, location).ToString();
                break;

            case SEGY_Constant.Int32:
                this.Value = BufferConverter.GetBytesInt32_BE(input, nu, location).ToString();
                break;

            default: break;
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Sets value to the buffer
        /// </summary>
        /// <param name="Buffer"></param>
        public void SetBuffer(byte[] Buffer)
        {
            NumberUnion nu = new NumberUnion();

            switch (Type)
            {
            case LDF_Constant.Int16:
                BufferConverter.SetBytesInt16_BE(Buffer, nu, Convert.ToInt16(Value), Location);
                break;

            case LDF_Constant.UInt16:
                BufferConverter.SetBytesUInt16_BE(Buffer, nu, Convert.ToUInt16(Value), Location);
                break;

            case LDF_Constant.Int32:
                BufferConverter.SetBytesInt32_BE(Buffer, nu, Convert.ToInt32(Value), Location);
                break;

            case LDF_Constant.Float32:
                BufferConverter.SetBytesFloat_BE(Buffer, nu, Convert.ToSingle(Value) / ConversionFactor, Location);
                break;

            case LDF_Constant.String:
                string v = (Value.Length > Length) ? Value.Substring(0, Length) : Value;
                BufferConverter.SetBytesString(Buffer, nu, v, Length + 1, Location);
                break;

            default: break;
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Sets value to the buffer
        /// </summary>
        /// <param name="Buffer"></param>
        public void GetBuffer(byte[] Buffer)
        {
            NumberUnion nu = new NumberUnion();

            switch (Type)
            {
            case LDF_Constant.Int16:
                this.Value = BufferConverter.GetBytesInt16_BE(Buffer, nu, Location).ToString();
                break;

            case LDF_Constant.UInt16:
                this.Value = BufferConverter.GetBytesUInt16_BE(Buffer, nu, Location).ToString();
                break;

            case LDF_Constant.Int32:
                this.Value = BufferConverter.GetBytesInt32_BE(Buffer, nu, Location).ToString();
                break;

            case LDF_Constant.Float32:
                this.Value = BufferConverter.GetBytesFloat_BE(Buffer, nu, Location).ToString();
                break;

            case LDF_Constant.String:
                this.Value = BufferConverter.GetBytesString(Buffer, nu, Length, Location);
                break;

            default: break;
            }
        }
Exemplo n.º 7
0
        /// <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);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Sets buffer to float trace
        /// </summary>
        /// <param name="trace">trace as floating points</param>
        /// <param name="buffer">buffer to get data from</param>
        public static void SetTraceData(float[] trace, byte[] buffer)
        {
            NumberUnion nu = new NumberUnion();

            for (int i = 0, j = 240; i < trace.Length; i++, j += 4)
            {
                BufferConverter.SetBytesIBM(buffer, nu, trace[i], j);
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// Converts buffer float trace
        /// </summary>
        /// <param name="buffer">buffer to get data from</param>
        /// <returns>Float trace</returns>
        public static float[] GetTraceData(byte[] buffer)
        {
            float[]     tmp = new float[(buffer.Length - 240) / 4];
            NumberUnion nu  = new NumberUnion();

            for (int i = 0, j = 240; i < tmp.Length; i++, j += 4)
            {
                tmp[i] = BufferConverter.GetBytesIBM(buffer, nu, j);
            }
            return(tmp);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Creates the constant from the string input
        /// </summary>
        /// <param name="input">string as in SEG-Y EBCDIC Header file</param>
        public SEGY_Constant(int line, byte[] input)
        {
            int         offset = line * 80;
            NumberUnion nu     = new NumberUnion();
            string      s      = BufferConverter.GetEBCDICBytesString(input, nu, 3, offset);

            if (s.Length < 3)
            {
                line++;
                s = "C" + line.ToString().PadLeft(2);
            }
            Name        = s;
            Value       = BufferConverter.GetEBCDICBytesString(input, nu, 77, offset);
            Unit        = "";
            Description = "Comment line " + s + ".";
        }
Exemplo n.º 11
0
        /// <summary>
        /// Gets value in the trace header as int
        /// </summary>
        /// <param name="position">position in the header as per Zebra convention</param>
        /// <param name="buffer">buffer to get data from</param>
        public static int GetIntValue(int position, byte[] buffer)
        {
            position--;
            NumberUnion nu = new NumberUnion();

            if (c_Sizes[position] == 2)
            {
                short t = BufferConverter.GetBytesInt16_BE(buffer, nu, c_Offsets[position]);
                return(Convert.ToInt32(t));
            }
            if (c_Sizes[position] == 4)
            {
                int t = BufferConverter.GetBytesInt32_BE(buffer, nu, c_Offsets[position]);
                return(t);
            }
            return(0);
        }
        /// <summary>
        /// Converts double number into bit representation.
        /// </summary>
        /// <param name="number">Double number to be converted.</param>
        /// <returns>String of bits.</returns>
        public static string DoubleToBits(this double number)
        {
            NumberUnion union = new NumberUnion();

            union.dNumber = number;

            StringBuilder result = new StringBuilder();

            for (int i = 0; i < 64; i++)
            {
                result.Append(((union.lNumber & 1) == 1) ? "1" : "0");
                union.lNumber >>= 1;
            }

            char[] resultArray = result.ToString().ToCharArray();
            Array.Reverse(resultArray);

            return(new string(resultArray));
        }
Exemplo n.º 13
0
        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);
            }
        }
Exemplo n.º 14
0
        private void DoubleBufferSaveProcessor(FileStream writer, int dimension)
        {
            long startPosition = m_Parent.DataStartPosition;

            writer.Seek(startPosition, SeekOrigin.Begin);
            byte[]      buffer = new byte[8];
            NumberUnion nu     = new NumberUnion();

            for (int i = 0; i < Data.Count; i++)
            {
                double d = Data[i];
                if (Double.IsNaN(d))
                {
                    d = -1.0e30;
                }
                BufferConverter.SetBytesDouble(buffer, nu, d, 0);
                writer.Write(buffer, 0, buffer.Length);
                writer.Seek(m_Parent.RecordWidth - 8, SeekOrigin.Current);
            }
        }
Exemplo n.º 15
0
        private void DoubleBufferLoadProcessor(FileStream reader, int dimension)
        {
            long startPosition = m_Parent.DataStartPosition;

            reader.Seek(startPosition, SeekOrigin.Begin);
            byte[]      buffer = new byte[8];
            NumberUnion nu     = new NumberUnion();

            while (true)
            {
                int i = reader.Read(buffer, 0, buffer.Length);
                if (i <= 0)
                {
                    break;
                }
                double d = BufferConverter.GetBytesDouble(buffer, nu, 0);
                if (d <= -1.0e30)
                {
                    d = Double.NaN;
                }
                Data.Add(d);
                reader.Seek(m_Parent.RecordWidth - 8, SeekOrigin.Current);
            }
        }
        /// <summary>
        /// Converts double number into bit representation.
        /// </summary>
        /// <param name="number">Double number to converting.</param>
        /// <returns>String of bits.</returns>
        public static string ConvertToString(this double number)
        {
            NumberUnion union = new NumberUnion(number);

            return(union.ToLong().Convertation());
        }