1 | // Part of BNC, a utility for retrieving decoding and
|
---|
2 | // converting GNSS data streams from NTRIP broadcasters.
|
---|
3 | //
|
---|
4 | // Copyright (C) 2007
|
---|
5 | // German Federal Agency for Cartography and Geodesy (BKG)
|
---|
6 | // http://www.bkg.bund.de
|
---|
7 | // Czech Technical University Prague, Department of Geodesy
|
---|
8 | // http://www.fsv.cvut.cz
|
---|
9 | //
|
---|
10 | // Email: euref-ip@bkg.bund.de
|
---|
11 | //
|
---|
12 | // This program is free software; you can redistribute it and/or
|
---|
13 | // modify it under the terms of the GNU General Public License
|
---|
14 | // as published by the Free Software Foundation, version 2.
|
---|
15 | //
|
---|
16 | // This program is distributed in the hope that it will be useful,
|
---|
17 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
18 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
19 | // GNU General Public License for more details.
|
---|
20 | //
|
---|
21 | // You should have received a copy of the GNU General Public License
|
---|
22 | // along with this program; if not, write to the Free Software
|
---|
23 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
---|
24 |
|
---|
25 | /* -------------------------------------------------------------------------
|
---|
26 | * BKG NTRIP Client
|
---|
27 | * -------------------------------------------------------------------------
|
---|
28 | *
|
---|
29 | * Class: t_rnxObsFile
|
---|
30 | *
|
---|
31 | * Purpose: Reads RINEX Observation File
|
---|
32 | *
|
---|
33 | * Author: L. Mervart
|
---|
34 | *
|
---|
35 | * Created: 24-Jan-2012
|
---|
36 | *
|
---|
37 | * Changes:
|
---|
38 | *
|
---|
39 | * -----------------------------------------------------------------------*/
|
---|
40 |
|
---|
41 | #include <iostream>
|
---|
42 | #include <iomanip>
|
---|
43 | #include "rnxobsfile.h"
|
---|
44 | #include "bncutils.h"
|
---|
45 |
|
---|
46 | using namespace std;
|
---|
47 |
|
---|
48 | // Constructor
|
---|
49 | ////////////////////////////////////////////////////////////////////////////
|
---|
50 | t_rnxObsFile::t_rnxObsHeader::t_rnxObsHeader() {
|
---|
51 | _antNEU.ReSize(3);
|
---|
52 | _xyz.ReSize(3);
|
---|
53 | _antNEU = 0.0;
|
---|
54 | _xyz = 0.0;
|
---|
55 | _version = 0.0;
|
---|
56 | }
|
---|
57 |
|
---|
58 | // Destructor
|
---|
59 | ////////////////////////////////////////////////////////////////////////////
|
---|
60 | t_rnxObsFile::t_rnxObsHeader::~t_rnxObsHeader() {
|
---|
61 | }
|
---|
62 |
|
---|
63 | // Read Header
|
---|
64 | ////////////////////////////////////////////////////////////////////////////
|
---|
65 | t_irc t_rnxObsFile::t_rnxObsHeader::read(QTextStream* stream) {
|
---|
66 | while (stream->status() == QTextStream::Ok && !stream->atEnd()) {
|
---|
67 | QString line = stream->readLine();
|
---|
68 | if (line.isEmpty()) {
|
---|
69 | continue;
|
---|
70 | }
|
---|
71 | QString value = line.left(60).trimmed();
|
---|
72 | QString key = line.mid(60).trimmed();
|
---|
73 | if (key == "END OF HEADER") {
|
---|
74 | break;
|
---|
75 | }
|
---|
76 | else if (key == "RINEX VERSION / TYPE") {
|
---|
77 | QTextStream in(value.toAscii(), QIODevice::ReadOnly);
|
---|
78 | in >> _version;
|
---|
79 | }
|
---|
80 | else if (key == "MARKER NAME") {
|
---|
81 | _markerName = value;
|
---|
82 | }
|
---|
83 | else if (key == "ANT # / TYPE") {
|
---|
84 | _antennaName = value.mid(20);
|
---|
85 | }
|
---|
86 | else if (key == "APPROX POSITION XYZ") {
|
---|
87 | QTextStream in(value.toAscii(), QIODevice::ReadOnly);
|
---|
88 | in >> _xyz[0] >> _xyz[1] >> _xyz[2];
|
---|
89 | }
|
---|
90 | else if (key == "ANTENNA: DELTA H/E/N") {
|
---|
91 | QTextStream in(value.toAscii(), QIODevice::ReadOnly);
|
---|
92 | in >> _antNEU[2] >> _antNEU[1] >> _antNEU[0];
|
---|
93 | }
|
---|
94 | else if (key == "# / TYPES OF OBSERV") {
|
---|
95 | QTextStream in(value.toAscii(), QIODevice::ReadOnly);
|
---|
96 | int nTypes;
|
---|
97 | in >> nTypes;
|
---|
98 | for (int ii = 0; ii < nTypes; ii++) {
|
---|
99 | QString hlp;
|
---|
100 | in >> hlp;
|
---|
101 | _obsTypesV2 << hlp;
|
---|
102 | }
|
---|
103 | }
|
---|
104 | else if (key == "SYS / # / OBS TYPES") {
|
---|
105 | QTextStream* in = new QTextStream(value.toAscii(), QIODevice::ReadOnly);
|
---|
106 | char sys;
|
---|
107 | int nTypes;
|
---|
108 | *in >> sys >> nTypes;
|
---|
109 | for (int ii = 0; ii < nTypes; ii++) {
|
---|
110 | if (ii > 0 && ii % 13 == 0) {
|
---|
111 | line = stream->readLine();
|
---|
112 | delete in;
|
---|
113 | in = new QTextStream(line.toAscii(), QIODevice::ReadOnly);
|
---|
114 | }
|
---|
115 | QString hlp;
|
---|
116 | *in >> hlp;
|
---|
117 | _obsTypesV3[sys] << hlp;
|
---|
118 | }
|
---|
119 | delete in;
|
---|
120 | }
|
---|
121 | }
|
---|
122 |
|
---|
123 | return success;
|
---|
124 | }
|
---|
125 |
|
---|
126 | // Constructor
|
---|
127 | ////////////////////////////////////////////////////////////////////////////
|
---|
128 | t_rnxObsFile::t_rnxObsFile(QString fileName) {
|
---|
129 | expandEnvVar(fileName);
|
---|
130 | _file = new QFile(fileName);
|
---|
131 | _file->open(QIODevice::ReadOnly | QIODevice::Text);
|
---|
132 | _stream = new QTextStream();
|
---|
133 | _stream->setDevice(_file);
|
---|
134 | _header.read(_stream);
|
---|
135 | }
|
---|
136 |
|
---|
137 | // Destructor
|
---|
138 | ////////////////////////////////////////////////////////////////////////////
|
---|
139 | t_rnxObsFile::~t_rnxObsFile() {
|
---|
140 | delete _stream;
|
---|
141 | delete _file;
|
---|
142 | }
|
---|
143 |
|
---|
144 | // Retrieve single Epoch
|
---|
145 | ////////////////////////////////////////////////////////////////////////////
|
---|
146 | const t_rnxObsFile::t_epo* t_rnxObsFile::nextEpoch() {
|
---|
147 |
|
---|
148 | _currEpo.clear();
|
---|
149 |
|
---|
150 | if (version() < 3.0) {
|
---|
151 | return nextEpochV2();
|
---|
152 | }
|
---|
153 | else {
|
---|
154 | return nextEpochV3();
|
---|
155 | }
|
---|
156 | }
|
---|
157 |
|
---|
158 | // Retrieve single Epoch (RINEX Version 3)
|
---|
159 | ////////////////////////////////////////////////////////////////////////////
|
---|
160 | const t_rnxObsFile::t_epo* t_rnxObsFile::nextEpochV3() {
|
---|
161 | while (_stream->status() == QTextStream::Ok && !_stream->atEnd()) {
|
---|
162 |
|
---|
163 | QString line = _stream->readLine();
|
---|
164 |
|
---|
165 | if (line.isEmpty()) {
|
---|
166 | continue;
|
---|
167 | }
|
---|
168 |
|
---|
169 | if (line.indexOf("END OF FILE") != -1) {
|
---|
170 | break;
|
---|
171 | }
|
---|
172 |
|
---|
173 | int flag;
|
---|
174 | readInt(line, 31, 1, flag);
|
---|
175 | if (flag > 1) { // TODO
|
---|
176 | break;
|
---|
177 | }
|
---|
178 |
|
---|
179 | QTextStream in(line.mid(1).toAscii());
|
---|
180 |
|
---|
181 | // Epoch Time
|
---|
182 | // ----------
|
---|
183 | int year, month, day, hour, min;
|
---|
184 | double sec;
|
---|
185 | in >> year >> month >> day >> hour >> min >> sec;
|
---|
186 | _currEpo.tt.set(year, month, day, hour, min, sec);
|
---|
187 |
|
---|
188 | // Number of Satellites
|
---|
189 | // --------------------
|
---|
190 | int numSat;
|
---|
191 | readInt(line, 32, 3, numSat);
|
---|
192 |
|
---|
193 | _currEpo.satObs.resize(numSat);
|
---|
194 |
|
---|
195 | // Observations
|
---|
196 | // ------------
|
---|
197 | for (int iSat = 0; iSat < numSat; iSat++) {
|
---|
198 | line = _stream->readLine();
|
---|
199 | _currEpo.satObs[iSat].prn = line.mid(0,3);
|
---|
200 | char sys = _currEpo.satObs[iSat].prn[0].toAscii();
|
---|
201 | if (_currEpo.satObs[iSat].size() != _header.nTypes(sys)) {
|
---|
202 | _currEpo.satObs[iSat].ReSize(_header.nTypes(sys));
|
---|
203 | }
|
---|
204 | for (int iType = 0; iType < _header.nTypes(sys); iType++) {
|
---|
205 | int pos = 3 + 16*iType;
|
---|
206 | readDbl(line, pos, 14, _currEpo.satObs[iSat][iType]);
|
---|
207 | readInt(line, pos + 14, 1, _currEpo.satObs[iSat].lli);
|
---|
208 | readInt(line, pos + 15, 1, _currEpo.satObs[iSat].snr);
|
---|
209 | }
|
---|
210 | }
|
---|
211 |
|
---|
212 | return &_currEpo;
|
---|
213 | }
|
---|
214 |
|
---|
215 | return 0;
|
---|
216 | }
|
---|
217 |
|
---|
218 | // Retrieve single Epoch (RINEX Version 2)
|
---|
219 | ////////////////////////////////////////////////////////////////////////////
|
---|
220 | const t_rnxObsFile::t_epo* t_rnxObsFile::nextEpochV2() {
|
---|
221 | while (_stream->status() == QTextStream::Ok && !_stream->atEnd()) {
|
---|
222 |
|
---|
223 | QString line = _stream->readLine();
|
---|
224 |
|
---|
225 | if (line.isEmpty()) {
|
---|
226 | continue;
|
---|
227 | }
|
---|
228 |
|
---|
229 | if (line.indexOf("END OF FILE") != -1) {
|
---|
230 | break;
|
---|
231 | }
|
---|
232 |
|
---|
233 | int flag;
|
---|
234 | readInt(line, 28, 1, flag);
|
---|
235 | if (flag > 1) { // TODO
|
---|
236 | break;
|
---|
237 | }
|
---|
238 |
|
---|
239 | QTextStream in(line.toAscii());
|
---|
240 |
|
---|
241 | // Epoch Time
|
---|
242 | // ----------
|
---|
243 | int year, month, day, hour, min;
|
---|
244 | double sec;
|
---|
245 | in >> year >> month >> day >> hour >> min >> sec;
|
---|
246 | if (year < 80) {
|
---|
247 | year += 2000;
|
---|
248 | }
|
---|
249 | else if (year < 100) {
|
---|
250 | year += 1900;
|
---|
251 | }
|
---|
252 | _currEpo.tt.set(year, month, day, hour, min, sec);
|
---|
253 |
|
---|
254 | // Number of Satellites
|
---|
255 | // --------------------
|
---|
256 | int numSat;
|
---|
257 | readInt(line, 29, 3, numSat);
|
---|
258 |
|
---|
259 | _currEpo.satObs.resize(numSat);
|
---|
260 |
|
---|
261 | // Read Satellite Numbers
|
---|
262 | // ----------------------
|
---|
263 | int pos = 32;
|
---|
264 | for (int iSat = 0; iSat < numSat; iSat++) {
|
---|
265 | if (iSat > 0 && iSat % 12 == 0) {
|
---|
266 | line = _stream->readLine();
|
---|
267 | pos = 32;
|
---|
268 | }
|
---|
269 | QString prn = line.mid(pos, 3);
|
---|
270 | pos += 3;
|
---|
271 |
|
---|
272 | _currEpo.satObs[iSat].prn = prn;
|
---|
273 | char sys = prn[0].toAscii();
|
---|
274 | _currEpo.satObs[iSat].ReSize(_header.nTypes(sys));
|
---|
275 | }
|
---|
276 |
|
---|
277 | // Read Observation Records
|
---|
278 | // ------------------------
|
---|
279 | for (int iSat = 0; iSat < numSat; iSat++) {
|
---|
280 | line = _stream->readLine();
|
---|
281 | pos = 0;
|
---|
282 | QString prn = _currEpo.satObs[iSat].prn;
|
---|
283 | char sys = prn[0].toAscii();
|
---|
284 | for (int iType = 0; iType < _header.nTypes(sys); iType++) {
|
---|
285 | if (iType > 0 && iType % 5 == 0) {
|
---|
286 | line = _stream->readLine();
|
---|
287 | pos = 0;
|
---|
288 | }
|
---|
289 | readDbl(line, pos, 14, _currEpo.satObs[iSat][iType]);
|
---|
290 | readInt(line, pos + 14, 1, _currEpo.satObs[iSat].lli);
|
---|
291 | readInt(line, pos + 15, 1, _currEpo.satObs[iSat].snr);
|
---|
292 | pos += 16;
|
---|
293 | }
|
---|
294 | }
|
---|
295 |
|
---|
296 | return &_currEpo;
|
---|
297 | }
|
---|
298 |
|
---|
299 | return 0;
|
---|
300 | }
|
---|