forked from manromao/RINEX-reader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreadRinexNav.m
executable file
·239 lines (196 loc) · 9.22 KB
/
readRinexNav.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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
function [ outputEphemeris] = readRinexNav( filePath )
%readRinexNav Reads a mixed RINEX navigation file *.nav and returns the
%loaded ephemeris for each constellation
% Reads Keplerian and Cartesian type ephemeris coming from RINEX 3.02
% Files can be downlaoded from here: ftp://cddis.gsfc.nasa.gov/gnss/data/campaign/mgex/daily/rinex3/2015/
% Download in *.p format and convert to .nav using rtklib
%%%%%-------Input
% fileName = File adress
%%%%%------- Output
% outputEphemeris = Class containing the ephemeris for each
% constellation
'Loading ephemeris...'
endOfHeader = 0;
navFile = fopen(filePath);
%Read header
while (~endOfHeader)
line = fgetl(navFile);
lineSplit = strsplit(line);
if strfind(line,'RINEX VERSION')
Version = lineSplit(2);
if ~strcmp(Version,'3.02')
error 'Not the correct version, should be 3.02'
end
elseif strfind(line,'DATE')
date = lineSplit(3);
year = str2doubleq(date{1,1}(1:4));
month = str2doubleq(date{1,1}(5:6));
day = str2doubleq(date{1,1}(7:8));
DOY=Date2DayOfYear(real(year),real(month),real(day));
elseif strfind(line,'IONOSPHERIC CORR')
if strcmp(lineSplit(1), 'GPSA')
ionoAlpha = str2doubleq(lineSplit(2:5));
elseif strcmp(lineSplit(1), 'GPSB')
ionoBeta = str2doubleq(lineSplit(2:5));
end
elseif strfind (line,'LEAP SECONDS')
leapSeconds = str2doubleq(lineSplit(2));
elseif strfind(line,'END OF HEADER')
endOfHeader = 1;
end
end
%Pointer line set at the end of the header.
ionosphericParameters = [ionoAlpha; ionoBeta];
%read body
gpsEphemeris = [];
glonassEphemeris = [];
beidouEphemeris = [];
keplerArray = zeros(22,1); %Vector containing Keplerian elements type ephemeris (GPS, Beidou, Galileo)
cartesianArray = zeros(19,1); %Vector containing Cartesian type ephemeris (GLONASS, SBAS)
while ~feof(navFile)
line = fgetl(navFile);
lineSplit = strsplit(line);
constellation = line(1);
if ischar(constellation) %New Ephemeris
switch constellation
case {'G', 'C'} %If the ephemeris is ether for GPS or Beidou, store Keplerian elements
%%Read All of the ephemeris
svprn = str2doubleq([line(2), line(3)]);
af0 = str2doubleq(lineSplit(end-2)); %Read from end because of 1 digit prn
af1 = str2doubleq(lineSplit(end-1));
af2 = str2doubleq(lineSplit(end));
lineSplit = strsplit(fgetl(navFile)); %
IODE = str2doubleq(lineSplit(2));
crs = str2doubleq(lineSplit(3));
deltan = str2doubleq(lineSplit(4));
M0 = str2doubleq(lineSplit(5));
lineSplit = strsplit(fgetl(navFile)); %
cuc = str2doubleq(lineSplit(2));
ecc = str2doubleq(lineSplit(3));
cus = str2doubleq(lineSplit(4));
roota = str2doubleq(lineSplit(5));
lineSplit = strsplit(fgetl(navFile));
toe = str2doubleq(lineSplit(2));
cic = str2doubleq(lineSplit(3));
Omega0 = str2doubleq(lineSplit(4));
cis = str2doubleq(lineSplit(5));
lineSplit = strsplit(fgetl(navFile)); %
i0 = str2doubleq(lineSplit(2));
crc = str2doubleq(lineSplit(3));
omega = str2doubleq(lineSplit(4));
Omegadot = str2doubleq(lineSplit(5));
lineSplit = strsplit(fgetl(navFile)); %
idot = str2doubleq(lineSplit(2));
CodesOnL2 = str2doubleq(lineSplit(3));
week_toe = str2doubleq(lineSplit(4));
L2Pflag = str2doubleq(lineSplit(5));
lineSplit = strsplit(fgetl(navFile)); %
SVaccuracy = str2doubleq(lineSplit(2));
SVhealth = str2doubleq(lineSplit(3));
tgd = str2doubleq(lineSplit(4));
IODC = str2doubleq(lineSplit(5));
lineSplit = strsplit(fgetl(navFile));
transmissionTime = str2doubleq(lineSplit(2));
fitInterval = str2doubleq(lineSplit(3));
%Conversion to the format required by function
%sat_coordinates_XYZ
keplerArray(1) = svprn;
keplerArray(2) = af2;
keplerArray(3) = M0;
keplerArray(4) = roota;
keplerArray(5) = deltan;
keplerArray(6) = ecc;
keplerArray(7) = omega;
keplerArray(8) = cuc;
keplerArray(9) = cus;
keplerArray(10) = crc;
keplerArray(11) = crs;
keplerArray(12) = i0;
keplerArray(13) = idot;
keplerArray(14) = cic;
keplerArray(15) = cis;
keplerArray(16) = Omega0;
keplerArray(17) = Omegadot;
keplerArray(18) = toe;
keplerArray(19) = af0;
keplerArray(20) = af1;
keplerArray(21) = toe;
keplerArray(22) = tgd;
if constellation == 'G'
gpsEphemeris = [gpsEphemeris keplerArray];
elseif constellation == 'C'
beidouEphemeris = [beidouEphemeris keplerArray];
else
error 'Unknown constellation'
%Should never reach this point, as there is a case
%above.
end
case 'R' %Also SBAS case
slot_sv=str2doubleq(line(2:3));
%Time of Emision
ToE(1)=str2doubleq(lineSplit(end-8)); %Star from the end to avoid problems with 1 digit prn
ToE(2)=str2doubleq(lineSplit(end-7));
ToE(3)=str2doubleq(lineSplit(end-6));
ToE(4)=str2doubleq(lineSplit(end-5));
ToE(5)=str2doubleq(lineSplit(end-4));
ToE(6)=str2doubleq(lineSplit(end-3));
ToE = real(ToE);
[toe,week]=Date2GPSTime(ToE(1),ToE(2),ToE(3),ToE(4)+ToE(5)/60+ToE(6)/3600);
sv_clock_bias=str2doubleq(lineSplit(end-2));
sv_rel_freq_bias=str2doubleq(lineSplit(end-1));
m_f_t=str2doubleq(lineSplit(end));
lineSplit = strsplit(fgetl(navFile));%%%
X=str2doubleq(lineSplit(2));
Xdot=str2doubleq(lineSplit(3));
Xacc=str2doubleq(lineSplit(4));
health=str2doubleq(lineSplit(5));
lineSplit = strsplit(fgetl(navFile));%%%
Y=str2doubleq(lineSplit(2));
Ydot=str2doubleq(lineSplit(3));
Yacc=str2doubleq(lineSplit(4));
freq_num=str2doubleq(lineSplit(5));
lineSplit = strsplit(fgetl(navFile));%%%
Z=str2doubleq(lineSplit(2));
Zdot=str2doubleq(lineSplit(3));
Zacc=str2doubleq(lineSplit(4));
age_oper_info=str2doubleq(lineSplit(5));
cartesianArray(1)=slot_sv;
cartesianArray(2)=toe;
cartesianArray(3)=sv_clock_bias;
cartesianArray(4)=sv_rel_freq_bias;
cartesianArray(5)=m_f_t;
cartesianArray(6)=X;
cartesianArray(7)=Xdot;
cartesianArray(8)=Xacc;
cartesianArray(9)=health;
cartesianArray(10)=Y;
cartesianArray(11)=Ydot;
cartesianArray(12)=Yacc;
cartesianArray(13)=freq_num;
cartesianArray(14)=Z;
cartesianArray(15)=Zdot;
cartesianArray(16)=Zacc;
cartesianArray(17)=age_oper_info;
cartesianArray(18)=1;
cartesianArray(19)=week;
if constellation == 'R'
glonassEphemeris = [glonassEphemeris, cartesianArray];
elseif constellation == 'S'
end
otherwise
%error 'Unknown constellation'
end
else
error ('Wrong counting. New ephemeris expected.')
end
end
% Construct output
outputEphemeris.glonassEphemeris = real(glonassEphemeris);
outputEphemeris.gpsEphemeris = real(gpsEphemeris);
outputEphemeris.beidouEphemeris = real(beidouEphemeris);
outputEphemeris.ionosphericParameters = real(ionosphericParameters);
outputEphemeris.DOY = real(DOY);
outputEphemeris.leapSeconds = real(leapSeconds);
fclose(navFile);
'Ephemeris loaded correctly'
end