forked from cultpenguin/segymat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
GetSegyTraceHeader.m
200 lines (167 loc) · 8.67 KB
/
GetSegyTraceHeader.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
% GetSegyTraceHeader : Reads a seg y trace, data and header
%
% [SegyTraceHeader]=GetSegyTraceHeader(segyid,TraceStart);
%
%
% (C) 2001-2012 Thomas Mejer Hansen, [email protected]
%
% Revisions:
% 07/2008 Kristian Stormark (<[email protected]>) : Reduce the
% number of disc operations causing a significant speed up
%
% 03/2012 Cleaned up after suggestion from Kristian Stormark
%
% 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.G
%
% 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 [SegyTraceHeader]=GetSegyTraceHeader(segyid,TraceStart,SegyTraceHeader);
if nargin<2
TraceStart=ftell(segyid);
end
% get current position in file
cur_pos=ftell(segyid);
if cur_pos~=TraceStart
fseek(segyid,TraceStart,'bof');
end
% GET POSITION FOR EASY LATER LOCALIZATION
SegyTraceHeader.SegyMAT_TraceStart = ftell(segyid);
chunk = fread(segyid,7,'int32');
SegyTraceHeader.TraceSequenceLine = chunk(1); % 0
SegyTraceHeader.TraceSequenceFile = chunk(2); % 4
SegyTraceHeader.FieldRecord = chunk(3); % 8
SegyTraceHeader.TraceNumber = chunk(4); % 12
SegyTraceHeader.EnergySourcePoint = chunk(5); % 16
SegyTraceHeader.cdp = chunk(6); % 20
SegyTraceHeader.cdpTrace = chunk(7); % 24
chunk = fread(segyid,4,'int16');
SegyTraceHeader.TraceIdentifactionCode = chunk(1); % 28
SegyTraceHeader.NSummedTraces = chunk(2); % 30
SegyTraceHeader.NStackedTraces = chunk(3); % 32
SegyTraceHeader.DataUse = chunk(4); % 34
chunk = fread(segyid,8,'int32');
SegyTraceHeader.offset = chunk(1); %36
SegyTraceHeader.ReceiverGroupElevation = chunk(2); %40
SegyTraceHeader.SourceSurfaceElevation = chunk(3); %44
SegyTraceHeader.SourceDepth = chunk(4); %48
SegyTraceHeader.ReceiverDatumElevation = chunk(5); %52
SegyTraceHeader.SourceDatumElevation = chunk(6); %56
SegyTraceHeader.SourceWaterDepth = chunk(7); %60
SegyTraceHeader.GroupWaterDepth = chunk(8); %64
% ElevationScalar to applied to %40 - %64
chunk = fread(segyid,2,'int16');
SegyTraceHeader.ElevationScalar = chunk(1); %68
% Multiply/divide next number for following 4 values
SegyTraceHeader.SourceGroupScalar = chunk(2); %70
chunk = fread(segyid,4,'int32');
SegyTraceHeader.SourceX = chunk(1); %72
SegyTraceHeader.SourceY = chunk(2); %76
SegyTraceHeader.GroupX = chunk(3); %80
SegyTraceHeader.GroupY = chunk(4); %84
chunk = fread(segyid,13,'int16');
SegyTraceHeader.CoordinateUnits = chunk(1); %88
SegyTraceHeader.WeatheringVelocity = chunk(2); %90
SegyTraceHeader.SubWeatheringVelocity = chunk(3); %92
SegyTraceHeader.SourceUpholeTime = chunk(4); %94
SegyTraceHeader.GroupUpholeTime = chunk(5); %96
SegyTraceHeader.SourceStaticCorrection = chunk(6); %98
SegyTraceHeader.GroupStaticCorrection = chunk(7); %100
SegyTraceHeader.TotalStaticApplied = chunk(8); %102
SegyTraceHeader.LagTimeA = chunk(9); %104
SegyTraceHeader.LagTimeB = chunk(10); %106
SegyTraceHeader.DelayRecordingTime = chunk(11); %108
SegyTraceHeader.MuteTimeStart = chunk(12); %110
SegyTraceHeader.MuteTimeEND = chunk(13); %112
chunk = fread(segyid,2,'uint16');
SegyTraceHeader.ns = chunk(1); %114
SegyTraceHeader.dt = chunk(2); %116
chunk = fread(segyid,31,'int16');
SegyTraceHeader.GainType = chunk(1); %118
SegyTraceHeader.InstrumentGainConstant = chunk(2); %120
SegyTraceHeader.InstrumentInitialGain = chunk(3); %%122
SegyTraceHeader.Correlated = chunk(4); %124
SegyTraceHeader.SweepFrequenceStart = chunk(5); %126
SegyTraceHeader.SweepFrequenceEnd = chunk(6); %128
SegyTraceHeader.SweepLength = chunk(7); %130
SegyTraceHeader.SweepType = chunk(8); %132
SegyTraceHeader.SweepTraceTaperLengthStart = chunk(9); %134
SegyTraceHeader.SweepTraceTaperLengthEnd = chunk(10); %136
SegyTraceHeader.TaperType = chunk(11); %138
SegyTraceHeader.AliasFilterFrequency = chunk(12); %140
SegyTraceHeader.AliasFilterSlope = chunk(13); %142
SegyTraceHeader.NotchFilterFrequency = chunk(14); %144
SegyTraceHeader.NotchFilterSlope = chunk(15); %146
SegyTraceHeader.LowCutFrequency = chunk(16); %148
SegyTraceHeader.HighCutFrequency = chunk(17); %150
SegyTraceHeader.LowCutSlope = chunk(18); %152
SegyTraceHeader.HighCutSlope = chunk(19); %154
SegyTraceHeader.YearDataRecorded = chunk(20); %156
SegyTraceHeader.DayOfYear = chunk(21); %158
SegyTraceHeader.HourOfDay = chunk(22); %160
SegyTraceHeader.MinuteOfHour = chunk(23); %162
SegyTraceHeader.SecondOfMinute = chunk(24); %164
SegyTraceHeader.TimeBaseCode = chunk(25); %166
% NEX FEW LINES ARE NOT STRICTLY NEEDED
% if SegyTraceHeader.TimeBaseCode==1, SegyTraceHeader.TimeBaseCodeText='Local';
% elseif SegyTraceHeader.TimeBaseCode==2, SegyTraceHeader.TimeBaseCodeText='GMT';
% elseif SegyTraceHeader.TimeBaseCode==3, SegyTraceHeader.TimeBaseCodeText='Other';
% elseif SegyTraceHeader.TimeBaseCode==4, SegyTraceHeader.TimeBaseCodeText='UTC';
% else SegyTraceHeader.TimeBaseCodeText=''; end
SegyTraceHeader.TraceWeightningFactor = chunk(26); %168
SegyTraceHeader.GeophoneGroupNumberRoll1 = chunk(27); %170
SegyTraceHeader.GeophoneGroupNumberFirstTraceOrigField = chunk(28); %172
SegyTraceHeader.GeophoneGroupNumberLastTraceOrigField = chunk(29); %174
SegyTraceHeader.GapSize = chunk(30); %176
SegyTraceHeader.OverTravel = chunk(31); %178
chunk = fread(segyid,5,'int32');
SegyTraceHeader.cdpX = chunk(1); %180
SegyTraceHeader.cdpY = chunk(2); %184
SegyTraceHeader.Inline3D = chunk(3); %188
SegyTraceHeader.Crossline3D = chunk(4); %192
SegyTraceHeader.ShotPoint = chunk(5); %196
SegyTraceHeader.ShotPointScalar=fread(segyid,1,'int16'); %200
SegyTraceHeader.TraceValueMeasurementUnit=fread(segyid,1,'int16'); %202
% NEXT LINES ARE STRICTLY NOT NEEDED
% if SegyTraceHeader.TraceValueMeasurementUnit==-1, SegyTraceHeader.TraceValueMeasurementUnitText='Other';
% elseif SegyTraceHeader.TraceValueMeasurementUnit==0, SegyTraceHeader.TraceValueMeasurementUnitText='Unknown';
% elseif SegyTraceHeader.TraceValueMeasurementUnit==1, SegyTraceHeader.TraceValueMeasurementUnitText='Pascal (Pa)';
% elseif SegyTraceHeader.TraceValueMeasurementUnit==2, SegyTraceHeader.TraceValueMeasurementUnitText='Volts (v)';
% elseif SegyTraceHeader.TraceValueMeasurementUnit==3, SegyTraceHeader.TraceValueMeasurementUnitText='Millivolts (v)';
% elseif SegyTraceHeader.TraceValueMeasurementUnit==4, SegyTraceHeader.TraceValueMeasurementUnitText='Amperes (A)';
% elseif SegyTraceHeader.TraceValueMeasurementUnit==5, SegyTraceHeader.TraceValueMeasurementUnitText='Meters (m)';
% elseif SegyTraceHeader.TraceValueMeasurementUnit==6, SegyTraceHeader.TraceValueMeasurementUnitText='Meters Per Second (m/s)';
% elseif SegyTraceHeader.TraceValueMeasurementUnit==7, SegyTraceHeader.TraceValueMeasurementUnitText='Meters Per Second squared (m/&s2)Other';
% elseif SegyTraceHeader.TraceValueMeasurementUnit==8, SegyTraceHeader.TraceValueMeasurementUnitText='Newton (N)';
% elseif SegyTraceHeader.TraceValueMeasurementUnit==8, SegyTraceHeader.TraceValueMeasurementUnitText='Watt (W)';
% else SegyTraceHeader.TraceValueMeasurementUnitText='Undefined'; end
SegyTraceHeader.TransductionConstantMantissa=fread(segyid,1,'int32'); %204
chunk = fread(segyid,5,'int16');
SegyTraceHeader.TransductionConstantPower = chunk(1);%208
SegyTraceHeader.TransductionUnit = chunk(2); %210
SegyTraceHeader.TraceIdentifier = chunk(3); %212
SegyTraceHeader.ScalarTraceHeader = chunk(4); %214
SegyTraceHeader.SourceType = chunk(5); %216
SegyTraceHeader.SourceEnergyDirectionMantissa=fread(segyid,1,'int32'); %218
SegyTraceHeader.SourceEnergyDirectionExponent=fread(segyid,1,'int16'); %222
SegyTraceHeader.SourceMeasurementMantissa=fread(segyid,1,'int32'); %224
chunk = fread(segyid,2,'int16');
SegyTraceHeader.SourceMeasurementExponent = chunk(1); %228
SegyTraceHeader.SourceMeasurementUnit = chunk(2); %230
chunk = fread(segyid,2,'int32');
SegyTraceHeader.UnassignedInt1 = chunk(1); %232
SegyTraceHeader.UnassignedInt2 = chunk(2); %236
%if exist('ns','var')==0,
% ns=SegyTraceHeader.ns;
%end
% remeber location
SegyTraceHeader.SegyMAT_TraceDataStart = ftell(segyid);