-
Notifications
You must be signed in to change notification settings - Fork 1
/
import_sfile.m
66 lines (51 loc) · 1.78 KB
/
import_sfile.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
function sfile_values = import_sfile(sfilename)
% Todd Anderson
% November 9 2022
%
% Reads Sfile information and returns matrix of sferic information.
fclose("all");
% sfilename = "data/S-files/2021/S202107080401"; % seattle/togasea Sfile
% sfilename = "data/S-files/2022/S202211072302"; % fairbanks Sfile
nlines = countLines(sfilename);
fid = fopen(sfilename,'r');
%
time = zeros(nlines, 1);
mutoga = zeros(nlines, 1);
rmsAmp = zeros(nlines, 1);
dtoga = zeros(nlines, 1);
c1 = zeros(nlines, 1);
c2 = zeros(nlines, 1);
c3 = zeros(nlines, 1);
Fs = zeros(nlines, 1);
N = zeros(nlines, 1);
% rmsPhaseError = zeros(nlines, 1);
% kHzFreqs = zeros(nlines, 17); % frequencies in dispersion fit
% tOffsets = zeros(nlines, 1); % time offset between start of sample and TOGA trigger point
% secs = zeros(nlines, 1);
j=1;
while j <= nlines
tLine = fgets(fid); % each successive call gets next line in sfile
% get header values, minus leading magic header "W210"
[A, ~, errmsg] = sscanf(tLine(6:end),'%d,%4d-%2d-%dT%2d:%2d:%2d,%d,%d,%f,%f,%f,%f,%d,%f,%d',16);
% add check: if line in Sfile does not have enough elements, skip it
if ~isempty(errmsg)
j = j+1;
continue;
end
% get waveform samples
%[y, count] = sscanf(tLine(nextindex+6:end),'%f,',inf);
time(j) = datenum(A(2:7)');
%secs(j) = A(7);
mutoga(j) = A(8); % UTC toga offset in microseconds
rmsAmp(j) = A(9); % rms amplitude
dtoga(j) = A(10); % TOGA offset in seconds from start of waveform
c1(j)=A(11); % dispersion fit parameters
c2(j)=A(12); %
c3(j)=A(13); %
Fs(j)=A(15); % sampling frequency in Hz
N(j)=A(16); % number of samples
j=j+1;
end
fclose(fid);
sfile_values = cat(2,time, mutoga, rmsAmp, dtoga, c1, c2, c3, Fs, N);
end