Sie sind auf Seite 1von 7

12/24/2015

FileExchangeMATLABCentral
Search:

FileExchange

CreateAccount

FileExchange

Answers

Newsgroup

LinkExchange

Blogs

Trendy

Cody

Contest

LogIn

MathWorks.com

LargeDatainMATLAB:ASeismic
DataProcessingCaseStudy
byStuartKozola
01Mar2011
ThesearethefilesusedinthewebinaronFeb.23,2011.

SegYFileReader

classdefSegYFileReader<SeismicFileReader
%SegYFileReaderSEGYfilereaderclass.
%
%SegYFileReaderisaSeismicFileReaderclassthatprovidesbasic
%functionalityforreadingaSEGYformattedfile.Thisclasscanread
%SEGYVersion0/1files.
%
%SegYFileReaderproperties:
%FileDescriptorSEG2fileidentifierlabel(must=3A55h)
%FileNamenameoftheseismicbinaryfile
%FilePathpathofthefile
%FileFormatfileformatdescription
%FileHeaderHeaderinformationfromtheseismicfile
%MachineFormatBinaryfileformat,big/littleendian
%NumberOfTracesNumberoftracesinthefile
%TraceDescriptionTraceinformationfromtheseismicfile
%
%SeealsoSEISMICFILEREADER,SEG2FILEREADER

properties(SetAccess=protected)
TapeLabel='';
end%publicproperties

methods
functionobj=SegYFileReader(fileName,procHeader,procTraceHeader,endian)
%ConstructorforSeg2FileReader
if~exist('fileName','var')
%creatanemptyclase
fileName='';
procHeader=false;
end

if~exist('procHeader','var')
%readintheheader
procHeader=true;
end

if~exist('procTraceHeader','var')
%readintheheader
procTraceHeader=true;
end

if~exist('endian','var')
endian='ieeebe';%SEGYRev1.0shouldbebigendian
end

obj=obj@SeismicFileReader(fileName);
obj.MachineFormat=endian;

ifprocHeader
readFileHeader(obj);
end

ifprocHeader&&procTraceHeader
readTraceHeader(obj);
end
end

functionfh=readFileHeader(obj)
%READFILEHEADERreadsSEGYheaderinformation
%H=READFILEHEADER(OBJ)readsintheoptionaltapellablelheader,the

DownloadZip
CodecoveredbytheBSDLicense

Highlightsfrom

