source: ntrip/trunk/BNC/rnxobsfile.cpp@ 3706

Last change on this file since 3706 was 3706, checked in by mervart, 13 years ago
File size: 7.7 KB
Line 
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
46using namespace std;
47
48// Constructor
49////////////////////////////////////////////////////////////////////////////
50t_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////////////////////////////////////////////////////////////////////////////
60t_rnxObsFile::t_rnxObsHeader::~t_rnxObsHeader() {
61}
62
63// Read Header
64////////////////////////////////////////////////////////////////////////////
65t_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(value.toAscii(), QIODevice::ReadOnly);
106 char sys;
107 int nTypes;
108 in >> sys >> nTypes;
109 for (int ii = 0; ii < nTypes; ii++) {
110 QString hlp;
111 in >> hlp;
112 _obsTypesV3[sys] << hlp;
113 }
114 }
115 }
116
117 return success;
118}
119
120// Constructor
121////////////////////////////////////////////////////////////////////////////
122t_rnxObsFile::t_rnxObsFile(QString fileName) {
123 expandEnvVar(fileName);
124 _file = new QFile(fileName);
125 _file->open(QIODevice::ReadOnly | QIODevice::Text);
126 _stream = new QTextStream();
127 _stream->setDevice(_file);
128 _header.read(_stream);
129}
130
131// Destructor
132////////////////////////////////////////////////////////////////////////////
133t_rnxObsFile::~t_rnxObsFile() {
134 delete _stream;
135 delete _file;
136}
137
138// Retrieve single Epoch
139////////////////////////////////////////////////////////////////////////////
140const t_rnxObsFile::t_epo* t_rnxObsFile::nextEpoch() {
141
142 _currEpo.clear();
143
144 if (version() < 3.0) {
145 return nextEpochV2();
146 }
147 else {
148 return nextEpochV3();
149 }
150}
151
152// Retrieve single Epoch (RINEX Version 3)
153////////////////////////////////////////////////////////////////////////////
154const t_rnxObsFile::t_epo* t_rnxObsFile::nextEpochV3() {
155 while (_stream->status() == QTextStream::Ok && !_stream->atEnd()) {
156
157 QString line = _stream->readLine();
158
159 if (line.isEmpty()) {
160 continue;
161 }
162
163 if (line.indexOf("END OF FILE") != -1) {
164 break;
165 }
166
167 int flag;
168 readInt(line, 31, 1, flag);
169 if (flag > 1) { // TODO
170 break;
171 }
172
173 QTextStream in(line.mid(1).toAscii());
174
175 // Epoch Time
176 // ----------
177 int year, month, day, hour, min;
178 double sec;
179 in >> year >> month >> day >> hour >> min >> sec;
180 _currEpo.tt.set(year, month, day, hour, min, sec);
181
182 // Number of Satellites
183 // --------------------
184 int numSat;
185 readInt(line, 32, 3, numSat);
186
187 _currEpo.satObs.resize(numSat);
188
189 // Observations
190 // ------------
191 for (int iSat = 0; iSat < numSat; iSat++) {
192 line = _stream->readLine();
193 _currEpo.satObs[iSat].prn = line.mid(0,3);
194 char sys = _currEpo.satObs[iSat].prn[0].toAscii();
195 for (int iType = 0; iType < _header.nTypes(sys); iType++) {
196 int pos = 16*iType;
197 readDbl(line, pos, 14, _currEpo.satObs[iSat][iType]);
198 readInt(line, pos + 14, 1, _currEpo.satObs[iSat].lli);
199 readInt(line, pos + 15, 1, _currEpo.satObs[iSat].snr);
200 }
201 }
202 }
203
204 return 0;
205}
206
207// Retrieve single Epoch (RINEX Version 2)
208////////////////////////////////////////////////////////////////////////////
209const t_rnxObsFile::t_epo* t_rnxObsFile::nextEpochV2() {
210 while (_stream->status() == QTextStream::Ok && !_stream->atEnd()) {
211
212 QString line = _stream->readLine();
213
214 if (line.isEmpty()) {
215 continue;
216 }
217
218 if (line.indexOf("END OF FILE") != -1) {
219 break;
220 }
221
222 int flag;
223 readInt(line, 28, 1, flag);
224 if (flag > 1) { // TODO
225 break;
226 }
227
228 QTextStream in(line.toAscii());
229
230 // Epoch Time
231 // ----------
232 int year, month, day, hour, min;
233 double sec;
234 in >> year >> month >> day >> hour >> min >> sec;
235 if (year < 80) {
236 year += 2000;
237 }
238 else if (year < 100) {
239 year += 1900;
240 }
241 _currEpo.tt.set(year, month, day, hour, min, sec);
242
243 // Number of Satellites
244 // --------------------
245 int numSat;
246 readInt(line, 29, 3, numSat);
247
248 _currEpo.satObs.resize(numSat);
249
250 // Read Satellite Numbers
251 // ----------------------
252 int pos = 32;
253 for (int iSat = 0; iSat < numSat; iSat++) {
254 if (iSat > 0 && iSat % 12 == 0) {
255 line = _stream->readLine();
256 pos = 32;
257 }
258 QString prn = line.mid(pos, 3);
259 pos += 3;
260
261 _currEpo.satObs[iSat].prn = prn;
262 char sys = prn[0].toAscii();
263 _currEpo.satObs[iSat].ReSize(_header.nTypes(sys));
264 }
265
266 // Read Observation Records
267 // ------------------------
268 for (int iSat = 0; iSat < numSat; iSat++) {
269 line = _stream->readLine();
270 pos = 0;
271 QString prn = _currEpo.satObs[iSat].prn;
272 char sys = prn[0].toAscii();
273 for (int iType = 0; iType < _header.nTypes(sys); iType++) {
274 if (iType > 0 && iType % 5 == 0) {
275 line = _stream->readLine();
276 pos = 0;
277 }
278 readDbl(line, pos, 14, _currEpo.satObs[iSat][iType]);
279 readInt(line, pos + 14, 1, _currEpo.satObs[iSat].lli);
280 readInt(line, pos + 15, 1, _currEpo.satObs[iSat].snr);
281 pos += 16;
282 }
283 }
284
285 return &_currEpo;
286 }
287
288 return 0;
289}
Note: See TracBrowser for help on using the repository browser.