资源简介
可以快速读取出SEG-Y格式的地震数据的详细信息,例如道头,采样点数,线数,道数等,方便快捷。
代码片段和文件信息
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 2014-06-03 17:54 SegReader\SegReader\bin\Debug\SegReader.dll
文件 26112 2014-06-03 17:54 SegReader\SegReader\bin\Debug\SegReader.pdb
文件 5605 2014-06-03 17:54 SegReader\SegReader\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache
文件 674 2014-04-12 09:43 SegReader\SegReader\obj\Debug\SegReader.csproj.FileListAbsolute.txt
文件 9216 2014-06-03 17:54 SegReader\SegReader\obj\Debug\SegReader.dll
文件 26112 2014-06-03 17:54 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 2014-06-03 17:55 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 2014-06-03 17:54 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
----------- --------- ---------- ----- ----
130747 24
- 上一篇:MCGS触摸屏西门子s7_1200驱动
- 下一篇:没有了
评论
共有 条评论