source: ntrip/trunk/BNC/src/bncrinex.cpp@ 4408

Last change on this file since 4408 was 4408, checked in by mervart, 13 years ago
File size: 27.7 KB
RevLine 
[280]1// Part of BNC, a utility for retrieving decoding and
[464]2// converting GNSS data streams from NTRIP broadcasters.
[280]3//
[464]4// Copyright (C) 2007
[280]5// German Federal Agency for Cartography and Geodesy (BKG)
6// http://www.bkg.bund.de
[464]7// Czech Technical University Prague, Department of Geodesy
[280]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.
[73]24
25/* -------------------------------------------------------------------------
[93]26 * BKG NTRIP Client
[73]27 * -------------------------------------------------------------------------
28 *
29 * Class: bncRinex
30 *
31 * Purpose: writes RINEX files
32 *
33 * Author: L. Mervart
34 *
35 * Created: 27-Aug-2006
36 *
37 * Changes:
38 *
39 * -----------------------------------------------------------------------*/
40
[292]41#include <stdlib.h>
[300]42#include <iostream>
[75]43#include <iomanip>
[221]44#include <math.h>
[2695]45#include <sstream>
[75]46
[300]47#include <QtCore>
48#include <QUrl>
49#include <QString>
50
[73]51#include "bncrinex.h"
[157]52#include "bncapp.h"
[82]53#include "bncutils.h"
[126]54#include "bncconst.h"
[298]55#include "bnctabledlg.h"
[301]56#include "bncgetthread.h"
[3337]57#include "bncnetqueryv1.h"
[1858]58#include "bncnetqueryv2.h"
[1535]59#include "bncsettings.h"
[2012]60#include "bncversion.h"
[2492]61#include "rtcm3torinex.h"
[75]62
63using namespace std;
64
[73]65// Constructor
66////////////////////////////////////////////////////////////////////////////
[408]67bncRinex::bncRinex(const QByteArray& statID, const QUrl& mountPoint,
[3525]68 const QByteArray& latitude, const QByteArray& longitude,
69 const QByteArray& nmea, const QByteArray& ntripVersion) {
[1387]70
[408]71 _statID = statID;
[336]72 _mountPoint = mountPoint;
[366]73 _latitude = latitude;
74 _longitude = longitude;
75 _nmea = nmea;
[1639]76 _ntripVersion = ntripVersion;
[77]77 _headerWritten = false;
[369]78 _reconnectFlag = false;
[656]79 _reloadTable = false;
80 _reloadDone = false;
[132]81
[1535]82 bncSettings settings;
[132]83 _rnxScriptName = settings.value("rnxScript").toString();
84 expandEnvVar(_rnxScriptName);
[153]85
[2012]86 _pgmName = QString(BNCPGMNAME).leftJustified(20, ' ', true);
[319]87#ifdef WIN32
88 _userName = QString("${USERNAME}");
89#else
[158]90 _userName = QString("${USER}");
[319]91#endif
[157]92 expandEnvVar(_userName);
[158]93 _userName = _userName.leftJustified(20, ' ', true);
[539]94
95 if ( Qt::CheckState(settings.value("rnxV3").toInt()) == Qt::Checked) {
96 _rinexVers = 3;
97 }
98 else {
99 _rinexVers = 2;
100 }
[1044]101
102 _approxPos[0] = _approxPos[1] = _approxPos[2] = 0.0;
[3528]103
104 _samplingRate = settings.value("rnxSampl").toInt();
[4390]105
106 // Initialize RINEX v3 Types
107 // -------------------------
[4402]108 _rnxTypes['G'] << "C1C" << "C1P" << "L1C" << "L1P"
109 << "D1C" << "D1P" << "S1C" << "S1P"
110 << "C2X" << "C2P" << "L2X" << "L2P"
111 << "D2X" << "D2P" << "S2X" << "S2P"
112 << "C5" << "D5" << "L5" << "S5";
[4390]113
[4402]114 _rnxTypes['R'] << "C1C" << "C1P" << "L1C" << "L1P"
115 << "D1C" << "D1P" << "S1C" << "S1P"
116 << "C2C" << "C2P" << "L2C" << "L2P"
117 << "D2C" << "D2P" << "S2C" << "S2P";
[4390]118
[4402]119 _rnxTypes['E'] << "C1" << "L1" << "D1" << "S1"
120 << "C5" << "L5" << "D5" << "S5"
121 << "C6" << "L6" << "D6" << "S6"
122 << "C7" << "L7" << "D7" << "S7"
123 << "C8" << "L8" << "D8" << "S8";
[4390]124
[4402]125 _rnxTypes['J'] << "C1C" << "C1Z" << "L1C" << "L1Z"
126 << "D1C" << "D1Z" << "S1C" << "S1Z"
127 << "C2" << "L2" << "D2" << "S2"
128 << "C5" << "L5" << "D5" << "S5"
129 << "C6" << "D6" << "L6" << "S6";
130
131 _rnxTypes['S'] << "C1C" << "C1W" << "L1C" << "L1W"
132 << "D1C" << "D1W" << "S1C" << "S1W"
[4390]133 << "C5" << "L5" << "D5" << "S5";
134
[4402]135 _rnxTypes['C'] << "C2I" << "L2I" << "D2I" << "S2I"
136 << "C6I" << "L6I" << "D6I" << "S6I"
137 << "C7I" << "L7I" << "D7I" << "S7I";
[73]138}
139
140// Destructor
141////////////////////////////////////////////////////////////////////////////
142bncRinex::~bncRinex() {
[1535]143 bncSettings settings;
[698]144 if ((_rinexVers == 3) && ( Qt::CheckState(settings.value("rnxAppend").toInt()) != Qt::Checked) ) {
[843]145 _out << "> 4 1" << endl;
[698]146 _out << "END OF FILE" << endl;
147 }
[77]148 _out.close();
[73]149}
150
[420]151// Download Skeleton Header File
152////////////////////////////////////////////////////////////////////////////
153t_irc bncRinex::downloadSkeleton() {
154
155 t_irc irc = failure;
156
157 QStringList table;
[3335]158 bncTableDlg::getFullTable(_ntripVersion, _mountPoint.host(),
159 _mountPoint.port(), table, _reloadTable);
[420]160 QString net;
161 QStringListIterator it(table);
162 while (it.hasNext()) {
163 QString line = it.next();
164 if (line.indexOf("STR") == 0) {
165 QStringList tags = line.split(";");
[1495]166 if (tags.size() > 7) {
167 if (tags.at(1) == _mountPoint.path().mid(1).toAscii()) {
168 net = tags.at(7);
169 break;
170 }
[420]171 }
172 }
173 }
174 QString sklDir;
[1495]175 if (!net.isEmpty()) {
176 it.toFront();
177 while (it.hasNext()) {
178 QString line = it.next();
179 if (line.indexOf("NET") == 0) {
180 QStringList tags = line.split(";");
181 if (tags.size() > 6) {
182 if (tags.at(1) == net) {
183 sklDir = tags.at(6).trimmed();
184 break;
185 }
186 }
187 }
[420]188 }
189 }
190 if (!sklDir.isEmpty() && sklDir != "none") {
191 QUrl url(sklDir + "/" + _mountPoint.path().mid(1,4).toLower() + ".skl");
192 if (url.port() == -1) {
193 url.setPort(80);
194 }
195
[3337]196 bncNetQuery* query;
197 if (_ntripVersion == "2s") {
198 query = new bncNetQueryV2(true);
199 }
200 else if (_ntripVersion == "2") {
201 query = new bncNetQueryV2(false);
202 }
203 else {
204 query = new bncNetQueryV1;
205 }
206
[1386]207 QByteArray outData;
[3337]208 query->waitForRequestResult(url, outData);
209 if (query->status() == bncNetQuery::finished) {
[1386]210 _headerLines.clear();
211 bool firstLineRead = false;
212 QTextStream in(outData);
213 QString line = in.readLine();
214 while ( !line.isNull() ) {
[1348]215 if (line.indexOf("MARKER NAME") != -1) {
216 irc = success;
217 }
218 if (line.indexOf("RINEX VERSION") != -1) {
219 if (_rinexVers == 3) {
220 _headerLines.append(" 3.00 OBSERVATION DATA"
221 " M (MIXED)"
222 " RINEX VERSION / TYPE");
[556]223 }
[1348]224 else {
225 _headerLines.append(" 2.11 OBSERVATION DATA"
226 " M (MIXED)"
227 " RINEX VERSION / TYPE");
[421]228 }
[1348]229 _headerLines.append("PGM / RUN BY / DATE");
230 firstLineRead = true;
231 }
232 else if (firstLineRead) {
233 if (line.indexOf("END OF HEADER") != -1) {
234 _headerLines.append("# / TYPES OF OBSERV");
235 if (_rinexVers == 2) {
236 _headerLines.append(
237 QString(" 1 1").leftJustified(60, ' ', true) +
238 "WAVELENGTH FACT L1/2");
[421]239 }
[1348]240 _headerLines.append("TIME OF FIRST OBS");
241 _headerLines.append( line );
242 break;
[421]243 }
[420]244 else {
[1348]245 _headerLines.append( line );
[420]246 }
247 }
[1386]248 line = in.readLine();
[420]249 }
[1386]250 }
251 else {
[3337]252 delete query;
[1386]253 return failure;
[420]254 }
[3337]255 delete query;
256 }
[1386]257
[420]258 return irc;
259}
260
[82]261// Read Skeleton Header File
262////////////////////////////////////////////////////////////////////////////
263void bncRinex::readSkeleton() {
264
[420]265 // Read the local file
266 // -------------------
[276]267 QFile skl(_sklName);
[82]268 if ( skl.exists() && skl.open(QIODevice::ReadOnly) ) {
[422]269 _headerLines.clear();
[82]270 QTextStream in(&skl);
271 while ( !in.atEnd() ) {
272 _headerLines.append( in.readLine() );
273 if (_headerLines.last().indexOf("END OF HEADER") != -1) {
274 break;
275 }
276 }
277 }
[298]278
[420]279 // Read downloaded file
280 // --------------------
[2376]281 else if ( _ntripVersion != "N" && _ntripVersion != "UN" &&
282 _ntripVersion != "S" ) {
[1154]283 QDate currDate = currentDateAndTimeGPS().date();
[420]284 if ( !_skeletonDate.isValid() || _skeletonDate != currDate ) {
285 if ( downloadSkeleton() == success) {
286 _skeletonDate = currDate;
[656]287 _reloadDone = false;
[298]288 }
[656]289 else {
290 if(!_reloadDone) {
291 _reloadTable = true;
292 if ( downloadSkeleton() == success) {
293 _skeletonDate = currDate;
294 }
295 _reloadTable = false;
296 _reloadDone = true;
297 }
298 }
[298]299 }
300 }
[82]301}
302
[647]303// Next File Epoch (static)
[82]304////////////////////////////////////////////////////////////////////////////
[647]305QString bncRinex::nextEpochStr(const QDateTime& datTim,
306 const QString& intStr, QDateTime* nextEpoch) {
[82]307
[647]308 QString epoStr;
[82]309
[129]310 QTime nextTime;
311 QDate nextDate;
312
[204]313 int indHlp = intStr.indexOf("min");
314
315 if ( indHlp != -1) {
316 int step = intStr.left(indHlp-1).toInt();
[127]317 char ch = 'A' + datTim.time().hour();
[647]318 epoStr = ch;
[204]319 if (datTim.time().minute() >= 60-step) {
[647]320 epoStr += QString("%1").arg(60-step, 2, 10, QChar('0'));
[199]321 if (datTim.time().hour() < 23) {
322 nextTime.setHMS(datTim.time().hour() + 1 , 0, 0);
323 nextDate = datTim.date();
324 }
325 else {
326 nextTime.setHMS(0, 0, 0);
327 nextDate = datTim.date().addDays(1);
328 }
329 }
330 else {
[204]331 for (int limit = step; limit <= 60-step; limit += step) {
332 if (datTim.time().minute() < limit) {
[647]333 epoStr += QString("%1").arg(limit-step, 2, 10, QChar('0'));
[204]334 nextTime.setHMS(datTim.time().hour(), limit, 0);
335 nextDate = datTim.date();
336 break;
337 }
[199]338 }
339 }
340 }
[127]341 else if (intStr == "1 hour") {
342 char ch = 'A' + datTim.time().hour();
[647]343 epoStr = ch;
[129]344 if (datTim.time().hour() < 23) {
345 nextTime.setHMS(datTim.time().hour() + 1 , 0, 0);
346 nextDate = datTim.date();
347 }
348 else {
349 nextTime.setHMS(0, 0, 0);
350 nextDate = datTim.date().addDays(1);
351 }
[127]352 }
353 else {
[647]354 epoStr = "0";
[129]355 nextTime.setHMS(0, 0, 0);
356 nextDate = datTim.date().addDays(1);
[127]357 }
[82]358
[647]359 if (nextEpoch) {
360 *nextEpoch = QDateTime(nextDate, nextTime);
361 }
362
363 return epoStr;
364}
365
366// File Name according to RINEX Standards
367////////////////////////////////////////////////////////////////////////////
368void bncRinex::resolveFileName(const QDateTime& datTim) {
369
[1535]370 bncSettings settings;
[647]371 QString path = settings.value("rnxPath").toString();
372 expandEnvVar(path);
373
374 if ( path.length() > 0 && path[path.length()-1] != QDir::separator() ) {
375 path += QDir::separator();
376 }
377
378 QString hlpStr = nextEpochStr(datTim, settings.value("rnxIntr").toString(),
379 &_nextCloseEpoch);
380
[183]381 QString ID4 = _statID.left(4);
382
383 // Check name conflict
384 // -------------------
385 QString distStr;
386 int num = 0;
387 QListIterator<QString> it(settings.value("mountPoints").toStringList());
388 while (it.hasNext()) {
389 QString mp = it.next();
390 if (mp.indexOf(ID4) != -1) {
391 ++num;
392 }
393 }
394 if (num > 1) {
395 distStr = "_" + _statID.mid(4);
396 }
397
[276]398 QString sklExt = settings.value("rnxSkel").toString();
399 if (!sklExt.isEmpty()) {
400 _sklName = path + ID4 + distStr + "." + sklExt;
401 }
402
[183]403 path += ID4 +
[127]404 QString("%1").arg(datTim.date().dayOfYear(), 3, 10, QChar('0')) +
[276]405 hlpStr + distStr + datTim.toString(".yyO");
[82]406
407 _fName = path.toAscii();
408}
409
[77]410// Write RINEX Header
411////////////////////////////////////////////////////////////////////////////
[3525]412void bncRinex::writeHeader(const QByteArray& format, const QDateTime& datTim,
[267]413 const QDateTime& datTimNom) {
[77]414
[1535]415 bncSettings settings;
[356]416
[77]417 // Open the Output File
418 // --------------------
[267]419 resolveFileName(datTimNom);
[260]420
421 // Append to existing file and return
422 // ----------------------------------
423 if ( QFile::exists(_fName) ) {
[369]424 if (_reconnectFlag ||
425 Qt::CheckState(settings.value("rnxAppend").toInt()) == Qt::Checked) {
[260]426 _out.open(_fName.data(), ios::app);
427 _out.setf(ios::showpoint | ios::fixed);
428 _headerWritten = true;
[369]429 _reconnectFlag = false;
[260]430 return;
431 }
432 }
433
[82]434 _out.open(_fName.data());
[85]435 _out.setf(ios::showpoint | ios::fixed);
[77]436
[82]437 // Copy Skeleton Header
438 // --------------------
[276]439 readSkeleton();
[82]440 if (_headerLines.size() > 0) {
[3723]441 bool typesOfObservationsWritten = false;
[82]442 QStringListIterator it(_headerLines);
443 while (it.hasNext()) {
444 QString line = it.next();
[157]445 if (line.indexOf("PGM / RUN BY / DATE") != -1) {
[552]446 if (_rinexVers == 3) {
[1154]447 QString hlp = currentDateAndTimeGPS().toString("yyyyMMdd hhmmss UTC").leftJustified(20, ' ', true);
[552]448 _out << _pgmName.toAscii().data() << _userName.toAscii().data()
449 << hlp.toAscii().data() << "PGM / RUN BY / DATE" << endl;
450 }
451 else {
[1154]452 QString hlp = currentDateAndTimeGPS().date().toString("dd-MMM-yyyy").leftJustified(20, ' ', true);
[552]453 _out << _pgmName.toAscii().data() << _userName.toAscii().data()
454 << hlp.toAscii().data() << "PGM / RUN BY / DATE" << endl;
455 }
[157]456 }
[3723]457 else if ( !typesOfObservationsWritten &&
458 (line.indexOf("# / TYPES OF OBSERV") != -1 ||
459 line.indexOf("SYS / # / OBS TYPES") != -1) ) {
460 typesOfObservationsWritten = true;
[4406]461 writeObsTypes();
[82]462 }
463 else if (line.indexOf("TIME OF FIRST OBS") != -1) {
[125]464 _out << datTim.toString(" yyyy MM dd"
465 " hh mm ss.zzz0000").toAscii().data();
[553]466 _out << " GPS TIME OF FIRST OBS" << endl;
[3525]467 QString hlp = (format.left(6) + QString(" %1").arg(_mountPoint.host() +
[337]468 _mountPoint.path())).leftJustified(60, ' ', true);
[156]469 _out << hlp.toAscii().data() << "COMMENT" << endl;
[82]470 }
[689]471 else if (line.indexOf("MARKER NAME") != -1) {
472 if (_rinexVers == 3) {
473 _out << line.toAscii().data() << endl;
474 _out << setw(71) << "GEODETIC MARKER TYPE" << endl;
475 }
476 else {
477 _out << line.toAscii().data() << endl;
478 }
479 }
[82]480 else {
481 _out << line.toAscii().data() << endl;
482 }
483 }
484 }
[78]485
[82]486 // Write Dummy Header
487 // ------------------
488 else {
489 double antennaNEU[3]; antennaNEU[0] = antennaNEU[1] = antennaNEU[2] = 0.0;
490
[545]491 if (_rinexVers == 3) {
492 _out << " 3.00 OBSERVATION DATA M (MIXED) RINEX VERSION / TYPE" << endl;
[1154]493 QString hlp = currentDateAndTimeGPS().toString("yyyyMMdd hhmmss UTC").leftJustified(20, ' ', true);
[552]494 _out << _pgmName.toAscii().data() << _userName.toAscii().data()
495 << hlp.toAscii().data() << "PGM / RUN BY / DATE" << endl;
[545]496 }
497 else {
498 _out << " 2.11 OBSERVATION DATA M (MIXED) RINEX VERSION / TYPE" << endl;
[1154]499 QString hlp = currentDateAndTimeGPS().date().toString("dd-MMM-yyyy").leftJustified(20, ' ', true);
[552]500 _out << _pgmName.toAscii().data() << _userName.toAscii().data()
501 << hlp.toAscii().data() << "PGM / RUN BY / DATE" << endl;
[545]502 }
[86]503 _out.setf(ios::left);
[82]504 _out << setw(60) << _statID.data() << "MARKER NAME" << endl;
[689]505 if (_rinexVers == 3) {
506 _out << setw(60) << "unknown" << "MARKER TYPE " << endl;
507 }
[354]508 _out << setw(60) << "unknown unknown" << "OBSERVER / AGENCY" << endl;
[82]509 _out << setw(20) << "unknown"
510 << setw(20) << "unknown"
511 << setw(20) << "unknown" << "REC # / TYPE / VERS" << endl;
512 _out << setw(20) << "unknown"
513 << setw(20) << "unknown"
514 << setw(20) << " " << "ANT # / TYPE" << endl;
[86]515 _out.unsetf(ios::left);
[1044]516 _out << setw(14) << setprecision(4) << _approxPos[0]
517 << setw(14) << setprecision(4) << _approxPos[1]
518 << setw(14) << setprecision(4) << _approxPos[2]
[82]519 << " " << "APPROX POSITION XYZ" << endl;
520 _out << setw(14) << setprecision(4) << antennaNEU[0]
521 << setw(14) << setprecision(4) << antennaNEU[1]
522 << setw(14) << setprecision(4) << antennaNEU[2]
523 << " " << "ANTENNA: DELTA H/E/N" << endl;
[4406]524
525 writeObsTypes();
526
[544]527 _out << datTim.toString(" yyyy MM dd"
[125]528 " hh mm ss.zzz0000").toAscii().data();
[553]529 _out << " GPS TIME OF FIRST OBS" << endl;
[3525]530 QString hlp = (format.left(6) + QString(" %1").arg(_mountPoint.host() +
[337]531 _mountPoint.path())).leftJustified(60, ' ', true);
[156]532 _out << hlp.toAscii().data() << "COMMENT" << endl;
[366]533
[410]534 if (_nmea == "yes") {
535 hlp = ("NMEA LAT=" + _latitude + " " + "LONG=" + _longitude).leftJustified(60, ' ',true);
[366]536 _out << hlp.toAscii().data() << "COMMENT" << endl; }
537
[82]538 _out << " END OF HEADER" << endl;
539 }
[78]540
[77]541 _headerWritten = true;
542}
543
[4406]544//
545////////////////////////////////////////////////////////////////////////////
546void bncRinex::writeObsTypes() {
547 if (_rinexVers == 3) {
548 QMapIterator<char, QVector<QString> > it(_rnxTypes);
549 while (it.hasNext()) {
550 it.next();
551 char sys = it.key();
552 const QVector<QString>& types = it.value();
553 QString hlp;
554 QTextStream(&hlp) << QString("%1 %2").arg(sys).arg(types.size(), 3);
555 for (int ii = 0; ii < types.size(); ii++) {
556 QTextStream(&hlp) << QString(" %1").arg(types[ii], -3);
557 if ((ii+1) % 13 == 0 || ii == types.size()-1) {
558 _out << QString(hlp.leftJustified(60) + "SYS / # / OBS TYPES\n").toAscii().data();
559 hlp = QString().leftJustified(6);
560 }
561 }
562 }
563 }
564 else {
565 _out << " 1 1 WAVELENGTH FACT L1/2" << endl;
566 _out << " 8 C1 P1 L1 S1 C2 P2 L2 S2 # / TYPES OF OBSERV" << endl;
567 }
568}
569
[73]570// Stores Observation into Internal Array
571////////////////////////////////////////////////////////////////////////////
[2711]572void bncRinex::deepCopy(t_obs obs) {
573 _obs.push_back(obs);
[73]574}
575
576// Write One Epoch into the RINEX File
577////////////////////////////////////////////////////////////////////////////
[3525]578void bncRinex::dumpEpoch(const QByteArray& format, long maxTime) {
[73]579
[160]580 // Select observations older than maxTime
581 // --------------------------------------
[2711]582 QList<t_obs> dumpList;
583 QMutableListIterator<t_obs> mIt(_obs);
[160]584 while (mIt.hasNext()) {
[2711]585 t_obs obs = mIt.next();
586 if (obs.GPSWeek * 7*24*3600 + obs.GPSWeeks < maxTime - 0.05) {
[622]587 dumpList.push_back(obs);
[160]588 mIt.remove();
589 }
590 }
591
[75]592 // Easy Return
593 // -----------
[160]594 if (dumpList.isEmpty()) {
[75]595 return;
596 }
597
598 // Time of Epoch
599 // -------------
[2711]600 const t_obs& fObs = dumpList.first();
601 QDateTime datTim = dateAndTimeFromGPSweek(fObs.GPSWeek, fObs.GPSWeeks);
602 QDateTime datTimNom = dateAndTimeFromGPSweek(fObs.GPSWeek,
603 floor(fObs.GPSWeeks+0.5));
[75]604
[130]605 // Close the file
606 // --------------
[267]607 if (_nextCloseEpoch.isValid() && datTimNom >= _nextCloseEpoch) {
[130]608 closeFile();
609 _headerWritten = false;
610 }
611
[78]612 // Write RINEX Header
613 // ------------------
614 if (!_headerWritten) {
[3525]615 writeHeader(format, datTim, datTimNom);
[78]616 }
617
[2711]618 double sec = double(datTim.time().second()) + fmod(fObs.GPSWeeks,1.0);
[75]619
[1044]620 // Epoch header line: RINEX Version 3
621 // ----------------------------------
[540]622 if (_rinexVers == 3) {
623 _out << datTim.toString("> yyyy MM dd hh mm ").toAscii().data()
624 << setw(10) << setprecision(7) << sec
625 << " " << 0 << setw(3) << dumpList.size() << endl;
[74]626 }
[1044]627 // Epoch header line: RINEX Version 2
628 // ----------------------------------
[540]629 else {
630 _out << datTim.toString(" yy MM dd hh mm ").toAscii().data()
631 << setw(10) << setprecision(7) << sec
632 << " " << 0 << setw(3) << dumpList.size();
[1044]633
[2711]634 QListIterator<t_obs> it(dumpList); int iSat = 0;
[540]635 while (it.hasNext()) {
636 iSat++;
[2711]637 const t_obs& obs = it.next();
638 _out << obs.satSys << setw(2) << obs.satNum;
[540]639 if (iSat == 12 && it.hasNext()) {
640 _out << endl << " ";
641 iSat = 0;
642 }
643 }
[77]644 _out << endl;
[1044]645 }
646
[2711]647 QListIterator<t_obs> it(dumpList);
[1044]648 while (it.hasNext()) {
[2711]649 const t_obs& obs = it.next();
[1044]650
651 // Cycle slips detection
652 // ---------------------
[2711]653 QString prn = QString("%1%2").arg(obs.satSys)
654 .arg(obs.satNum, 2, 10, QChar('0'));
[1044]655
656 char lli1 = ' ';
657 char lli2 = ' ';
[2688]658 char lli5 = ' ';
[2711]659 if ( obs.slip_cnt_L1 >= 0 ) {
[1044]660 if ( _slip_cnt_L1.find(prn) != _slip_cnt_L1.end() &&
[2711]661 _slip_cnt_L1.find(prn).value() != obs.slip_cnt_L1 ) {
[2682]662 lli1 = '1';
[1044]663 }
664 }
665
[2711]666 if ( obs.slip_cnt_L2 >= 0 ) {
[1044]667 if ( _slip_cnt_L2.find(prn) != _slip_cnt_L2.end() &&
[2711]668 _slip_cnt_L2.find(prn).value() != obs.slip_cnt_L2 ) {
[2682]669 lli2 = '1';
[1044]670 }
671 }
672
[2711]673 if ( obs.slip_cnt_L5 >= 0 ) {
[2688]674 if ( _slip_cnt_L5.find(prn) != _slip_cnt_L5.end() &&
[2711]675 _slip_cnt_L5.find(prn).value() != obs.slip_cnt_L5 ) {
[2688]676 lli5 = '1';
677 }
678 }
679
[2711]680 _slip_cnt_L1[prn] = obs.slip_cnt_L1;
681 _slip_cnt_L2[prn] = obs.slip_cnt_L2;
682 _slip_cnt_L5[prn] = obs.slip_cnt_L5;
[1044]683
684 // RINEX Version 3
685 // ---------------
686 if (_rinexVers == 3) {
[3341]687 _out << rinexSatLine(obs, lli1, lli2, lli5);
[2696]688 _out << endl;
[1044]689 }
690
691 // RINEX Version 2
692 // ---------------
693 else {
[4403]694 _out << setw(14) << setprecision(3) << obs.measdata("C1", _rinexVers) << ' ' << ' '
695 << setw(14) << setprecision(3) << obs.measdata("P1", _rinexVers) << ' ' << ' '
696 << setw(14) << setprecision(3) << obs.measdata("L1", _rinexVers) << lli1 << ' '
697 << setw(14) << setprecision(3) << obs.measdata("S1", _rinexVers) << ' ' << ' '
698 << setw(14) << setprecision(3) << obs.measdata("C2", _rinexVers) << ' ' << ' ' << endl
699 << setw(14) << setprecision(3) << obs.measdata("P2", _rinexVers) << ' ' << ' '
700 << setw(14) << setprecision(3) << obs.measdata("L2", _rinexVers) << lli2 << ' '
701 << setw(14) << setprecision(3) << obs.measdata("S2", _rinexVers) << endl;
[540]702 }
[75]703 }
704
[77]705 _out.flush();
[73]706}
707
[130]708// Close the Old RINEX File
709////////////////////////////////////////////////////////////////////////////
710void bncRinex::closeFile() {
[698]711 if (_rinexVers == 3) {
[843]712 _out << "> 4 1" << endl;
[698]713 _out << "END OF FILE" << endl;
714 }
[130]715 _out.close();
[132]716 if (!_rnxScriptName.isEmpty()) {
[1523]717 qApp->thread()->wait(100);
[435]718#ifdef WIN32
719 QProcess::startDetached(_rnxScriptName, QStringList() << _fName) ;
720#else
[475]721 QProcess::startDetached("nohup", QStringList() << _rnxScriptName << _fName) ;
[435]722#endif
[436]723
[132]724 }
[130]725}
[2695]726
[4391]727// One Line in RINEX v3
[2695]728////////////////////////////////////////////////////////////////////////////
[3341]729string bncRinex::rinexSatLine(const t_obs& obs, char lli1, char lli2,
730 char lli5) {
[2695]731 ostringstream str;
732 str.setf(ios::showpoint | ios::fixed);
733
[4384]734 str << obs.satSys
735 << setw(2) << setfill('0') << obs.satNum << setfill(' ');
736
[4391]737 const QVector<QString>& types = _rnxTypes[obs.satSys];
738 for (int ii = 0; ii < types.size(); ii++) {
[4408]739 double value = obs.measdata(types[ii], _rinexVers);
740 str << setw(14) << setprecision(3) << value;
741 if (value != 0.0 && types[ii].indexOf("L1") == 0) {
742 str << lli1 << ' ';
[4407]743 }
[4408]744 else if (value != 0.0 && types[ii].indexOf("L2") == 0) {
745 str << lli2 << ' ';
[4407]746 }
[4408]747 else if (value != 0.0 && types[ii].indexOf("L5") == 0) {
748 str << lli5 << ' ';
[4407]749 }
750 else {
[4408]751 str << " ";
[4407]752 }
[2695]753 }
[4389]754
[2695]755 return str.str();
756}
[3324]757
[3344]758//
759////////////////////////////////////////////////////////////////////////////
760string bncRinex::obsToStr(double val, int width, int precision) {
[3326]761 if (val != 0.0) {
762 ostringstream str;
763 str.setf(ios::showpoint | ios::fixed);
[3344]764 str << setw(width) << setprecision(precision) << val;
[3326]765 return str.str();
766 }
767 else {
768 return "0.0";
769 }
770}
771
[3324]772// One Line in ASCII (Internal) Format
773////////////////////////////////////////////////////////////////////////////
774string bncRinex::asciiSatLine(const t_obs& obs) {
775
776 ostringstream str;
777 str.setf(ios::showpoint | ios::fixed);
778
[3325]779 str << obs.satSys << setw(2) << setfill('0') << obs.satNum << setfill(' ');
780
[3344]781 if (obs.satSys == 'R') { // Glonass
782 str << ' ' << setw(2) << obs.slotNum;
783 }
784 else {
785 str << " ";
786 }
787
[4403]788 float rnxVers = 3.0;
789
[4391]790 if (obs.satSys == 'G') { // GPS
791 str << " 1C "
[4403]792 << obsToStr(obs.measdata("C1C", rnxVers)) << ' '
793 << obsToStr(obs.measdata("L1C", rnxVers)) << ' '
794 << obsToStr(obs.measdata("D1C", rnxVers)) << ' '
795 << obsToStr(obs.measdata("S1C", rnxVers), 8, 3) << ' '
[4391]796 << setw(2) << obs.slip_cnt_L1;
[4403]797 str << " 1P "
798 << obsToStr(obs.measdata("C1P", rnxVers)) << ' '
799 << obsToStr(obs.measdata("L1P", rnxVers)) << ' '
800 << obsToStr(obs.measdata("D1P", rnxVers)) << ' '
801 << obsToStr(obs.measdata("S1P", rnxVers), 8, 3) << ' '
[4391]802 << setw(2) << obs.slip_cnt_L1;
803 str << " 2P "
[4403]804 << obsToStr(obs.measdata("C2P", rnxVers)) << ' '
805 << obsToStr(obs.measdata("L2P", rnxVers)) << ' '
806 << obsToStr(obs.measdata("D2P", rnxVers)) << ' '
807 << obsToStr(obs.measdata("S2P", rnxVers), 8, 3) << ' '
[4391]808 << setw(2) << obs.slip_cnt_L2;
809 str << " 5C "
[4403]810 << obsToStr(obs.measdata("C5", rnxVers)) << ' '
811 << obsToStr(obs.measdata("L5", rnxVers)) << ' '
812 << obsToStr(obs.measdata("D5", rnxVers)) << ' '
813 << obsToStr(obs.measdata("S5", rnxVers), 8, 3) << ' '
[4391]814 << setw(2) << obs.slip_cnt_L5;
[3324]815 }
[4391]816 else if (obs.satSys == 'R') { // Glonass
817 str << " 1C "
[4403]818 << obsToStr(obs.measdata("C1C", rnxVers)) << ' '
819 << obsToStr(obs.measdata("L1C", rnxVers)) << ' '
820 << obsToStr(obs.measdata("D1C", rnxVers)) << ' '
821 << obsToStr(obs.measdata("S1C", rnxVers), 8, 3) << ' '
[4391]822 << setw(2) << obs.slip_cnt_L1;
823 str << " 1P "
[4403]824 << obsToStr(obs.measdata("C1P", rnxVers)) << ' '
825 << obsToStr(obs.measdata("L1P", rnxVers)) << ' '
826 << obsToStr(obs.measdata("D1P", rnxVers)) << ' '
827 << obsToStr(obs.measdata("S1P", rnxVers), 8, 3) << ' '
[4391]828 << setw(2) << obs.slip_cnt_L1;
829 str << " 2P "
[4403]830 << obsToStr(obs.measdata("C2P", rnxVers)) << ' '
831 << obsToStr(obs.measdata("L2P", rnxVers)) << ' '
832 << obsToStr(obs.measdata("D2P", rnxVers)) << ' '
833 << obsToStr(obs.measdata("S2P", rnxVers), 8, 3) << ' '
[4391]834 << setw(2) << obs.slip_cnt_L2;
835 str << " 2C "
[4403]836 << obsToStr(obs.measdata("C2C", rnxVers)) << ' '
837 << obsToStr(obs.measdata("L2C", rnxVers)) << ' '
838 << obsToStr(obs.measdata("D2C", rnxVers)) << ' '
839 << obsToStr(obs.measdata("S2C", rnxVers), 8, 3) << ' '
[4391]840 << setw(2) << obs.slip_cnt_L2;
841 }
842 else if (obs.satSys == 'E') { // Galileo
843 str << " 1C "
[4403]844 << obsToStr(obs.measdata("C1", rnxVers)) << ' '
845 << obsToStr(obs.measdata("L1", rnxVers)) << ' '
846 << obsToStr(obs.measdata("D1", rnxVers)) << ' '
847 << obsToStr(obs.measdata("S1", rnxVers), 8, 3) << ' '
[4391]848 << setw(2) << obs.slip_cnt_L1;
[4389]849
[4391]850 str << " 5C "
[4403]851 << obsToStr(obs.measdata("C5", rnxVers)) << ' '
852 << obsToStr(obs.measdata("L5", rnxVers)) << ' '
853 << obsToStr(obs.measdata("D5", rnxVers)) << ' '
854 << obsToStr(obs.measdata("S5", rnxVers), 8, 3) << ' '
[4391]855 << setw(2) << obs.slip_cnt_L5;
856 }
[3324]857 return str.str();
858}
Note: See TracBrowser for help on using the repository browser.