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

Last change on this file since 10577 was 10532, checked in by stuerze, 8 weeks ago

bug fixed: obs types from skl file are used now to write them into RINEX version 3 or 4 observation files as configured

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