forked from cultpenguin/segymat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MergeSegy.m
60 lines (51 loc) · 1.23 KB
/
MergeSegy.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
% MergeSegy : Merge multiple SEGY files
%
% Example :
% MergeSegy('*.sgy','merge.sgy')
%
% f{1}='file1.sgy';
% f{2}='file2.sgy';
% f{3}='file3.sgy';
% MergeSegy(f,'merge.sgy')
%
%
% Note: All imput segy files must have the same constant trace length
% The SEGY header of the merged SEGY file will be the SEGY header
% form the first input SEGY file.
%
%
function [file_out,D,STH,SegyHeader]=MergeSegy(files,file_out)
if nargin<2
file_out='segymerge.sgy';
end
if isstr(files)
file_names=dir(files);
end
if iscell(files);
for i=1:length(files);
file_names(i).name=files{i};
end
end
for i=1:length(file_names);
[Data,SegyTraceHeaders,SegyHeader]=ReadSegy(file_names(i).name);
if i==1;
ss=size(Data);
else
%check size
if (length(find(ss==size(Data)))~=2)
SegymatVerbose(sprintf('%s : Data sizes differs',mfilename),-1);
end
end
if i==1;
D=Data;
STH=SegyTraceHeaders;
else
n_sth=length(STH);
for j=1:length(SegyTraceHeaders)
STH(j+n_sth)=SegyTraceHeaders(j);
STH(j+n_sth).TraceNumber=j;
end
D=[D Data];
end
end
WriteSegyStructure(file_out,SegyHeader,STH,D);