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

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