-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathSRTParse_PICASIntruder.m
158 lines (146 loc) · 6.37 KB
/
SRTParse_PICASIntruder.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
% Copyright (c) 2022 National Research Council Canada
function [ out ] = SRT_PARSE( file, DBG )
%SRT_PARSE: extract aircraft data from srt file
% Detailed explanation goes here
%Open File for Parsing
fid = fopen(file, 'rb');
%Set Not Debug if No Debug Variabl is Passed
if ~exist('DBG');
DBG = 0;
end
%File Does Not Exist?
if(fid < 0)
fprintf(2, 'ERROR: The File "%s" Does Not Exist!\n\n', file);
return;
end
out = cell(0,0);
%Initial State
STATE = 0;
%Main Loop Parses File.
line = '';
tst = [1,1];
while STATE ~= -1
%Set Loop Condition
tst = [];
%Read Lines Until Line With Writing is Found End if EOF
while length(tst) == 0
line = fgets(fid);
if feof(fid)
STATE = -1;
break;
end
tst = regexp(line, '[a-zA-Z0-9]');
end
%Parse Current Line
switch STATE
case -1
break;
case 0
%Make Sure This is a Frame Number
if DBG
fprintf(1, 'CASE %d: %s', STATE, line);
end
if isnan(str2double(line))
fprintf(2, 'ERROR: Incorrect Format of Input File %s\n\n', file);
return;
end
%Create Entry for new Frame
out = [out; cell(1,1)];
out{end} = struct('host_gpstime', 0, 'cam_gpstime', 0, 'frame_gpstime', 0, 'index', 0, ...
'elapsed_time',...
0, 'host_roll', 0, 'host_pitch', 0, 'host_hdg', 0, 'cam_roll', 0,...
'cam_pitch', 0, 'cam_hdg', 0, 'host_alt_gps_ft', 0, 'host_alt_agl_ft', 0,...
'host_lat', 0, 'host_lon', 0, 'cam_lat', 0, 'cam_lon', 0, 'cam_alt_gps_ft', 0,...
'cam_p', 0, 'cam_q', 0, 'cam_r', 0, 'cam_acc_x', 0,'cam_acc_y', 0, 'cam_acc_z',0 );
nums = regexp(line, '[-]?\d\d*+\.?\d*');
out{end} = struct('frameIndex', str2double(strtok(line(nums(1):end), ' ')), 'gps_time', 0);
STATE = 1;
case 1
%Ignore Time Stamp (For Now)
if DBG
fprintf(1, 'CASE %d: %s', STATE, line);
end
STATE = 2;
case 2
if DBG
fprintf(1, 'CASE %d: %s', STATE, line);
end
nums = regexp(line, '[-]?\d\d*+\.?\d*');
out{end}.host_gpstime = str2double(strtok(line(nums(1):end), ' ')); %num
out{end}.cam_gpstime = str2double(strtok(line(nums(2):end), ' ')); %num
out{end}.frame_gpstime = str2double(strtok(line(nums(3):end), ' ')); %sec
STATE = 3;
case 3
if DBG
fprintf(1, 'CASE %d: %s', STATE, line);
end
nums = regexp(line, '[-]?\d\d*+\.?\d*');
out{end}.index = str2double(strtok(line(nums(1):end), ' ')); %deg
STATE = 4;
case 4
if DBG
fprintf(1, 'CASE %d: %s', STATE, line);
end
nums = regexp(line, '[-]?\d\d*+\.?\d*');
out{end}.host_roll = str2double(strtok(line(nums(1):end), ' ')); %deg
out{end}.host_pitch = str2double(strtok(line(nums(2):end), ' ')); %deg
out{end}.host_hdg = str2double(strtok(line(nums(3):end), ' ')); %ft
STATE = 5;
case 5
if DBG
fprintf(1, 'CASE %d: %s', STATE, line);
end
nums = regexp(line, '[-]?\d\d*+\.?\d*');
out{end}.host_lat = str2double(strtok(line(nums(1):end), ' ')); %deg
out{end}.host_lon = str2double(strtok(line(nums(2):end), ' ')); %deg
out{end}.host_alt_gps_ft = str2double(strtok(line(nums(3):end), ' ')); %deg
out{end}.host_alt_agl_ft = str2double(strtok(line(nums(4):end), ' ')); %deg
STATE = 6;
case 6
if DBG
fprintf(1, 'CASE %d: %s', STATE, line);
end
nums = regexp(line, '[-]?\d\d*+\.?\d*');
out{end}.cam_roll = str2double(strtok(line(nums(1):end), ' ')); %deg
out{end}.cam_pitch = str2double(strtok(line(nums(2):end), ' ')); %deg
out{end}.cam_hdg = str2double(strtok(line(nums(3):end), ' ')); %ft
STATE = 7;
case 7
if DBG
fprintf(1, 'CASE %d: %s', STATE, line);
end
nums = regexp(line, '[-]?\d\d*+\.?\d*');
out{end}.cam_lat = str2double(strtok(line(nums(1):end), ' ')); %deg
out{end}.cam_lon = str2double(strtok(line(nums(2):end), ' ')); %deg
out{end}.cam_alt_gps_ft = str2double(strtok(line(nums(3):end), ' ')); %deg
STATE = 8;
case 8
if DBG
fprintf(1, 'CASE %d: %s', STATE, line);
end
nums = regexp(line, '[-]?\d\d*+\.?\d*');
out{end}.cam_P = str2double(strtok(line(nums(1):end), ' ')); %deg
out{end}.cam_Q = str2double(strtok(line(nums(2):end), ' ')); %deg
out{end}.cam_R = str2double(strtok(line(nums(3):end), ' ')); %deg
STATE = 9;
case 9
if DBG
fprintf(1, 'CASE %d: %s', STATE, line);
end
nums = regexp(line, '[-]?\d\d*+\.?\d*');
out{end}.cam_acc_x = str2double(strtok(line(nums(1):end), ' ')); %deg
out{end}.cam_acc_y = str2double(strtok(line(nums(2):end), ' ')); %deg
out{end}.cam_acc_z = str2double(strtok(line(nums(3):end), ' ')); %deg
STATE = 0;
% case 5
% if DBG
% fprintf(1, 'CASE %d: %s', STATE, line);
% end
% nums = regexp(line, '[-]?\d\d*+\.?\d*');
% out{end}.altitude_gps = str2double(strtok(line(nums(1):end), ' ')); %ft
% out{end}.altitude_agl = str2double(strtok(line(nums(2):end), ' ')); %ft
% STATE = 0;
otherwise
end
end
end