-
Notifications
You must be signed in to change notification settings - Fork 0
/
getFileAndEQseconds_SL190.m
executable file
·300 lines (234 loc) · 11.8 KB
/
getFileAndEQseconds_SL190.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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
function [FIsec, FIyyyy, EQsec, Omarker] = getFileAndEQseconds(F,eqin,offset)
% Calculate start times of the files in seconds after midnight, January 1st
% this works for SAC files created with rdseed4.5.1
% eg: F = '1993.159.23.15.09.7760.IU.KEV..BHN.D.SAC'
% if your filenames contains no julian day, please use command
% dayofyear (in Splitlab/Tools)
%
% Windows user can try a renamer , for example 1-4aren (one-for all renamer)
% http://www.1-4a.com/rename/ perhaps this address is still valid
%==========================================================================
% Yvonne Fröhlich (YF)
% ORCID: https://orcid.org/0000-0002-8566-0619
%
% July-December 2021
% Modifications to fix extraction of start time by SplitLab
% (unconsidered milliseconds or seconds of start time)
%
% - GitHub: https://github.com/yvonnefroehlich/SplitLab-TemporalAlignment
% - Zenodo: https://doi.org/10.5281/zenodo.5805029
% - Publication: Fröhlich, Grund, Ritter (2022). On the effects of wrongly
% aligned seismogram components for shear wave splitting
% analysis. Annals of Geophysics, 66(2).
% https://doi.org/10.4401/ag-8781.
%==========================================================================
global config
if config.UseHeaderTimes || strcmp(config.FileNameConvention, '*.e; *.n; *.z')
FIyyyy = zeros(1,size(F,1));
FIddd = zeros(1,size(F,1));
FIHH = zeros(1,size(F,1));
FIMM = zeros(1,size(F,1));
FISS = zeros(1,size(F,1));
FIMSEC = zeros(1,size(F,1));
Omarker = zeros(1,size(F,1));
for k=1:size(F,1)
workbar(k/size(F,1),'Reading header')
try
sac = rsac([config.datadir filesep F(k,:)]);
catch
fclose all;
sac = rsacsun([config.datadir filesep F(k,:)]);
end
[FIyyyy(k), FIddd(k), FIHH(k), FIMM(k), FISS(k), FIMSEC(k)] =...
lh(sac, 'NZYEAR','NZJDAY','NZHOUR','NZMIN', 'NZSEC', 'NZMSEC');
Omarker(k) = lh(sac, 'O');
end
if any(FIMSEC==-12345) || any(FISS==-12345) || any(FIMM==-12345) || any(FIHH==-12345) || any(FIddd==-12345) || any(FIyyyy==-12345)
disp('WARNING: Some header times are not set properly. Assigning files with no warranty')
end
FISS ( FISS == -12345) = 0;
FIMSEC( FIMSEC == -12345) = 0;
Omarker(Omarker == -12345) = 0; %verify, if O-marker is set
FIsec = FIMSEC/1000 + FISS + FIMM*60 + FIHH*3600 + (FIddd)*86400 + Omarker;
fclose all;
else % USE FILENAME
% YF add warning 2021/Nov/28
msgbox( {'When extracting the \bfstart time\rm from the \bffile name\rm be sure that this time is \bf\itreally\rm the exact \bfstart time\rm of the \bftrace!'}, ...
'Check start time' ,'warn', ...
struct('WindowStyle',{'modal'},'Interpreter',{'tex'}) );
switch config.FileNameConvention
case 'RDSEED'
% '2012.169.20.32.00.0150.YV.EURO.00.BHE.M.SAC'
% letter position of Component descriptor in filename
% here: letter before second but last point
% use for last letter: comp = fstr(end);
% eg: 1994.130.06.35.24.9000.GR.GRA1..BHZ.D.SAC
% dot is [5 9 12 15 18 23 26 31 32 36 38]
% thus, pos would be 35
sizeF = size(F);
num_rows = sizeF(1);
splitArray = {};
for row_index = 1:num_rows
char_line_of_F = F(row_index,:);
cell_of_line = strsplit(char_line_of_F, {'.',','}, 'CollapseDelimiters',false);
splitArray = [splitArray; cell_of_line ];
end
FIyyyy = str2num(char(splitArray(:,1)));
FIddd = str2num(char(splitArray(:,2)));
FIHH = str2num(char(splitArray(:,3)));
FIMM = str2num(char(splitArray(:,4)));
FISS = str2num(char(splitArray(:,5)));
FIMMMM = str2num(char(splitArray(:,6)));
FIsec = FIMMMM + FISS + FIMM*60 + FIHH*3600 + (FIddd)*86400;
% OLD SOLUTION - JRS 09/2016
% FIyyyy = str2num(F(:,1:4));%#ok
% FIddd = str2num(F(:,6:8));%#ok
% FIHH = str2num(F(:,10:11));%#ok
% FIMM = str2num(F(:,13:14));%#ok
% FISS = str2num(F(:,16:17));%#ok
% FIMMMM = str2num(F(:,18:22));%#ok
% FIsec = FIMMMM + FISS + FIMM*60 + FIHH*3600 + (FIddd)*86400;
case 'miniSEED'
% miniSEED format (with commas)
% 'TA.ELFS..LHZ.R.2006,123,153619.SAC'
% YF add warning 2021/Nov/28
msgbox( 'Only correct for traces with start times of \bfzero milliseconds\rm!', ...
'Check milliseconds' ,'warn', ...
struct('WindowStyle',{'modal'},'Interpreter',{'tex'}) );
sizeF = size(F);
num_rows = sizeF(1);
splitArray = {};
for row_index = 1:num_rows
char_line_of_F = F(row_index,:);
cell_of_line = strsplit(char_line_of_F, {'.',','}, 'CollapseDelimiters',false);
splitArray = [splitArray; cell_of_line ];
end
FIyyyy = str2num(char(splitArray(:,6)));
FIddd = str2num(char(splitArray(:,7)));
FFtime = char(splitArray(:,8));
FIHH = str2num(FFtime(:,1:2));
FIMM = str2num(FFtime(:,3:4));
FISS = str2num(FFtime(:,5:6));
FIsec = FISS + FIMM*60 + FIHH*3600 + (FIddd)*86400;
case 'RHUM-RUM'
% miniSEED format (with points)
% 'YV.RR39.00.BH1.M.2012.318.221725.SAC' or also
% 'YV.RUN01.00.BH1.M.2012.318.221725.SAC' ..
% YF add warning 2021/Nov/28
msgbox( 'Only correct for traces with start times of \bfzero milliseconds\rm!', ...
'Check milliseconds' ,'warn', ...
struct('WindowStyle',{'modal'},'Interpreter',{'tex'}) );
sizeF = size(F);
num_rows = sizeF(1);
splitArray = {};
for row_index = 1:num_rows
char_line_of_F = F(row_index,:);
cell_of_line = strsplit(char_line_of_F, '.', 'CollapseDelimiters',false);
splitArray = [splitArray; cell_of_line ];
end
FIyyyy = str2num(char(splitArray(:,6)));
FIddd = str2num(char(splitArray(:,7)));
FFtime = char(splitArray(:,8));
FIHH = str2num(FFtime(:,1:2));
FIMM = str2num(FFtime(:,3:4));
FISS = str2num(FFtime(:,5:6));
FIsec = FISS + FIMM*60 + FIHH*3600 + (FIddd)*86400;
disp(FIddd);
% OLD SOLUTION - JRS 09/2016
% FIyyyy = str2num(F(:,18:21));%#ok
% FIddd = str2num(F(:,23:25));%#ok
% FIHH = str2num(F(:,27:28));%#ok
% FIMM = str2num(F(:,29:30));%#ok
% FISS = str2num(F(:,31:32));%#ok
case 'SEISAN' % should be soft-coded ..
% SEISAN format '2003-05-26-0947-20S.HOR___003_HORN__BHZ__SAC'
% YF add warning 2021/Nov/28
msgbox( 'Only correct for traces with start times of \bfzero milliseconds\rm!', ...
'Check milliseconds' ,'warn', ...
struct('WindowStyle',{'modal'},'Interpreter',{'tex'}) );
FIyyyy = str2num(F(:,1:4));%#ok
FImonth= str2num(F(:,6:7));%#ok
FIdd = str2num(F(:,9:10));%#ok
FIHH = str2num(F(:,12:13));%#ok
FIMM = str2num(F(:,14:15));%#ok
FISS = str2num(F(:,17:18));%#ok
FIddd = dayofyear(FIyyyy',FImonth',FIdd')'; %julian Day
FIsec = FISS + FIMM*60 + FIHH*3600 + (FIddd)*86400;
case 'YYYY.JJJ.hh.mm.ss.stn.sac.e'
% Format: 1999.136.15.25.00.ATD.sac.z
% YF add warning 2021/Nov/28
msgbox( 'Only correct for traces with start times of \bfzero milliseconds\rm!', ...
'Check milliseconds' ,'warn', ...
struct('WindowStyle',{'modal'},'Interpreter',{'tex'}) );
FIyyyy = str2num(F(:,1:4));%#ok
FIddd = str2num(F(:,6:8));%#ok
FIHH = str2num(F(:,10:11));%#ok
FIMM = str2num(F(:,13:14));%#ok
FISS = str2num(F(:,16:17));%#ok
FIsec = FISS + FIMM*60 + FIHH*3600 + (FIddd)*86400;
case 'YYYY.MM.DD.hh.mm.ss.stn.E.sac';
% Format: 2003.10.07-05.07.15.DALA.sac.z
% YF add warning 2021/Nov/28
msgbox( 'Only correct for traces with start times of \bfzero milliseconds\rm!', ...
'Check milliseconds' ,'warn', ...
struct('WindowStyle',{'modal'},'Interpreter',{'tex'}) );
FIyyyy = str2num(F(:,1:4));%#ok
FImonth= str2num(F(:,6:7));%#ok
FIdd = str2num(F(:,9:10));%#ok
FIHH = str2num(F(:,12:13));%#ok
FIMM = str2num(F(:,15:16));%#ok
FISS = str2num(F(:,18:19));%#ok
FIddd = dayofyear(FIyyyy',FImonth',FIdd')';%julian Day
FIsec = FISS + FIMM*60 + FIHH*3600 + (FIddd)*86400;
case 'YYYY.MM.DD-hh.mm.ss.stn.sac.e';
% Format: 2003.10.07-05.07.15.DALA.sac.z
% YF add warning 2021/Nov/28
msgbox( 'Only correct for traces with start times of \bfzero milliseconds\rm!', ...
'Check milliseconds' ,'warn', ...
struct('WindowStyle',{'modal'},'Interpreter',{'tex'}) );
FIyyyy = str2num(F(:,1:4));%#ok
FImonth= str2num(F(:,6:7));%#ok
FIdd = str2num(F(:,9:10));%#ok
FIHH = str2num(F(:,12:13));%#ok
FIMM = str2num(F(:,15:16));%#ok
FISS = str2num(F(:,18:19));%#ok
FIddd = dayofyear(FIyyyy',FImonth',FIdd')';%julian Day
FIsec = FISS + FIMM*60 + FIHH*3600 + (FIddd)*86400;
case 'YYYY_MM_DD_hhmm_stnn.sac.e';
% Format: 2005_03_02_1155_pptl.sac (LDG/CEA data)
% YF add warning 2021/Nov/28
msgbox( 'Only correct for traces with start times of \bfzero seconds\rm!', ...
'Check seconds' ,'warn', ...
struct('WindowStyle',{'modal'},'Interpreter',{'tex'}) );
FIyyyy = str2num(F(:,1:4));%#ok
FImonth= str2num(F(:,6:7));%#ok
FIdd = str2num(F(:,9:10));%#ok
FIHH = str2num(F(:,12:13));%#ok
FIMM = str2num(F(:,14:15));%#ok
FIddd = dayofyear(FIyyyy',FImonth',FIdd')';%julian Day
FIsec = FIMM*60 + FIHH*3600 + (FIddd)*86400;
case 'stn.YYMMDD.hhmmss.e'
% Format: fp2.030723.213056.X (BroadBand OBS data)
% YF add warning 2021/Nov/28
msgbox( {'Only correct for traces with start times of \bfzero milliseconds\rm!'; ...
'Only correct for \bfyear 2000 or later\rm!'}, ...
'Check milliseconds and year' ,'warn', ...
struct('WindowStyle',{'modal'},'Interpreter',{'tex'}) );
FIyyyy = 2000 + str2num(F(:,5:6));%#ok %only two-digit year identifier => add 2000, assuming no OBS data before 2000
FImonth= str2num(F(:,7:8));%#ok
FIdd = str2num(F(:,9:10));%#ok
FIHH = str2num(F(:,12:13));%#ok
FIMM = str2num(F(:,14:15));%#ok
FISS = str2num(F(:,16:17));%#ok
FIddd = dayofyear(FIyyyy',FImonth',FIdd')';%julian Day
FIsec = FISS + FIMM*60 + FIHH*3600 + (FIddd)*86400;
end
Omarker = zeros(size(FIsec));
end
%% get earthquake origin times
EQsec=zeros(1,length(eqin));
for a=1:length(eqin);
EQsec(a) = eqin(a).date(6) + eqin(a).date(5)*60 + eqin(a).date(4)*3600 + eqin(a).date(7)*86400;
end
% EOF
EQsec = EQsec + offset;