📄 seg2input.m
字号:
function [record,recordid,sampleint,numsample,shotno,stationsum,firststation] = seg2input(sg2file)
% 自编
format long e;
record(1:500,4096)=0;
recordid=0;
sampleint=0;
numsample=0;
shotno=0;
stationsum=0;
firststation=0;
fileinfo = dir(sg2file); % Fileinfo is a structured array of file information.
[ro, co] = size(fileinfo);
if ro == 0
error(['The file ', sg2file, ' is not in the present working directory.'])
else
lastbyte = fileinfo.bytes; % Pull the size of the file out of fileinfo.
end
dataout.textheader = zeros(40, 80); % Initialize the text header.
fclose('all'); % Close any previously opened segy files.
fid = fopen(sg2file, 'r');% Open the seg2 file for reading.
if fid == -1
error('Unable to open file.')
end
%读文件头
s1=fread(fid, 1, 'uchar');
s2=fread(fid, 1, 'uchar');
if ((s1~=88) & (s2~=58))
return;
end;
tracepoint(1:1000)=0;
revnum=fread(fid, 1, 'int16');
pointbytecount=fread(fid, 1, 'int16');
numtrace=fread(fid, 1, 'int16');
s8=fread(fid, 1, 'uchar');
s9=fread(fid, 1, 'uchar');
s10=fread(fid, 1, 'uchar');
s11=fread(fid, 1, 'uchar');
s12=fread(fid, 1, 'uchar');
s13=fread(fid, 1, 'uchar');
s1431=fread(fid, 18, 'uchar');
for i=1:numtrace
tracepoint(i)=fread(fid, 1, 'int32');
end;
fseek(fid, 32+pointbytecount, 'bof');
temp(1:50,:)=0;
filestring=num2str(temp);
l1=fread(fid, 1, 'int16');
hh=0;
while(0~=l1)
s1=fread(fid, l1-2, 'uchar');
s2=sprintf('%s',s1);
hh=hh+1;
for m=1:size(s1)
filestring(hh,m)=s1(m);
end;
l1=fread(fid, 1, 'int16');
end;
for m=1:hh
if isstr(filestring(m,:))
if findstr(filestring(m,:),'STATION_NUMBERS ');
p1=length(filestring(m,:));
p2=length('STATION_NUMBERS ');
stationsum=str2num(deblank(filestring(m,p2+1:p1)));
end;
if findstr(filestring(m,:),'FIRST_STATION_NUMBER ');
p1=length(filestring(m,:));
p2=length('FIRST_STATION_NUMBER ');
firststation=str2num(deblank(filestring(m,p2+1:p1)));
end;
end;
end;
%读到头
for j=1:numtrace
fseek(fid, tracepoint(j), 'bof');
a1=fread(fid, 1, 'uchar');
a2=fread(fid, 1, 'uchar');
if ((a1~=34) & (a2~=68))
return;
end;
blocklen=fread(fid, 1, 'int16');
datalen=fread(fid, 1, 'int32');
numsample=fread(fid, 1, 'int32');
datatype=fread(fid, 1, 'uchar');
resv=fread(fid, 19, 'uchar');
fseek(fid, tracepoint(j)+32, 'bof');
temp(1:50,:)=0;
tracestring=num2str(temp);
l1=fread(fid, 1, 'int16');
hh=0;
while(0~=l1)
s1=fread(fid, l1-2, 'uchar');
s2=sprintf('%s',s1);
hh=hh+1;
for m=1:size(s1)
tracestring(hh,m)=s1(m);
end;
l1=fread(fid, 1, 'int16');
end;
for m=1:hh
if isstr(tracestring(m,:))
if findstr(tracestring(m,:),'RAW_RECORD ');
p1=length(tracestring(m,:));
p2=length('RAW_RECORD ');
recordid=str2num(deblank(tracestring(m,p2+1:p1)));
end;
if findstr(tracestring(m,:),'SAMPLE_INTERVAL ');
p1=length(tracestring(m,:));
p2=length('SAMPLE_INTERVAL ');
sampleint=str2num(deblank(tracestring(m,p2+1:p1)));
end;
if findstr(tracestring(m,:),'SOURCE_STATION_NUMBER ');
p1=length(tracestring(m,:));
p2=length('SOURCE_STATION_NUMBER ');
shotno=str2num(deblank(tracestring(m,p2+1:p1)));
end;
end;
end;
fseek(fid, blocklen+tracepoint(j), 'bof');
for k=1:numsample
record(j,k)=fread(fid, 1, 'float32');
end;
%plot(1:numsample,record(1,1:numsample));
end;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -