| 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.00
|
|---|
| 43 |
|
|---|
| 44 | class 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 | int numSys() const;
|
|---|
| 61 | char system(int iSys) const;
|
|---|
| 62 | int nTypes(char sys) const;
|
|---|
| 63 | int numGloBiases() const;
|
|---|
| 64 | int numGloSlots() const;
|
|---|
| 65 | QString obsType(char sys, int index, double version = 0.0) const;
|
|---|
| 66 | QString usedSystems() const;
|
|---|
| 67 | QStringList obsTypes(char sys) const;
|
|---|
| 68 | QStringList phaseShifts() const;
|
|---|
| 69 | QStringList gloBiases() const;
|
|---|
| 70 | QStringList gloSlots() const;
|
|---|
| 71 | void write(QTextStream* stream, const QMap<QString, QString>* txtMap = 0) const;
|
|---|
| 72 | bncTime startTime() const {return _startTime;}
|
|---|
| 73 | void setStartTime(const bncTime& startTime) {_startTime = startTime;}
|
|---|
| 74 |
|
|---|
| 75 | private:
|
|---|
| 76 | QStringList obsTypesStrings() const;
|
|---|
| 77 | QString _usedSystems;
|
|---|
| 78 | double _version;
|
|---|
| 79 | double _interval;
|
|---|
| 80 | QString _antennaNumber;
|
|---|
| 81 | QString _antennaName;
|
|---|
| 82 | QString _markerName;
|
|---|
| 83 | QString _markerNumber;
|
|---|
| 84 |
|
|---|
| 85 | QString _markerType;
|
|---|
| 86 | QString _observer;
|
|---|
| 87 | QString _agency;
|
|---|
| 88 | QString _receiverNumber;
|
|---|
| 89 | QString _receiverType;
|
|---|
| 90 | QString _receiverVersion;
|
|---|
| 91 | QString _digitalObjectId;
|
|---|
| 92 | QStringList _licenseOfUse;
|
|---|
| 93 | QStringList _stationInformation;
|
|---|
| 94 | QStringList _comments;
|
|---|
| 95 | ColumnVector _antNEU;
|
|---|
| 96 | ColumnVector _antXYZ;
|
|---|
| 97 | ColumnVector _antBSG;
|
|---|
| 98 | ColumnVector _xyz;
|
|---|
| 99 | QMap<char, QStringList> _obsTypes;
|
|---|
| 100 | QMap<t_prn, int> _gloSlots;
|
|---|
| 101 | QMap<QString, double> _gloBiases;
|
|---|
| 102 | int _wlFactorsL1[t_prn::MAXPRN_GPS+1];
|
|---|
| 103 | int _wlFactorsL2[t_prn::MAXPRN_GPS+1];
|
|---|
| 104 | bncTime _startTime;
|
|---|
| 105 | bool _writeRinexOnlyWithSklObsTypes;
|
|---|
| 106 |
|
|---|
| 107 | QMap<QString, QPair<double, QStringList> > _phaseShifts;
|
|---|
| 108 | };
|
|---|
| 109 |
|
|---|
| 110 | class t_rnxObsFile {
|
|---|
| 111 | public:
|
|---|
| 112 |
|
|---|
| 113 | static bool earlierStartTime(const t_rnxObsFile* file1, const t_rnxObsFile* file2) {
|
|---|
| 114 | return file1->startTime() < file2->startTime();
|
|---|
| 115 | }
|
|---|
| 116 |
|
|---|
| 117 | class t_rnxObs {
|
|---|
| 118 | public:
|
|---|
| 119 | t_rnxObs() {
|
|---|
| 120 | value = 0.0; lli = 0; snr = 0;
|
|---|
| 121 | }
|
|---|
| 122 | double value;
|
|---|
| 123 | int lli;
|
|---|
| 124 | int snr;
|
|---|
| 125 | };
|
|---|
| 126 |
|
|---|
| 127 | class t_rnxSat {
|
|---|
| 128 | public:
|
|---|
| 129 | t_prn prn;
|
|---|
| 130 | QMap<QString, t_rnxObs> obs;
|
|---|
| 131 | static bool prnSort(const t_rnxSat rnxSat1, const t_rnxSat rnxSat2) {return rnxSat1.prn < rnxSat2.prn;}
|
|---|
| 132 | };
|
|---|
| 133 |
|
|---|
| 134 | class t_rnxEpo {
|
|---|
| 135 | public:
|
|---|
| 136 | t_rnxEpo() {clear();}
|
|---|
| 137 | void clear() {
|
|---|
| 138 | tt.reset();
|
|---|
| 139 | rnxSat.clear();
|
|---|
| 140 | }
|
|---|
| 141 | bncTime tt;
|
|---|
| 142 | std::vector<t_rnxSat> rnxSat;
|
|---|
| 143 | };
|
|---|
| 144 |
|
|---|
| 145 | enum e_inpOut {input, output};
|
|---|
| 146 |
|
|---|
| 147 | t_rnxObsFile(const QString& fileName, e_inpOut inpOut);
|
|---|
| 148 | ~t_rnxObsFile();
|
|---|
| 149 |
|
|---|
| 150 | double version() const {return _header._version;}
|
|---|
| 151 | double interval() const {return _header._interval;}
|
|---|
| 152 | int numSys() const {return _header.numSys();}
|
|---|
| 153 | char system(int iSys) const {return _header.system(iSys);}
|
|---|
| 154 | int nTypes(char sys) const {return _header.nTypes(sys);}
|
|---|
| 155 | int numGloBiases() const {return _header.numGloBiases();}
|
|---|
| 156 | int numGloSlots() const {return _header.numGloSlots();}
|
|---|
| 157 | const QString& fileName() const {return _fileName;}
|
|---|
| 158 | QString obsType(char sys, int index, double version = 0.0) const {
|
|---|
| 159 | return _header.obsType(sys, index, version);
|
|---|
| 160 | }
|
|---|
| 161 | QStringList phaseShifts() const {return _header.phaseShifts();}
|
|---|
| 162 | QStringList gloBiases() const {return _header.gloBiases();}
|
|---|
| 163 | QStringList gloSlots() const {return _header.gloSlots();}
|
|---|
| 164 | const QString& antennaName() const {return _header._antennaName;}
|
|---|
| 165 | const QString& antennaNumber() const {return _header._antennaNumber;}
|
|---|
| 166 | const QString& markerName() const {return _header._markerName;}
|
|---|
| 167 | const QString& markerNumber() const {return _header._markerNumber;}
|
|---|
| 168 | const QString& receiverType() const {return _header._receiverType;}
|
|---|
| 169 | const QString& receiverNumber() const {return _header._receiverNumber;}
|
|---|
| 170 | const QString& digitalObjectId() const {return _header._digitalObjectId;}
|
|---|
| 171 | const QStringList licenseOfUse() const {return _header._licenseOfUse;}
|
|---|
| 172 | const QStringList stationInformation() const {return _header._stationInformation;}
|
|---|
| 173 |
|
|---|
| 174 | void setInterval(double interval) {_header._interval = interval;}
|
|---|
| 175 | void setAntennaName(const QString& antennaName) {_header._antennaName = antennaName;}
|
|---|
| 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 |
|
|---|
| 181 | void setMarkerName(const QString& markerName) {_header._markerName = markerName;}
|
|---|
| 182 | void setReceiverType(const QString& receiverType) {_header._receiverType = receiverType;}
|
|---|
| 183 | void setReceiverNumber(const QString& receiverNumber) {_header._receiverNumber = receiverNumber;}
|
|---|
| 184 |
|
|---|
| 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 |
|
|---|
| 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;}
|
|---|
| 193 |
|
|---|
| 194 | const bncTime& startTime() const {return _header._startTime;}
|
|---|
| 195 | void setStartTime(const bncTime& startTime) {_header._startTime = startTime;}
|
|---|
| 196 |
|
|---|
| 197 | t_rnxEpo* nextEpoch();
|
|---|
| 198 |
|
|---|
| 199 | int wlFactorL1(unsigned iPrn) {
|
|---|
| 200 | return iPrn <= t_prn::MAXPRN_GPS ? _header._wlFactorsL1[iPrn] : 1;
|
|---|
| 201 | }
|
|---|
| 202 | int wlFactorL2(unsigned iPrn) {
|
|---|
| 203 | return iPrn <= t_prn::MAXPRN_GPS ? _header._wlFactorsL2[iPrn] : 1;
|
|---|
| 204 | }
|
|---|
| 205 |
|
|---|
| 206 | const t_rnxObsHeader& header() const {return _header;}
|
|---|
| 207 |
|
|---|
| 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);
|
|---|
| 212 | }
|
|---|
| 213 |
|
|---|
| 214 | void writeEpoch(const t_rnxEpo* epo);
|
|---|
| 215 |
|
|---|
| 216 | QTextStream* stream() {return _stream;}
|
|---|
| 217 |
|
|---|
| 218 | static void setObsFromRnx(const t_rnxObsFile* rnxObsFile, const t_rnxObsFile::t_rnxEpo* epo,
|
|---|
| 219 | const t_rnxObsFile::t_rnxSat& rnxSat, t_satObs& obs);
|
|---|
| 220 |
|
|---|
| 221 | static QString type2to3(char sys, const QString& typeV2);
|
|---|
| 222 | static QString type3to2(char sys, const QString& typeV3);
|
|---|
| 223 | static QStringList signalPriorities(char sys);
|
|---|
| 224 |
|
|---|
| 225 | static void writeEpoch(QTextStream* stream, const t_rnxObsHeader& header, const t_rnxEpo* epo) {
|
|---|
| 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) {
|
|---|
| 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' &&
|
|---|
| 236 | rnxSat.prn.system() != 'E' && rnxSat.prn.system() != 'S' &&
|
|---|
| 237 | rnxSat.prn.system() != 'I') {
|
|---|
| 238 | continue;
|
|---|
| 239 | }
|
|---|
| 240 | }
|
|---|
| 241 | epoLocal.rnxSat.push_back(rnxSat);
|
|---|
| 242 | }
|
|---|
| 243 | }
|
|---|
| 244 | std::stable_sort(epoLocal.rnxSat.begin(), epoLocal.rnxSat.end(), t_rnxSat::prnSort);
|
|---|
| 245 |
|
|---|
| 246 | if (header.version() >= 3.0) {
|
|---|
| 247 | writeEpochV3(stream, header, &epoLocal);
|
|---|
| 248 | }
|
|---|
| 249 | else {
|
|---|
| 250 | writeEpochV2(stream, header, &epoLocal);
|
|---|
| 251 | }
|
|---|
| 252 | }
|
|---|
| 253 |
|
|---|
| 254 | private:
|
|---|
| 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);
|
|---|
| 257 | t_rnxObsFile() {};
|
|---|
| 258 | void openRead(const QString& fileName);
|
|---|
| 259 | void openWrite(const QString& fileName);
|
|---|
| 260 | void close();
|
|---|
| 261 | t_rnxEpo* nextEpochV2();
|
|---|
| 262 | t_rnxEpo* nextEpochV3();
|
|---|
| 263 | void handleEpochFlag(int flag, const QString& line, bool& headerReRead);
|
|---|
| 264 |
|
|---|
| 265 | e_inpOut _inpOut;
|
|---|
| 266 | QFile* _file;
|
|---|
| 267 | QString _fileName;
|
|---|
| 268 | QTextStream* _stream;
|
|---|
| 269 | t_rnxObsHeader _header;
|
|---|
| 270 | t_rnxEpo _currEpo;
|
|---|
| 271 | bool _flgPowerFail;
|
|---|
| 272 | };
|
|---|
| 273 |
|
|---|
| 274 | #endif
|
|---|