-
Notifications
You must be signed in to change notification settings - Fork 1
/
load_sequence.m
92 lines (77 loc) · 2.15 KB
/
load_sequence.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
function [survey] = load_sequence(file_name)
% [tlines clines] = load_sequence(file_name)
% Loads an SGL survey sequence file. Returns two structures defining the
% traverse and control survey lines.
f = fopen(file_name,'r');
%
% First line has the grid definition
%
s = fgets(f);
C = textscan(s,'%s %s %s');
survey.utm_zone= char(C{3});
%
% Second line defines the traverse reference line
%
s = fgets(f);
C = textscan(s,'%f %f %f %f %f %s %f');
tlines.ref_pt1= [C{1} C{2}];
tlines.ref_pt2 = [C{3} C{4}];
tlines.spacing = C{7};
tlines.n_lines = 0;
tlines.line = [];
tlines.theta = atan2(C{4} - C{2}, C{3} - C{1});
theta = tlines.theta;
%
% Third line line defines the control reference line
%
s = fgets(f);
C = textscan(s,'%f %f %f %s %f');
clines.start_offset = C{1};
clines.intersection_angle = C{2} * pi / 180;
clines.spacing = C{5};
clines.n_lines = 0;
clines.line = [];
clines.phi = theta - clines.intersection_angle;
phi = clines.phi;
alpha = clines.intersection_angle;
%
% Traverse lines
%
s = fgets(f);
if(~strncmp(s,'TLIMITS', 7))
error('Invalid sequence file');
return;
end
s = fgets(f);
while(~strncmp(s,'CLIMITS',7))
n_lines = tlines.n_lines + 1;
C = textscan(s,'%d %fm %fm');
tlines.n_lines = n_lines;
tlines.line(n_lines).num = C{1};
start_lim = C{2};
end_lim = C{3};
tmp = tlines.ref_pt1 + (n_lines-1) * tlines.spacing * [sin(theta) -cos(theta)];
tlines.line(n_lines).pt1 = tmp + start_lim * [cos(theta) sin(theta)];
tlines.line(n_lines).pt2 = tmp + end_lim * [cos(theta) sin(theta)];
s = fgets(f);
end
%
% Control lines
%
s = fgets(f);
while(~strncmp(s,'ENDGRID',7))
C = textscan(s,'%d T%d%f T%d%f');
clines.n_lines = clines.n_lines + 1;
n_lines = clines.n_lines;
clines.line(n_lines).num = C{1};
start_lim = C{3};
end_lim = C{5};
tmp = tlines.ref_pt1 + ...
((n_lines-1) * clines.spacing / sin(alpha) + clines.start_offset) * [cos(theta) sin(theta)];
clines.line(n_lines).pt1 = tmp + start_lim * [cos(phi) sin(phi)];
clines.line(n_lines).pt2 = tmp + end_lim * [cos(phi) sin(phi)] + ...
(tlines.n_lines - 1) * tlines.spacing / sin(alpha) * [cos(phi) sin(phi)];
s = fgets(f);
end
survey.tlines = tlines;
survey.clines = clines;