-
Notifications
You must be signed in to change notification settings - Fork 2
/
station_check.m
53 lines (49 loc) · 1.16 KB
/
station_check.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
function station_check(fname)
%
% Given edited station list `fname` (i.e. unnecessary stations commented out)
% diagnose the stations
%
%
fid = fopen(fname, 'r');
% stations to be included
good = [];
n = 0;
while 1
tline = fgetl(fid);
if ~ischar(tline)
break;
end
% commented out
if tline(1) == '%' || tline(1) == '#'
continue;
end
words = textscan(tline, '%s', 4);
m = sscanf(words{1}{1}, '%d');
% assume no flag
lat = sscanf(words{1}{2}, '%f');
lon = sscanf(words{1}{3}, '%f');
if isempty(lat)
% we have flag
lat = sscanf(words{1}{3}, '%f');
lon = sscanf(words{1}{4}, '%f');
end
n = n + 1;
lats(n) = lat;
lons(n) = lon;
label(n) = m;
end
idx = sort_stations(lons, lats);
%
% station distance
%
cum = 0;
for i = 2:n
j0 = idx(i);
j1 = idx(i-1);
dx = gsw_distance([lons(j0), lons(j1)], [lats(j0), lats(j1)]) / 1852;
cum = cum + dx;
%fprintf(2, '%3d -- %3d %8.2f nm %8.2f nm\n', label(i-1), label(i), dx, cum);
fprintf(2, '%3d -- %3d %8.2f nm\n', label(j1), label(j0), dx);
end
%plot(lons, lats, 'o', 'Color', 'r');
plot(lons, lats, 'x', 'Color', 'b');