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

Last change on this file since 3698 was 3698, checked in by mervart, 13 years ago
File size: 7.0 KB
RevLine 
[3645]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>
[3677]42#include <iomanip>
[3645]43#include "rnxobsfile.h"
[3646]44#include "bncutils.h"
[3645]45
46using namespace std;
47
48// Constructor
49////////////////////////////////////////////////////////////////////////////
[3646]50t_rnxObsFile::t_rnxObsHeader::t_rnxObsHeader() {
[3672]51 _antNEU.ReSize(3);
52 _xyz.ReSize(3);
53 _antNEU = 0.0;
54 _xyz = 0.0;
55 _version = 0.0;
[3645]56}
57
58// Destructor
59////////////////////////////////////////////////////////////////////////////
[3646]60t_rnxObsFile::t_rnxObsHeader::~t_rnxObsHeader() {
61}
62
63// Read Header
64////////////////////////////////////////////////////////////////////////////
65t_irc t_rnxObsFile::t_rnxObsHeader::read(QTextStream* stream) {
[3649]66 while (stream->status() == QTextStream::Ok && !stream->atEnd()) {
[3646]67 QString line = stream->readLine();
[3656]68 if (line.isEmpty()) {
69 continue;
70 }
[3651]71 QString value = line.left(60).trimmed();
72 QString key = line.mid(60).trimmed();
73 if (key == "END OF HEADER") {
[3650]74 break;
75 }
[3652]76 else if (key == "RINEX VERSION / TYPE") {
77 QTextStream in(value.toAscii(), QIODevice::ReadOnly);
[3651]78 in >> _version;
79 }
[3652]80 else if (key == "MARKER NAME") {
81 _markerName = value;
82 }
83 else if (key == "ANT # / TYPE") {
84 _antennaName = value.mid(20);
85 }
[3656]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 }
[3672]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 _obsTypes << hlp;
102 }
103 }
[3646]104 }
105
106 return success;
107}
108
109// Constructor
110////////////////////////////////////////////////////////////////////////////
111t_rnxObsFile::t_rnxObsFile(QString fileName) {
112 expandEnvVar(fileName);
113 _file = new QFile(fileName);
114 _file->open(QIODevice::ReadOnly | QIODevice::Text);
115 _stream = new QTextStream();
116 _stream->setDevice(_file);
117 _header.read(_stream);
118}
119
120// Destructor
121////////////////////////////////////////////////////////////////////////////
[3645]122t_rnxObsFile::~t_rnxObsFile() {
[3646]123 delete _stream;
124 delete _file;
[3645]125}
126
127// Retrieve single Epoch
128////////////////////////////////////////////////////////////////////////////
[3675]129const t_rnxObsFile::t_epo* t_rnxObsFile::nextEpoch() {
[3676]130
131 _currEpo.clear();
132
[3673]133 if (version() < 3.0) {
[3675]134 return nextEpochV2();
[3673]135 }
136 else {
[3675]137 return nextEpochV3();
[3673]138 }
139}
140
141// Retrieve single Epoch (RINEX Version 3)
142////////////////////////////////////////////////////////////////////////////
[3675]143const t_rnxObsFile::t_epo* t_rnxObsFile::nextEpochV3() {
[3697]144 while (_stream->status() == QTextStream::Ok && !_stream->atEnd()) {
145
146 QString line = _stream->readLine();
147
148 if (line.isEmpty()) {
149 continue;
150 }
151
152 QTextStream in(line.mid(1).toAscii());
153
154 // Epoch Time
155 // ----------
156 int year, month, day, hour, min, flag;
157 double sec;
158 in >> year >> month >> day >> hour >> min >> sec >> flag;
159 _currEpo.tt.set(year, month, day, hour, min, sec);
160
161 // Number of Satellites
162 // --------------------
163 int numSat;
164 readInt(line, 32, 3, numSat);
165
166 _currEpo.satObs.resize(numSat);
167
168 // Observations
169 // ------------
170 for (int iSat = 0; iSat < numSat; iSat++) {
171 line = _stream->readLine();
[3698]172 _currEpo.satObs[iSat].prn = line.mid(0,3);
[3697]173 for (int iType = 0; iType < _header.nTypes(); iType++) {
174 int pos = 16*iType;
175 readDbl(line, pos, 14, _currEpo.satObs[iSat][iType]);
176 readInt(line, pos + 14, 1, _currEpo.satObs[iSat].lli);
177 readInt(line, pos + 15, 1, _currEpo.satObs[iSat].snr);
178 }
179 }
180 }
181
182 return 0;
[3673]183}
184
185// Retrieve single Epoch (RINEX Version 2)
186////////////////////////////////////////////////////////////////////////////
[3675]187const t_rnxObsFile::t_epo* t_rnxObsFile::nextEpochV2() {
[3656]188 while (_stream->status() == QTextStream::Ok && !_stream->atEnd()) {
[3680]189
[3656]190 QString line = _stream->readLine();
[3680]191
[3656]192 if (line.isEmpty()) {
193 continue;
194 }
[3680]195
[3673]196 QTextStream in(line.toAscii());
[3680]197
198 // Epoch Time
199 // ----------
[3673]200 int year, month, day, hour, min, flag;
201 double sec;
202 in >> year >> month >> day >> hour >> min >> sec >> flag;
203 if (year < 80) {
204 year += 2000;
205 }
206 else if (year < 100) {
207 year += 1900;
208 }
[3680]209 _currEpo.tt.set(year, month, day, hour, min, sec);
[3673]210
[3680]211 // Number of Satellites
212 // --------------------
[3673]213 int numSat;
214 readInt(line, 29, 3, numSat);
[3674]215
[3677]216 _currEpo.satObs.resize(numSat);
217
[3676]218 // Read Satellite Numbers
219 // ----------------------
[3674]220 int pos = 32;
221 for (int iSat = 0; iSat < numSat; iSat++) {
222 if (iSat > 0 && iSat % 12 == 0) {
223 line = _stream->readLine();
224 pos = 32;
225 }
226 QString prn = line.mid(pos, 3);
227 pos += 3;
[3676]228
[3677]229 _currEpo.satObs[iSat].prn = prn;
230 _currEpo.satObs[iSat].ReSize(_header.nTypes());
[3674]231 }
232
[3676]233 // Read Observation Records
234 // ------------------------
235 for (int iSat = 0; iSat < numSat; iSat++) {
236 line = _stream->readLine();
237 pos = 0;
[3677]238 QString prn = _currEpo.satObs[iSat].prn;
[3676]239 for (int iType = 0; iType < _header.nTypes(); iType++) {
240 if (iType > 0 && iType % 5 == 0) {
241 line = _stream->readLine();
242 pos = 0;
243 }
[3677]244 readDbl(line, pos, 14, _currEpo.satObs[iSat][iType]);
245 readInt(line, pos + 14, 1, _currEpo.satObs[iSat].lli);
246 readInt(line, pos + 15, 1, _currEpo.satObs[iSat].snr);
[3676]247 pos += 16;
248 }
249 }
250
[3678]251 return &_currEpo;
[3656]252 }
[3674]253
[3678]254 return 0;
[3645]255}
Note: See TracBrowser for help on using the repository browser.