LargeDatainMATLAB:A
SeismicDataProcessing
CaseStudy
LargeDatainMATLAB:AC...
SeismicMigrationExample...
fm2d(v,model,nz,dz,nx,dx,...
fm2d_gpu(v,model,nz,dz,nx...
ibm2ieee
Name:ibm2ieee
migrate(travelTime,shot,d...
Migrateashotrecordforagiven
traveltimebetweenshot(source)
and
plotProgress(X,Y,Z,curren...
checktoseeiffigureexists
ray2d(V,Shot,dx)
2Draytracing
ricker(f,n,dt,t0,t1)
RICKERcreatesancausalricker
waveletsignal
rtm2d(v,data,nz,dz,nx,dx,...
rtm2d_gpu(v,data,nz,dz,nx...
seismic(n)
seismic(n)createsacolormap,
rangingfromdarkblueviawhiteto
darkred.
shot2RecTime(travelTime,i...
shotRecordLocator(shotNum...
Numberoftracespershotrecord
Seg2FileReader
Seg2FileReaderSEG2filereader
class.
SegYFileReader
SegYFileReaderSEGYfilereader
class.
SegyMemmap
SeismicFileReader
SeismicFileReaderSeismicfile
readerclass.
travelTimeMemmap
migrateExample.m
SeismicMigrationwitha20GBArray
build.m
saltModelMigrationRTM.m
SeismicMigrationExample
setup.m
Viewallfiles

http://www.mathworks.com/matlabcentral/fileexchange/30585largedatainmatlabaseismicdataprocessingcasestudy/content/fileReader/SegYFileReade

1/7

12/24/2015

FileExchangeMATLABCentral

%H=READFILEHEADER(OBJ)readsintheoptionaltapellablelheader,the
%3200bytestextualheader,the400bytebinaryheader,andoption3200
%bytetextualheaders.
%
%Example:TODO
%
%SeealsoSEGYFILEREADER,READTAPEHEADER,READTAPEDATA
%readintheoptionalheaderifpresent
%Isthereaoptionalfileheader?
fmt={'uchar',{128,'TapeLabel'}};
fh=readFileHeader@SeismicFileReader(obj,fmt);
tapeHeader=char(fh.TapeLabel');

%ifSYX.Xispresent,thisfilecontainsanoptionalheader
ifstrcmpi('SY',tapeHeader(5:6))
obj.TapeLabel.StorageUnitSeqNumber=tapeHeader(1:4);
obj.TapeLabel.SEGYRevision=tapeHeader(5:9);
obj.TapeLabel.StorageUnitStructure=tapeHeader(10:15);
obj.TapeLabel.BindingEdition=tapeHeader(16:19);
obj.TapeLabel.MaxBlockSize=tapeHeader(20:29);
obj.TapeLabel.ProducerOrganizationCode=tapeHeader(30:39);
obj.TapeLabel.CreationDate=tapeHeader(40:50);
obj.TapeLabel.SerialNumber=tapeHeader(51:62);
obj.TapeLabel.Reserved=tapeHeader(63:68);
obj.TapeLabel.StorageSetIdentifier=tapeHeader(69:128);
else
obj.TapeLabel='None';
end

%ifpresent,settheoffsettoaccountforit
ifisstruct(obj.TapeLabel)
offset=128;
else
offset=0;
end

%readinthe3200byterequiredheader
fmt={'uchar',{3200,'TextHeader'}};
fh=readFileHeader@SeismicFileReader(obj,fmt,offset);
obj.FileHeader.TextualHeader=char(fh.TextHeader');

%readinthe400Bytebinaryheader
offset=offset+3200;
fmt={'int32',{'JobID','LineNumber','ReelNumber'};
'int16',{'DataTracePerEnsemble',...
'AuxillaryTracePerEnsemble',...
'SamplingTimeInMicroSec',...
'OrigninalSamplingTime',...
'NumberOfSamples','OriginalNumberOfSamples',...
'SampleFormatCode','EnsembleFold',...
'TraceSorting','VerticalSumCode',...
'SweepFreqencyStart','SweepFrequencyEnd',...
'SweepLength','SweepType','SweepChannel',...
'SweepTaperLengthStart',...
'SweepTaperLengthEnd','TaperType',...
'CorrelatedTraces','BinaryGain',...
'AmplitudeRecovery','MeasurementSystem',...
'ImpulsePolarity','VibratoryPolarity'};
'int16',{120,'Unassigned1'};
'int16',{'RevisionNumber','FixedLengthTraceFlag',...
'NumberOfExtendedTextualHeaders'};
'int16',{94,'Unassigned2'}
};

fh=readFileHeader@SeismicFileReader(obj,fmt,offset);
obj.FileHeader.BinaryHeader=fh;

%VerifySEGYsupportedrevision
v=obj.FileHeader.BinaryHeader.RevisionNumber;
ifv>257
error('SegYFileReader:UnsupportedVersion',...
'Versionnumberfoundinfileis%2.2f.Supportedversionsareupto1.0',...
num2str(v/10));
else
obj.FileFormat=['SEGYVersion',num2str(v/10)];
end

%Setnumberoftraces
obj.NumberOfTraces=obj.FileHeader.BinaryHeader.DataTracePerEnsemble;

offset=offset+400;

%ReadExtended3200bytetextualheadersifpresent
fori=1:obj.FileHeader.BinaryHeader.NumberOfExtendedTextualHeaders;
fmt={'uchar',{3200,'TextHeader'}};

http://www.mathworks.com/matlabcentral/fileexchange/30585largedatainmatlabaseismicdataprocessingcasestudy/content/fileReader/SegYFileReade

2/7

12/24/2015

FileExchangeMATLABCentral

fmt={'uchar',{3200,'TextHeader'}};
fh=readFileHeader@SeismicFileReader(obj,fmt,offset);
obj.FileHeader.ExtendedTextualHeader(i)=char(fh.TextHeader');
offset=offset+3200;
end

%Validateinputselections
switchobj.FileHeader.BinaryHeader.SampleFormatCode
case1%4byteIBMfloatingpoint
obj.FileHeader.TraceFormat='uint';
mult=4;
case2%4bytetwo'scomplementinteger
obj.FileHeader.TraceFormat='int32';
mult=4;
case3%2bytetwo'scomplementinteger
obj.FileHeader.TraceFormat='int16';
mult=2;
case4%4bytefixedpointwithgain(obsolete)
obj.FileHeader.TraceFormat='int32';
mult=4;
case5%4byteIEEEfloatingpoint
obj.FileHeader.TraceFormat='float32';
mult=4;
case8%1bytetwo'scomplementinteger
obj.FileHeader.TraceFormat='int8';
mult=1;
otherwise
warning('Couldn''tdeterminedataformat,assumingfloat32');
obj.FileHeader.TraceFormat='float32';
mult=4;
end

%Storetraceoffsetpointers
fmt={'int16',{1,'NumberOfSamples'}};
fh=readFileHeader@SeismicFileReader(obj,fmt,offset+114);
traceSize=fh.NumberOfSamples*mult+240;
mxTraces=ceil((obj.FileSizeoffset)/traceSize);
obj.FileHeader.TracePointers=zeros(mxTraces,1);
obj.FileHeader.TracePointers(1)=offset;
%checktoseeifalltracesareofequalsize
ifobj.FileHeader.BinaryHeader.FixedLengthTraceFlag==1
%allarethesamesizesobuildpointers
i=1:(mxTraces+1);
obj.FileHeader.TracePointers=[(i1)*traceSize+offset]';
obj.NumberOfTraces=mxTraces;
else%tracescouldbedifferentsizes
i=1;
while(offset<obj.FileSize)%fori=2:obj.NumberOfTraces;
%readthetraceheaderstogetthesizeofthetraces
%numberofsamplesis114bytesintothetraceheader
i=i+1;
fh=readFileHeader@SeismicFileReader(obj,fmt,offset+114);
ptr=fh.NumberOfSamples*mult+240+...
obj.FileHeader.TracePointers(i1);
ifptr<obj.FileSize
obj.FileHeader.TracePointers(i)=ptr;
end
offset=ptr;
end
obj.NumberOfTraces=i;
ifi<mxTraces
obj.FileHeader.TracePointers(i+1:end)=[];
end
end
end%readFileHeader

functionth=readTraceHeader(obj,traceNumber)
ifnargin<2
traceNumber=1:obj.NumberOfTraces;
end
%readinheaderdata
fmt={'int32',{'TraceSequenceLine','TraceSequenceFile',...
'OriginalFieldRecord','TraceNumberInField',...
'EnergySourceNumber','EnsembleNumber',...
'EnsembleTraceNumber'};
'int16',{'TraceIdentificationCode','NumberVertSummedTraces',...
'NumberHorizSummedTraces','DataUse'};
'int32',{'ReceiverGroupOffset',...
'ReceiverGroupElevation',...
'SurfaceSourceElevation',...
'SurfaceSourceDepth',...
'ReceiverDatumElevation',...
'SourceDatumElevation',...
'SourceWaterDepth','GroupWaterDepth'};

http://www.mathworks.com/matlabcentral/fileexchange/30585largedatainmatlabaseismicdataprocessingcasestudy/content/fileReader/SegYFileReade

3/7

12/24/2015

FileExchangeMATLABCentral

'SourceWaterDepth','GroupWaterDepth'};
'int16',{'ElevationOrDepthScalar','CoordinateScalar'};
'int32',{'SourceX','SourceY','GroupX','GroupY'};
'int16',{'CoordinateUnits','WeatheringVelocity',...
'SubweatheringVelocity',...
'SourceUpholeTime_ms','GroupUpholeTime_ms',...
'SourceStaticCorrection_ms',...
'GroupStaticCorrection_ms',...
'TotalStaticApplied_ms',...
'ALagTime_ms','BLagTime_ms',...
'RecordingDelay_ms',...
'MuteTimeStart_ms','MuteTimeEnd_ms',...
'NumberOfSamples',...
'SampleInterval_ms',...
'GainType','GainConstant_dB',...
'InitialGain_dB','Correlated',...
'SweepFrequencyStart_Hz',...
'SweepFrequencyEnd_Hz',...
'SweepLength_ms','SweepType',...
'SweepTaperLengthStart_ms',...
'SweepTaperLengthEnd_ms',...
'TaperType','AliasFilter_Hz',...
'AliasSlope_dBperOctave',...
'NotchFilterFrequency_Hz',...
'NotchFilterSlope_dBperOctave',...
'LowCutFrequency_Hz',...
'HighCutFrequency_Hz',...
'LowCutSlope_dBperOctave',...
'HighCutSlope_dBperOctave',...
'Year','Day','Hour','Minute','Second',...
'TimeBasisCode','WeightingFactor',...
'GeophoneGroupNumberRoll1',...
'GeophoneGroupNumberFirstTraceOriginalRecord',...
'GeophoneGroupNumberLastTraceOriginalRecord',...
'GapSize','OverTravel'};
'int32',{'EnsembleX','EnsembleY','InLineNumber3D',...
'CrossLineNumber3D','ShotPointNumber'};
'int16',{'ShotPointScalar','TraceMeasurementUnit'};
'int32',{1,'TransductionConstantMantissa'};
'int16',{'TransductionConstantExponent',...
'TranductionUnits','TraceIdentifier',...
'TimeScalar','SourceTypeOrientation'};
'bit48',{1,'SourceEnergyDirection'};
'int32',{1,'SourceMeasurementMantissa'};
'int16',{'SourceMeasurementExponent',...
'SourceMeasurementUnit'};
'int16',{4,'Unassigned'}
};

fort=1:length(traceNumber)
offset=obj.FileHeader.TracePointers(traceNumber(t));
f=readTraceHeader@SeismicFileReader(obj,fmt,offset);
th(t)=f;
end

ifnargout==0%addtoobjectifnooutputrequested
obj.TraceDescription=th;
end
end%readTraceHeader

function[td,th]=readTraceData(obj,traceNumber,td)
ifnargin==1||isempty(traceNumber)
traceNumber=1:obj.NumberOfTraces;
end

%get1sttracesizetodetermineinitialarraysize
th=readTraceHeader(obj,1);
r=th.NumberOfSamples;
c=length(traceNumber);

%createasdistributedarrayifrequested
ifnargin>2&&license('test','distrib_computing_toolbox')
td=distributed.nan(r,c);
else
try
td=nan(r,c);
catch
e=lasterror;
ifstrcmpi(e.identifier,'MATLAB:nomem')
%testmaximumarraysize
u=memory;
str=['\n\tCouldnotallocateanarrayof',...
num2str(r*c*8),'bytes.Availablememoryis:\n',...
u.MaxPossibleArrayBytes,...
'\tTrydeclaringasadistributedarray:\n\t\t',...
'd=readTraceData(obj,traceNumbers,distributed)'];

http://www.mathworks.com/matlabcentral/fileexchange/30585largedatainmatlabaseismicdataprocessingcasestudy/content/fileReader/SegYFileReade

4/7

12/24/2015

FileExchangeMATLABCentral

'd=readTraceData(obj,traceNumbers,distributed)'];
e.message=sprintf([e.message,str]);
end
rethrow(e)
end

end

fort=1:length(traceNumber)
%readthetraceheaderinformation
th(t)=readTraceHeader(obj,traceNumber(t));

%needtoaccountforvariablelengthdata(NaNs)
n=th(t).NumberOfSamples;
%sincerissizedbythefirstdataset,itshouldnever
%besmallerthanthis,weonlyneedtotestforthecase
%whereitisgreater

%ifth(t).NumberOfSamples>r
%th(end:end+n,:)=NaN;
%end

%gettracedataandfillpreallocatedarray
fmtCode=obj.FileHeader.TraceFormat;
fmt={fmtCode,th(1).NumberOfSamples};
offset=obj.FileHeader.TracePointers(traceNumber(t))+...
240;%offsetfortracebinaryheader
%accountforibmfloatingpoint
ifobj.FileHeader.BinaryHeader.SampleFormatCode==1
td(:,t)=ibm2ieee(readTraceData@SeismicFileReader(obj,fmt,offset));
else
td(:,t)=readTraceData@SeismicFileReader(obj,fmt,offset);
end
end%forloop
end%readTraceData

functiontxt=parseTextBlock(obj,textBlock)
%parseouttextblockdata
txt=[];
%extractkeywords
[keys,idx]=regexp(textBlock,'[AZ_]\w*','match','start');
%checkvalidity
[~,idx]=obj.validKeys(keys,idx);

%remove1sttwobytes(offsets)infilefromkeywords
%andlastoffsetbytes
textBlock([idx2,idx1,end1:end])=[];

%extractkeywordswithnewindexlocations
[keys,idx]=regexp(textBlock,'[AZ_]\w*','match','end');
%checkvalidity
[keys,idx]=obj.validKeys(keys,idx);
fori=1:length(idx)
ifi<length(idx)
str=textBlock((idx(i)+1):(idx(i+1)length(keys{i+1})));
else
str=textBlock((idx(i)+1):end);
end
%checkifitisadateortimestring
ifisempty(strfind(str,':'))&&isempty(strfind(str,'\'))
tmpStr=str2num(str);
else
tmpStr=deblank(strtrim(str));
end
ifisempty(tmpStr)
%Ifonlywhitespacesdon'tadd
if~isempty(strtok(str,char(0)))
txt.(keys{i})=deblank(strtrim(str));
end
else
txt.(keys{i})=tmpStr;
end
end%for
end%parseTextBlock

functionvarargout=subsref(obj,s)
ifnumel(obj)>1
iflength(s)>1
obj=obj(s(1).subs{:});
varargout{1}=subsref(obj,s(2:end));
else
varargout{1}=obj(s.subs{:});
end
else
ifstrcmp(s(1).type,'()')

http://www.mathworks.com/matlabcentral/fileexchange/30585largedatainmatlabaseismicdataprocessingcasestudy/content/fileReader/SegYFileReade

5/7

12/24/2015

FileExchangeMATLABCentral

ifstrcmp(s(1).type,'()')
iflength(s)>1
error('SeismicFileReader:InvalidIndexing','Thisindexoperationisnotallowed');
end
ifstrcmpi(s.subs{2},':')
ind=[];
else
ind=s.subs{2};
end
tmp=readTraceData(obj,ind);
varargout{1}=tmp(s.subs{1},:);
elseifstrcmp(s.type,'.')
varargout{1}=obj.(s.subs);
end
end
end%subsref
end%methods

methods(Static)

function[keys,idx]=validKeys(keys,idx)
%checkvalidkeys
validKey={'ACQUISITION_DATE',...%fileheader
'ACQUISITION_TIME',...
'CLIENT',...
'COMPANY',...
'GENERAL_CONSTANT',...
'INSTRUMENT',...
'JOB_ID',...
'OBSERVER',...
'PROCESSING_TIME',...
'TRACE_SORT',...
'UNITS',...
'NOTE',...
'ALIAS_FILTER',...%traceheader
'AMPLITUDE_RECOVERY',...
'BAND_REJECT_FILTER',...
'CDP_NUMBER',...
'CDP_TRACE',...
'CHANNEL_NUMBER',...
'DATUM',...
'DELAY',...
'DESCALING_FACTOR',...
'DIGITAL_BAND_REJECT_FILTER',...
'DIGITAL_HIGHT_CUT_FILTER',...
'DIGITAL_LOW_CUT_FILTER',...
'END_OF_GROUP',...
'FIXED_GAIN',...
'HIGH_CUT_FILTER',...
'LINE_ID'...
'LOW_CUT_FILTER',...
'NOTCH_FREQUENCY',...
'POLARITY',...
'RAW_RECORD',...
'RECEIVER',...
'RECEIVER_GEOMETERY',...
'RECEIVER_LOCATION',...
'RECEIVER_SPECS',...
'RECEIVER_STATION_NUMBER',...
'SAMPLE_INTERVAL',...
'SHOT_SEQUENCE_NUMBER',...
'SKEW',...
'SOURCE',...
'SOURCE_GEOMETRY',...
'SOURCE_LOCATION',...
'SOURCE_STATION_NUMBER',...
'STACK',...
'STATIC_CORRECTIONS',...
'TRACE_TYPE',...
'UNIT',...%nonspeckeywordsbelow
'ACQUISITION_SECOND_FRACTION'};

lidx=ismember(keys,validKey);
keys=keys(lidx);
idx=idx(lidx);
end%validKeys

end%Staticmethods

end%Seg2FileReaderClass

http://www.mathworks.com/matlabcentral/fileexchange/30585largedatainmatlabaseismicdataprocessingcasestudy/content/fileReader/SegYFileReade

6/7

12/24/2015

FileExchangeMATLABCentral

Contactus

Patents Trademarks PrivacyPolicy PreventingPiracy TermsofUse

19942015TheMathWorks,Inc.
FeaturedMathWorks.comTopics:

NewProducts Support Documentation Training Webinars Newsletters MATLABTrials Careers

http://www.mathworks.com/matlabcentral/fileexchange/30585largedatainmatlabaseismicdataprocessingcasestudy/content/fileReader/SegYFileReade

7/7