-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWriteSpect.m
More file actions
54 lines (47 loc) · 1.66 KB
/
Copy pathWriteSpect.m
File metadata and controls
54 lines (47 loc) · 1.66 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
51
52
53
function WriteSpect(pathtowrite,filename,file_header,headers,complexdata)
%% Write complex data into .spect format
% Use: WriteSpect(pathtowrite,filename,fileheader,headers,complexdata)
%
%
% FORMAT IS ALL IN DOUBLES
% towrite = [32 byte File Header] + {[32 byte Trace Header] + [ns*8 bytes real part of trace]
% + [ns*8 bytes imag part of trace]}*ntraces
%
% FILE HEADER, must be a 4x1 vector
% 1st sample in file header is f0, the frequency of the first sample
% 2nd sample in file header is df, the frequency resolution
% 3rd sample in file header is ns, the number of samples before being decomposed into
% real and imag parts.
% 4th sample in file header is ntraces, the number of traces in the file.
%
% TRACE HEADER, must be a (4,ntraces) aray
% 1: Source X
% 2: Source Y
% 3: Receiver X
% 4: Receiver Y
%
% Then all real parts, followed by all imaginary parts for
% each trace.
% -----------------------------------------------------------------------------
% Author:
% Keegan Lensink
% Seismic Laboratory for Imaging and Modeling
% Department of Earth, Ocean, and Atmospheric Sciences
% The University of British Columbia
%
% Date: March, 2017
% -----------------------------------------------------------------------------
% Decompose complex data into real and imag parts
Dr = real(complexdata);
Di = imag(complexdata);
% Get metadata from file_header
ns = file_header(3);
ntraces = file_header(4);
% Create array to write
towrite = [headers; Dr; Di];
% Open file for writing
fid = fopen([pathtowrite,filename],'w');
% Write in the towrite vector
fwrite(fid,[file_header; towrite(:)],'double');
% Close the file
fclose(fid);