-
Notifications
You must be signed in to change notification settings - Fork 9
/
a3_a_run_autowinpick.m
78 lines (66 loc) · 1.9 KB
/
a3_a_run_autowinpick.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
% Scripts to run the auto_win_pick function for all the events and generate a old version "events" file
clear;
%plot native;
isfigure = 1;
is_overwrite = 1;
% Setup parameters
setup_parameters
% eventmatpath = './eventmat/';
% outwinpath = './winpara/';
workingdir = parameters.workingdir;
eventmatpath = [workingdir,'eventmat/'];
outwinpath = [workingdir,'winpara/'];
if ~exist(outwinpath,'dir')
mkdir(outwinpath)
end
% Setup Error Codes for Bad data
setup_ErrorCode
periods = parameters.periods;
comp = parameters.component;
matfiles = dir([eventmatpath,'/*_',comp,'.mat']);
for ie = 1:length(matfiles)
clear event eventcs CS
% read in the events information
temp = load([eventmatpath,matfiles(ie).name]);
event = temp.event;
disp(event.id)
if ~is_overwrite
filename = [outwinpath,'/',event.id,'_',comp,'.bad'];
if exist(filename,'file')
disp(['Exist: ',filename,' Skip!']);
continue;
end
filename = [outwinpath,'/',event.id,'_',comp,'.win'];
if exist(filename,'file')
disp(['Exist: ',filename,' Skip!']);
continue;
end
end
% set up some useful arrays
stlas = [event.stadata(:).stla];
stlos = [event.stadata(:).stlo];
stnms = {event.stadata(:).stnm};
dists = [event.stadata(:).dist];
% automatically select the signal window by using ftan method
disp('Start to picking the window');
tic
[winpara event] = auto_win_select(event);
toc
if isfigure && length(find([event.stadata.isgood]>0))>1
plot_win_select(event,periods,winpara);
end
if length(winpara) ~= 4
filename = [outwinpath,'/',event.id,'_',comp,'.bad'];
fp = fopen(filename,'w');
fprintf(fp,'%f\n',0);
fclose(fp);
continue;
end
filename = [outwinpath,'/',event.id,'_',comp,'.win'];
fp = fopen(filename,'w');
fprintf(fp,'%s %f %f %f %f\n',event.id,winpara(1),winpara(2),winpara(3),winpara(4));
fclose(fp);
event.winpara = winpara;
save([eventmatpath,matfiles(ie).name],'event');
disp(winpara);
end % end of event