-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReadSpectSample.m
More file actions
50 lines (39 loc) · 1.5 KB
/
Copy pathReadSpectSample.m
File metadata and controls
50 lines (39 loc) · 1.5 KB
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
function [file_header, headers, data] = ReadSpectSample(filename,index)
%% Reads a .spect file and returns the indexed sample
% from each trace and metadata
%
% Use: [fileheader, headers, data] = ReadSpectSample(filename,index);
% -----------------------------------------------------------------------------
% Author:
% Keegan Lensink
% Seismic Laboratory for Imaging and Modeling
% Department of Earth, Ocean, and Atmospheric Sciences
% The University of British Columbia
%
% Date: March, 2017
% -----------------------------------------------------------------------------
% Open the file for reading
fid = fopen(filename,'r');
% Read the file header
file_header = fread(fid,[4,1],'double');
% Pull out metadata that will be used to read
ns = file_header(3);
ntraces = file_header(4);
% Calc byte to skip
bytespersample = 8;
toskip = ns*2*bytespersample;
% Now read all of the headers, real, and imag data
headers = fread(fid, [4,ntraces],'4*double=>double',toskip);
% Return to index's first real sample
bytespersample = 8;
toskip = 2*ns*bytespersample+32-8;
fseek(fid, 32+32+(index-1)*bytespersample, 'bof');
% Read out all the real entries at this index
realpart = fread(fid,[1,ntraces],'1*double=>double',toskip);
% Return to first index's first imag sample
fseek(fid, 32+32+(ns+index-1)*bytespersample, 'bof');
% Read all the imag parts
imagpart = fread(fid,[1,ntraces],'1*double=>double',toskip);
% Reconstruct complex data
data = complex(realpart, imagpart);
fclose(fid);