source: ntrip/trunk/BNC/src/rinex/rnxobsfile.h@ 10525

Last change on this file since 10525 was 10127, checked in by stuerze, 16 months ago
File size: 10.0 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#ifndef RNXOBSFILE_H
26#define RNXOBSFILE_H
27
28#include <QtCore>
29
30#include <fstream>
31#include <vector>
32#include <map>
33
34#include "newmat.h"
35#include "bncconst.h"
36#include "bnctime.h"
37#include "t_prn.h"
38#include "satObs.h"
39
40#define defaultRnxObsVersion2 2.11
41#define defaultRnxObsVersion3 3.05
42#define defaultRnxObsVersion4 4.01
43
44class t_rnxObsHeader {
45
46 friend class t_rnxObsFile;
47
48 public:
49
50 t_rnxObsHeader();
51 ~t_rnxObsHeader();
52
53 double version() const {return _version;}
54 double versionFromInt(int version);
55 t_irc read(QTextStream* stream, int maxLines = 0);
56 void setDefault(const QString& markerName, int version);
57 void set(const t_rnxObsHeader& header, int version,
58 const QStringList* useObsTypes = 0, const QStringList* phaseShifts = 0,
59 const QStringList* gloBiases = 0, const QStringList* gloSlots = 0,
60 const QStringList* runByDate = 0);
61 int numSys() const;
62 char system(int iSys) const;
63 int nTypes(char sys) const;
64 int numGloBiases() const;
65 int numGloSlots() const;
66 QString obsType(char sys, int index, double version = 0.0) const;
67 QString usedSystems() const;
68 QStringList obsTypes(char sys) const;
69 QStringList phaseShifts() const;
70 QStringList gloBiases() const;
71 QStringList gloSlots() const;
72 QStringList runByDate() const {return _runByDate;}
73 void write(QTextStream* stream, const QMap<QString, QString>* txtMap = 0) const;
74 bncTime startTime() const {return _startTime;}
75 void setStartTime(const bncTime& startTime) {_startTime = startTime;}
76
77 private:
78 QStringList obsTypesStrings() const;
79 QString _usedSystems;
80 double _version;
81 double _interval;
82 QString _antennaNumber;
83 QString _antennaName;
84 QString _markerName;
85 QString _markerNumber;
86
87 QString _markerType;
88 QString _observer;
89 QString _agency;
90 QString _receiverNumber;
91 QString _receiverType;
92 QString _receiverVersion;
93 QString _digitalObjectId;
94 QStringList _licenseOfUse;
95 QStringList _stationInformation;
96 QStringList _comments;
97 QStringList _runByDate;
98 ColumnVector _antNEU;
99 ColumnVector _antXYZ;
100 ColumnVector _antBSG;
101 ColumnVector _xyz;
102 QMap<char, QStringList> _obsTypes;
103 QMap<t_prn, int> _gloSlots;
104 QMap<QString, double> _gloBiases;
105 int _wlFactorsL1[t_prn::MAXPRN_GPS+1];
106 int _wlFactorsL2[t_prn::MAXPRN_GPS+1];
107 bncTime _startTime;
108 bool _writeRinexOnlyWithSklObsTypes;
109
110 QMap<QString, QPair<double, QStringList> > _phaseShifts;
111};
112
113class t_rnxObsFile {
114 public:
115
116 static bool earlierStartTime(const t_rnxObsFile* file1, const t_rnxObsFile* file2) {
117 return file1->startTime() < file2->startTime();
118 }
119
120 class t_rnxObs {
121 public:
122 t_rnxObs() {
123 value = 0.0; lli = 0; snr = 0;
124 }
125 double value;
126 int lli;
127 int snr;
128 };
129
130 class t_rnxSat {
131 public:
132 t_prn prn;
133 QMap<QString, t_rnxObs> obs;
134 static bool prnSort(const t_rnxSat rnxSat1, const t_rnxSat rnxSat2) {return rnxSat1.prn < rnxSat2.prn;}
135 };
136
137 class t_rnxEpo {
138 public:
139 t_rnxEpo() {clear();}
140 void clear() {
141 tt.reset();
142 rnxSat.clear();
143 }
144 bncTime tt;
145 std::vector<t_rnxSat> rnxSat;
146 };
147
148 enum e_inpOut {input, output};
149
150 t_rnxObsFile(const QString& fileName, e_inpOut inpOut);
151 ~t_rnxObsFile();
152
153 double version() const {return _header._version;}
154 double interval() const {return _header._interval;}
155 int numSys() const {return _header.numSys();}
156 char system(int iSys) const {return _header.system(iSys);}
157 int nTypes(char sys) const {return _header.nTypes(sys);}
158 int numGloBiases() const {return _header.numGloBiases();}
159 int numGloSlots() const {return _header.numGloSlots();}
160 const QString& fileName() const {return _fileName;}
161 QString obsType(char sys, int index, double version = 0.0) const {
162 return _header.obsType(sys, index, version);
163 }
164 QStringList phaseShifts() const {return _header.phaseShifts();}
165 QStringList gloBiases() const {return _header.gloBiases();}
166 QStringList gloSlots() const {return _header.gloSlots();}
167 QStringList runByDate() const {return _header.runByDate();}
168 const QString& antennaName() const {return _header._antennaName;}
169 const QString& antennaNumber() const {return _header._antennaNumber;}
170 const QString& markerName() const {return _header._markerName;}
171 const QString& markerNumber() const {return _header._markerNumber;}
172 const QString& receiverType() const {return _header._receiverType;}
173 const QString& receiverNumber() const {return _header._receiverNumber;}
174 const QString& digitalObjectId() const {return _header._digitalObjectId;}
175 const QStringList licenseOfUse() const {return _header._licenseOfUse;}
176 const QStringList stationInformation() const {return _header._stationInformation;}
177
178 void setInterval(double interval) {_header._interval = interval;}
179 void setAntennaName(const QString& antennaName) {_header._antennaName = antennaName;}
180 void setAntennaNumber(const QString& antennaNumber) {_header._antennaNumber = antennaNumber;}
181 void setAntennaN(double antN) {_header._antNEU(1) = antN;}
182 void setAntennaE(double antE) {_header._antNEU(2) = antE;}
183 void setAntennaU(double antU) {_header._antNEU(3) = antU;}
184
185 void setMarkerName(const QString& markerName) {_header._markerName = markerName;}
186 void setReceiverType(const QString& receiverType) {_header._receiverType = receiverType;}
187 void setReceiverNumber(const QString& receiverNumber) {_header._receiverNumber = receiverNumber;}
188
189 void setDigitalObjectId(const QString& digitalObjectId) {_header._digitalObjectId = digitalObjectId;}
190 void setLicenseOfUse(const QString& licenseOfUse) {_header._licenseOfUse.append(licenseOfUse);}
191 void setStationInformation(const QString& stationInformation) {_header._stationInformation.append(stationInformation);}
192
193 const ColumnVector& xyz() const {return _header._xyz;}
194 const ColumnVector& antNEU() const {return _header._antNEU;}
195 const ColumnVector& antXYZ() const {return _header._antXYZ;}
196 const ColumnVector& antBSG() const {return _header._antBSG;}
197
198 const bncTime& startTime() const {return _header._startTime;}
199 void setStartTime(const bncTime& startTime) {_header._startTime = startTime;}
200
201 t_rnxEpo* nextEpoch();
202
203 int wlFactorL1(unsigned iPrn) {
204 return iPrn <= t_prn::MAXPRN_GPS ? _header._wlFactorsL1[iPrn] : 1;
205 }
206 int wlFactorL2(unsigned iPrn) {
207 return iPrn <= t_prn::MAXPRN_GPS ? _header._wlFactorsL2[iPrn] : 1;
208 }
209
210 const t_rnxObsHeader& header() const {return _header;}
211
212 void setHeader(const t_rnxObsHeader& header, int version,
213 const QStringList* useObsTypes = 0, const QStringList* phaseShifts = 0,
214 const QStringList* gloBiases = 0, const QStringList* gloSlots = 0, const QStringList* runByDate = 0) {
215 _header.set(header, version, useObsTypes, phaseShifts, gloBiases, gloSlots, runByDate);
216 }
217
218 void writeEpoch(const t_rnxEpo* epo);
219
220 QTextStream* stream() {return _stream;}
221
222 static void setObsFromRnx(const t_rnxObsFile* rnxObsFile, const t_rnxObsFile::t_rnxEpo* epo,
223 const t_rnxObsFile::t_rnxSat& rnxSat, t_satObs& obs);
224
225 static QString type2to3(char sys, const QString& typeV2);
226 static QString type3to2(char sys, const QString& typeV3);
227 static QStringList signalPriorities(char sys);
228
229 static void writeEpoch(QTextStream* stream, const t_rnxObsHeader& header, const t_rnxEpo* epo) {
230 if (epo == 0) {
231 return;
232 }
233 t_rnxEpo epoLocal;
234 epoLocal.tt = epo->tt;
235 for (unsigned ii = 0; ii < epo->rnxSat.size(); ii++) {
236 const t_rnxSat& rnxSat = epo->rnxSat[ii];
237 if (header._obsTypes[rnxSat.prn.system()].size() > 0) {
238 if (header.version() < 3.0) { // exclude new GNSS such as BDS, QZSS, IRNSS, etc.
239 if (rnxSat.prn.system() != 'G' && rnxSat.prn.system() != 'R' &&
240 rnxSat.prn.system() != 'E' && rnxSat.prn.system() != 'S' ) {
241 continue;
242 }
243 }
244 epoLocal.rnxSat.push_back(rnxSat);
245 }
246 }
247 std::stable_sort(epoLocal.rnxSat.begin(), epoLocal.rnxSat.end(), t_rnxSat::prnSort);
248
249 if (header.version() >= 3.0) {
250 writeEpochV3(stream, header, &epoLocal);
251 }
252 else {
253 writeEpochV2(stream, header, &epoLocal);
254 }
255 }
256
257 private:
258 static void writeEpochV2(QTextStream* stream, const t_rnxObsHeader& header, const t_rnxEpo* epo);
259 static void writeEpochV3(QTextStream* stream, const t_rnxObsHeader& header, const t_rnxEpo* epo);
260 t_rnxObsFile() {};
261 void openRead(const QString& fileName);
262 void openWrite(const QString& fileName);
263 void close();
264 t_rnxEpo* nextEpochV2();
265 t_rnxEpo* nextEpochV3();
266 void handleEpochFlag(int flag, const QString& line, bool& headerReRead);
267
268 e_inpOut _inpOut;
269 QFile* _file;
270 QString _fileName;
271 QTextStream* _stream;
272 t_rnxObsHeader _header;
273 t_rnxEpo _currEpo;
274 bool _flgPowerFail;
275};
276
277#endif
Note: See TracBrowser for help on using the repository browser.