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

Last change on this file since 3680 was 3680, checked in by mervart, 14 years ago
File size: 6.4 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 _obsTypes << hlp;
102 }
103 }
104 }
105
106 cout << "RINEX Version = " << _version << endl;
107 cout << "Antenna Name >" << _antennaName.toAscii().data() << "<\n";
108 cout << "Marker Name >" << _markerName.toAscii().data() << "<\n";
109
110 return success;
111}
112
113// Constructor
114////////////////////////////////////////////////////////////////////////////
115t_rnxObsFile::t_rnxObsFile(QString fileName) {
116 expandEnvVar(fileName);
117 _file = new QFile(fileName);
118 _file->open(QIODevice::ReadOnly | QIODevice::Text);
119 _stream = new QTextStream();
120 _stream->setDevice(_file);
121 _header.read(_stream);
122}
123
124// Destructor
125////////////////////////////////////////////////////////////////////////////
126t_rnxObsFile::~t_rnxObsFile() {
127 delete _stream;
128 delete _file;
129}
130
131// Retrieve single Epoch
132////////////////////////////////////////////////////////////////////////////
133const t_rnxObsFile::t_epo* t_rnxObsFile::nextEpoch() {
134
135 _currEpo.clear();
136
137 if (version() < 3.0) {
138 return nextEpochV2();
139 }
140 else {
141 return nextEpochV3();
142 }
143}
144
145// Retrieve single Epoch (RINEX Version 3)
146////////////////////////////////////////////////////////////////////////////
147const t_rnxObsFile::t_epo* t_rnxObsFile::nextEpochV3() {
148 return 0; // TODO
149}
150
151// Retrieve single Epoch (RINEX Version 2)
152////////////////////////////////////////////////////////////////////////////
153const t_rnxObsFile::t_epo* t_rnxObsFile::nextEpochV2() {
154 while (_stream->status() == QTextStream::Ok && !_stream->atEnd()) {
155
156 QString line = _stream->readLine();
157
158 if (line.isEmpty()) {
159 continue;
160 }
161
162 QTextStream in(line.toAscii());
163
164 // Epoch Time
165 // ----------
166 int year, month, day, hour, min, flag;
167 double sec;
168 in >> year >> month >> day >> hour >> min >> sec >> flag;
169 if (year < 80) {
170 year += 2000;
171 }
172 else if (year < 100) {
173 year += 1900;
174 }
175 _currEpo.tt.set(year, month, day, hour, min, sec);
176
177 // Number of Satellites
178 // --------------------
179 int numSat;
180 readInt(line, 29, 3, numSat);
181
182 _currEpo.satObs.resize(numSat);
183
184 // Read Satellite Numbers
185 // ----------------------
186 int pos = 32;
187 for (int iSat = 0; iSat < numSat; iSat++) {
188 if (iSat > 0 && iSat % 12 == 0) {
189 line = _stream->readLine();
190 pos = 32;
191 }
192 QString prn = line.mid(pos, 3);
193 pos += 3;
194
195 _currEpo.satObs[iSat].prn = prn;
196 _currEpo.satObs[iSat].ReSize(_header.nTypes());
197 }
198
199 // Read Observation Records
200 // ------------------------
201 for (int iSat = 0; iSat < numSat; iSat++) {
202 line = _stream->readLine();
203 pos = 0;
204 QString prn = _currEpo.satObs[iSat].prn;
205 for (int iType = 0; iType < _header.nTypes(); iType++) {
206 if (iType > 0 && iType % 5 == 0) {
207 line = _stream->readLine();
208 pos = 0;
209 }
210 readDbl(line, pos, 14, _currEpo.satObs[iSat][iType]);
211 readInt(line, pos + 14, 1, _currEpo.satObs[iSat].lli);
212 readInt(line, pos + 15, 1, _currEpo.satObs[iSat].snr);
213 pos += 16;
214 }
215
216 cout.setf(ios::fixed);
217 cout << "prn: " << prn.toAscii().data() << " "
218 << setprecision(3) << _currEpo.satObs[iSat][0] << " "
219 << setprecision(3) << _currEpo.satObs[iSat][5] << " "
220 << setprecision(3) << _currEpo.satObs[iSat][6] << endl;
221 }
222
223 return &_currEpo;
224 }
225
226 return 0;
227}
Note: See TracBrowser for help on using the repository browser.