function writesegyfile(sgyfile, datain, sampint, numsamps, numtraces, segfmt, byteorder)
if nargin < 3
error('Invalid number of arguments: at least 3 required (segyfile, datain, sampint)');
end
if nargin < 4
numsamps = size(datain,1);
end
if nargin < 5
numtraces = size(datain,2);
end
if nargin < 6
segfmt = 5;
end
if nargin < 7
byteorder = 'be';
end
switch lower(byteorder)
case {'be', 'bigendian', 'ieee-be'}
platform='ieee-be';
case {'le', 'littleendian', 'ieee-le'}
platform = 'ieee-le';
otherwise
error(['Invalid byte order parameter: ' byteorder]);
end
fid = fopen(sgyfile, 'w', platform);
textLine{1} = char(['File generated ' datestr(now)]);
switch segfmt
case 1
textLine{1} = 'IBM Floating point fmt (not implemented)';
dformat = 'float32'; % 4 bytes, should be IBM floating point
case 2
textLine{2} = '4-byte integer format';
dformat = 'int32'; % 4 bytes, signed.
case 3
textLine{3} = '2-byte integer format';
dformat = 'int16'; % 2 bytes, signed.
case 4
textLine{4} = 'WARNING BAD DATA: Fixed point w/gain code format (not implemented)'
error('Can not write this format. (Fixed point with gain code.)');
case 5
textLine{5} = 'IEEE Floating point format';
dformat = 'float32'; % 4 bytes presumably IEEE floating point
case 8
textLine{8} = '1-byte integer format';
dformat = 'uchar8'; % 4 bytes presumably IEEE floating point
otherwise
error(['invalid format specified: ', num2str(segfmt)]);
end
textLine{39} = 'SEG Y rev1'; % ooh, bleeding edge
textLine{40} = 'END EBCDIC'; %
% Next line should contain 80 spaces
textLine{41} = ' ';
for i = 1:40
if isempty(textLine{i})
textLine{i} = ' ';
end
end
textHdrBlock = char(textLine);
textHdrBlock = [reshape(sprintf('C%2d ',1:40),4,40)' textHdrBlock(1:40,1:76)];
textHdrBlock = ascii2ebcdic(textHdrBlock);
count = fwrite(fid, textHdrBlock', 'uchar');
if count ~= 3200
error(['EBCDIC header is too short. Size is only ', num2str(count), '.']);
end
temp = zeros(27,1);
temp(6) = sampint*1000000;
temp(8) = numsamps;
temp(10) = segfmt;
if (fwrite(fid, temp(1:3), 'ulong') ~= 3) | ...
(fwrite(fid, temp(4:27), 'ushort') ~= 24) | ...
(fwrite(fid, zeros(170,1), 'ushort') ~= 170) ;
error('The binary header has been truncated.')
end
clear temp
tracewrit = 1;
trcount = 0;
traceheader = zeros(120,1);
traceheader(floor((29+1)/2)) = 1; % seismic data
traceheader(floor((35+1)/2)) = 1; % production data
traceheader(floor((115+1)/2)) = numsamps; % number of samples for this trace
while tracewrit <= numtraces
trcount = fwrite(fid, traceheader, 'ushort');
count = fwrite(fid, datain(:, tracewrit), dformat);
if count ~= numsamps
error(['Problem writing trace ', num2str(tracewrit), '.'])
end
tracewrit = tracewrit + 1;
end
fclose(fid);
读取和写入地震segy文件的matlab代码
4星 · 超过85%的资源 需积分: 49 154 浏览量
2013-06-04
16:57:44
上传
评论 10
收藏 2KB RAR 举报
explosionys
- 粉丝: 4
- 资源: 7
最新资源
- 基于Qt+opencv+C++实现图像旋转+自动&&手动+直线检测,角度计算+界面操作+源码(期末大作业&课程设计&项目开发)
- 基于servlet的简单游戏管理系统
- matlab基于混沌系统的图像加密.zip
- Fortran语言教程,详细地介绍了Fortran语言
- (函数)图论中最短路径计算D算法MATLAB源代码,修改网络上D算法的错误,并编写通用的MATLAB函数.rar
- 基于matlab 2Dijkstra最短路径算法的matlab程序,希望对大家有所帮助.zip
- python入门学习,基础语法,用法等.zip
- Swift代码转换指南(Swift Swift Code Convension Guide .)
- Python入门到精通.zip
- 基于QT+C++开发的炫酷九宫格主界面+源码
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
- 1
- 2
- 3
前往页