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