forked from esokos/isola
-
Notifications
You must be signed in to change notification settings - Fork 0
/
allstat.m
95 lines (86 loc) · 3.73 KB
/
allstat.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
function [] = allstat
% read allstat.dat
h=dir('.\invert\allstat.dat');
%
if isempty(h);
errordlg('allstat.dat file doesn''t exist in invert folder. Run Station Selection. ','File Error');
return
else
% try to guess allstat version
fid=fopen('.\invert\allstat.dat');
tline=fgets(fid);
[~,cnt]=sscanf(tline,'%s');
fclose(fid);
switch cnt
case 9
disp('Found current version of allstat e.g. STA 1 1 1 1 f1 f2 f3 f4')
case 6
disp('Found version of allstat without frequencies e.g. 001 1 1 1 1 STA. Will be converted to new version.')
[~,d1,d2,d3,d4,NS] = textread('.\invert\allstat.dat','%s %f %f %f %f %s',-1);
nsta=length(NS);
% read freq band from inpinv.dat
a=exist('.\invert\inpinv.dat','file');
if a==2
fid = fopen('.\invert\inpinv.dat','r');
for i=1:3
aa=fgetl(fid);
end
dtime=fgetl(fid);
for i=1:6
aa=fgetl(fid);
end
nsubevents=fgetl(fid);
for i=1:2
aa=fgetl(fid);
end
invband=fgetl(fid);
fclose(fid);
else
end
% output
labp=char(NS);
fid = fopen('test.dat','w');
for p=1:nsta
if ispc
fprintf(fid,'%s %u %u %u %u %s\r\n', labp(p,1:end),d1(p),d2(p),d3(p),d4(p),invband);
else
fprintf(fid,'%s %u %u %u %u %s\n', labp(p,1:end),d1(p),d2(p),d3(p),d4(p),invband);
end
end
fclose(fid);
case 5
disp('Found old version of allstat without frequencies and without station masking e.g. STA 1 1 1 1. Will be converted to new version')
[NS,d1,d2,d3,d4] = textread('.\invert\allstat.dat','%s %f %f %f %f',-1);
nsta=length(NS);
% read freq band from inpinv.dat
a=exist('.\invert\inpinv.dat','file');
if a==2
fid = fopen('.\invert\inpinv.dat','r');
for i=1:3
aa=fgetl(fid);
end
dtime=fgetl(fid);
for i=1:6
aa=fgetl(fid);
end
nsubevents=fgetl(fid);
for i=1:2
aa=fgetl(fid);
end
invband=fgetl(fid);
fclose(fid);
else
end
% output
labp=char(NS);
fid = fopen('test.dat','w');
for p=1:nsta
if ispc
fprintf(fid,'%s %u %u %u %u %s\r\n', labp(p,1:end),d1(p),d2(p),d3(p),d4(p),invband);
else
fprintf(fid,'%s %u %u %u %u %s\n', labp(p,1:end),d1(p),d2(p),d3(p),d4(p),invband);
end
end
fclose(fid);
end
end