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

Last change on this file since 9770 was 9770, checked in by stuerze, 22 months ago

minor changes to handle RINEX 2,3,4

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