• 大小: 32KB
    文件类型: .rar
    金币: 2
    下载: 1 次
    发布日期: 2021-05-21
  • 语言: C#
  • 标签: C#  SEG-Y文件  

资源简介

使用C#编写的一个读SegY文件的类库,里面有源代码。有问题的可以给我留言交流,原创代码。

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace SegyRead
{
    public class SegYReader
    {
        private SegyVolumeHeader volumeHeaderStruct;
        public List traceData;
        private string fileNamePath;

        public SegYReader(string fileNamePath)
        {

            this.fileNamePath = fileNamePath;
            this.traceData = new List();

        }
        //读取卷头信息
        private void ReadVolumeHeader(Stream stream)
        {
            byte[] temp = new byte[18];
            stream.Seek(12 SeekOrigin.Current);
            stream.Read(temp 0 18);
            Tools.SwapNybbleByteOrder(ref temp 0 9);
            volumeHeaderStruct = (SegyVolumeHeader)Tools.BytesToStruct(temp volumeHeaderStruct.GetType());
        }

        public void Read()
        {
            Stream stream = null;
            FileStream fileStream = null;

            if (!File.Exists(fileNamePath))
            {
                throw new Exception(“文件不存在“);
            }
            else
            {
                 fileStream = new FileStream(fileNamePath FileMode.Open);
            }
            if (fileStream.Length < 3600)
            {
                fileStream.Dispose();
                throw new Exception(“文件格式不正确“);
            }
            else
            {
                stream = new MemoryStream();
                fileStream.CopyTo(stream);
                fileStream.Dispose();

                stream.Seek(3200 SeekOrigin.Begin);
                this.ReadVolumeHeader(stream);
                switch (volumeHeaderStruct.data_sample_format_code)
                {
                    case 1:
                        ReadSampleDataOfIBM(stream);
                        break;//采样数据格式为IBM4字节浮点型
                    case 5:
                        ReadSampleDataOfIEEE(stream);
                        break;//采样数据位4字节IEEE浮点数
                }

                stream.Dispose();
            }
                

        }

        private void ReadSampleDataOfIBM(Stream stream)
        {
            byte[] tempWord = new byte[4];
            byte[] tempNybble = new byte[2];
            int traceIndex;
            int sampleNum;
            int sampleInterval;
            float[] sampleData;

            stream.Seek(3600 SeekOrigin.Begin);
            while (stream.Position < stream.Length)
            {
                //读取道号
                stream.Read(tempWord 0 4);                
                Tools.SwapWordByteOrder(ref tempWord 0 1);
                traceIndex = BitConverter.ToInt32(tempWord 0);
                //读取道采样点数
                stream.Seek(110 SeekOrigin.Current);
                stream.Read(tempNybble 0 2);
                Tools.SwapNybbleByteOrder(ref tempNybble 0 1);
                sampleNum = BitConverter.ToInt16(tempNybble 

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件       9216  2012-05-03 09:42  SegReader\SegReader\bin\Debug\SegReader.dll

     文件      24064  2012-05-03 09:42  SegReader\SegReader\bin\Debug\SegReader.pdb

     文件       5613  2012-05-03 09:42  SegReader\SegReader\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache

     文件        347  2012-03-14 15:20  SegReader\SegReader\obj\Debug\SegReader.csproj.FileListAbsolute.txt

     文件       9216  2012-05-03 09:42  SegReader\SegReader\obj\Debug\SegReader.dll

     文件      24064  2012-05-03 09:42  SegReader\SegReader\obj\Debug\SegReader.pdb

     文件       1370  2012-03-14 15:15  SegReader\SegReader\Properties\AssemblyInfo.cs

     文件       2483  2012-05-03 09:42  SegReader\SegReader\SegReader.csproj

     文件       4014  2012-05-03 09:38  SegReader\SegReader\SegYReader.cs

     文件       1200  2012-03-14 15:16  SegReader\SegReader\SegyTraceData.cs

     文件       7748  2012-03-14 15:16  SegReader\SegReader\SegyTraceHeader.cs

     文件       3596  2012-03-14 15:16  SegReader\SegReader\SegyVolumeHeader.cs

     文件       5348  2012-05-03 09:21  SegReader\SegReader\Tools.cs

     文件        917  2012-03-14 15:15  SegReader\SegReader.sln

    ..A..H.     27136  2012-05-03 09:42  SegReader\SegReader.suo

     目录          0  2012-08-08 14:49  SegReader\SegReader\obj\Debug\TempPE

     目录          0  2012-08-17 16:00  SegReader\SegReader\bin\Debug

     目录          0  2012-08-08 14:49  SegReader\SegReader\bin\Release

     目录          0  2012-08-17 16:00  SegReader\SegReader\obj\Debug

     目录          0  2012-08-17 16:00  SegReader\SegReader\bin

     目录          0  2012-08-17 16:00  SegReader\SegReader\obj

     目录          0  2012-08-17 16:00  SegReader\SegReader\Properties

     目录          0  2012-08-17 16:00  SegReader\SegReader

     目录          0  2012-08-17 16:00  SegReader

----------- ---------  ---------- -----  ----

               126332                    24


评论

共有 条评论