示例#1
0
        /// <summary>
        /// Reads a single trace from the file.
        /// </summary>
        /// <param name="traceIndex">The trace index as it appears in squence in the file</param>
        /// <returns>The segy trace</returns>
        public SegyTrace ReadTrace(long traceIndex)
        {
            CodeContract.Requires(traceIndex < TraceCount, "Trace index to read must be less than the number of traces in the file.");
            CodeContract.Requires(traceIndex >= 0, "Trace index must be greater than or equal to 0");

            var islilEndian = IsLittleEndian;

            _stream.Seek(0, SeekOrigin.Begin);

            var textFileHeadersCount = FileTextualHeaders.Length;
            var binaryHeader         = FileBinaryHeader;
            var dataStartIndex       = TextHeaderBytesCount + BinaryHeaderBytesCount + TextHeaderBytesCount * (textFileHeadersCount - 1);
            var sampleFormat         = (FormatCode)binaryHeader.DataSampleFormatCode;
            int sampleSz             = SizeFrom(sampleFormat);

            // as per rev 1, all data values are assumed big endian
            var ns = binaryHeader.SamplesPerTraceOfFile;
            var initStreamPosition = dataStartIndex + (240 + ns * sampleSz) * traceIndex;

            CodeContract.Assume(initStreamPosition <= _stream.Length, "initial trace index exceeds file length.");
            _stream.Seek(initStreamPosition, SeekOrigin.Begin);

            var traceHeaderByteArr = _reader.ReadBytes(TraceHeaderBytesCount);
            var trHeader           = SegyTraceHeader.From(traceHeaderByteArr, islilEndian);
            var traceDataBytesSz   = trHeader.SampleCount * sampleSz;
            var traceDataBytes     = _reader.ReadBytes(traceDataBytesSz);
            var traceData          = GetData(traceDataBytes, sampleFormat, trHeader.SampleCount);
            var seismicTrace       = new SegyTrace {
                ComponentAxis = 0, Data = traceData, Header = trHeader
            };

            return(seismicTrace);
        }
示例#2
0
        /// <summary>
        /// Appends a single segy trace to the end of the file or trace series.
        /// </summary>
        /// <param name="sgyTrace">The trace to write.</param>
        public void Write(SegyTrace sgyTrace)
        {
            CodeContract.Requires(sgyTrace.Data.Length != 0);

            if (TraceCount == 0)
            {
                TraceSampleCount = sgyTrace.Data.Length;
            }

            CodeContract.Assume(sgyTrace.Data.Length == TraceSampleCount);

            _writer.BaseStream.Position = _writer.BaseStream.Length;
            _writer.Write(sgyTrace.GetBytes());
            TraceCount++;
        }