forked from cultpenguin/segymat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
WriteSegyStructure.m
88 lines (73 loc) · 3.05 KB
/
WriteSegyStructure.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
% WriteSegyStructure : writes data to disk using SEGY REV 0 and 1 standards.
%
% EX
% WriteSegyStructure('datacube.segy',SegyHeader,SegyTraceHeaders,Data);
%
% To force the use of SEG Y revision 0
% WriteSegyStructure('datacube.segy',SegyHeader,SegyTraceHeaders,Data,'revision',0);
% To force the use of SEG Y revision 1
% WriteSegyStructure('datacube.segy',SegyHeader,SegyTraceHeaders,Data,'revision',1);
% To force the data sampling format to be IBM Floating Point
% WriteSegyStructure('datacube.segy',SegyHeader,SegyTraceHeaders,Data,'dsf',1);
%
% To force the use of SEG Y revision 0 and data sampling format IEEE :
% WriteSegyStructure('datacube.segy',SegyHeader,SegyTraceHeaders,Data,'revision',1,'dsf',5);
%
% See the dokumentation for for proper values of 'dsf'
%
%
%
% (C) 2001-2004, Thomas Mejer Hansen, [email protected]/[email protected]
%
% This program is free software; you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation; either version 2 of the License, or
% (at your option) any later version.
%
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with this program; if not, write to the Free Software
% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
%
%
function SegyHeader=WriteSegyStructure(filename,SegyHeader,SegyTraceHeaders,Data,varargin)
SegymatVerbose(sprintf('%s: writing to %s',mfilename,filename),0)
for i=1:2:length(varargin)
var=varargin{i};
val=varargin{i+1};
eval([var,'=[',num2str(val),'];']);
end
if exist('revision')==1,
if revision==0,
SegyHeader.SegyFormatRevisionNumber=0;
else
SegyHeader.SegyFormatRevisionNumber=256;
end
SegymatVerbose([mfilename,' : Using SEG Y revision ',num2str(revision)])
end
if exist('dsf'),
SegyHeader.DataSampleFormat=dsf;
SegymatVerbose([mfilename,' : Using Data Sample Format ',num2str(dsf)])
end
segyid = fopen(filename,'w','b'); % ALL DISK FILES ARE IN BIG
% ENDIAN FORMAT, ACCORDING SEG
% Y rev 1
% JUST SOME INFORMATION TO WRITE TO SCREEN :
Revision=SegyHeader.SegyFormatRevisionNumber;
if Revision>0, Revision=1; end
%Format=SegyHeader.Rev(Revision+1).DataSampleFormat(SegyHeader.DataSampleFormat).name;
%txt=['SegyRevision ',sprintf('%0.4g',Revision),', ',Format,'(',num2str(SegyHeader.DataSampleFormat),')'];
txt='';
SegyHeader=PutSegyHeader(segyid,SegyHeader);
ntraces=size(Data,2);
for i=1:ntraces;
if (i/1000)==round(i/1000),
SegymatVerbose([mfilename,': writing trace ',num2str(i),' of ',num2str(ntraces),', filepos=',num2str(ftell(segyid))],0)
end
PutSegyTrace(segyid,Data(:,i),SegyTraceHeaders(i),SegyHeader);
end
fclose(segyid);