source: ntrip/trunk/BNC/rinex/reqcedit.cpp@ 4003

Last change on this file since 4003 was 4003, checked in by mervart, 12 years ago
File size: 7.9 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/* -------------------------------------------------------------------------
26 * BKG NTRIP Client
27 * -------------------------------------------------------------------------
28 *
29 * Class: t_reqcEdit
30 *
31 * Purpose: Edit/Concatenate RINEX Files
32 *
33 * Author: L. Mervart
34 *
35 * Created: 11-Apr-2012
36 *
37 * Changes:
38 *
39 * -----------------------------------------------------------------------*/
40
41#include <iostream>
42#include "reqcedit.h"
43#include "bncapp.h"
44#include "bncsettings.h"
45
46using namespace std;
47
48// Constructor
49////////////////////////////////////////////////////////////////////////////
50t_reqcEdit::t_reqcEdit(QObject* parent) : QThread(parent) {
51
52 bncSettings settings;
53
54 _obsFileNames = settings.value("reqcObsFile").toString().split(",", QString::SkipEmptyParts);
55 _outObsFileName = settings.value("reqcOutObsFile").toString();
56 _navFileNames = settings.value("reqcNavFile").toString().split(",", QString::SkipEmptyParts);
57 _outNavFileName = settings.value("reqcOutNavFile").toString();
58 _rnxVersion = settings.value("reqcRnxVersion").toDouble();
59 _samplingRate = settings.value("reqcSampling").toInt();
60 _begTime = bncTime(settings.value("reqcStartDateTime").toString().toAscii().data());
61 _endTime = bncTime(settings.value("reqcEndDateTime").toString().toAscii().data());
62}
63
64// Destructor
65////////////////////////////////////////////////////////////////////////////
66t_reqcEdit::~t_reqcEdit() {
67 for (int ii = 0; ii < _rnxObsFiles.size(); ii++) {
68 delete _rnxObsFiles[ii];
69 }
70 for (int ii = 0; ii < _ephs.size(); ii++) {
71 delete _ephs[ii];
72 }
73}
74
75//
76////////////////////////////////////////////////////////////////////////////
77void t_reqcEdit::run() {
78
79 editObservations();
80
81 editEphemerides();
82
83 bncApp* app = (bncApp*) qApp;
84 if ( app->mode() != bncApp::interactive) {
85 app->exit(0);
86 }
87 else {
88 emit finished();
89 deleteLater();
90 }
91}
92
93//
94////////////////////////////////////////////////////////////////////////////
95void t_reqcEdit::editObservations() {
96
97 // Initialize input observation files, sort them according to start time
98 // ---------------------------------------------------------------------
99 QStringListIterator it(_obsFileNames);
100 while (it.hasNext()) {
101 QString fileName = it.next();
102 t_rnxObsFile* rnxObsFile = new t_rnxObsFile(fileName, t_rnxObsFile::input);
103 _rnxObsFiles.append(rnxObsFile);
104 }
105 qStableSort(_rnxObsFiles.begin(), _rnxObsFiles.end(),
106 t_rnxObsFile::earlierStartTime);
107
108 // Initialize output observation file
109 // ----------------------------------
110 t_rnxObsFile outObsFile(_outObsFileName, t_rnxObsFile::output);
111
112 // Loop over all input observation files
113 // -------------------------------------
114 for (int ii = 0; ii < _rnxObsFiles.size(); ii++) {
115 t_rnxObsFile* obsFile = _rnxObsFiles[ii];
116 if (ii == 0) {
117 outObsFile.setHeader(obsFile->header(), _rnxVersion);
118 if (_begTime.valid() && _begTime > outObsFile.startTime()) {
119 outObsFile.setStartTime(_begTime);
120 }
121 editRnxObsHeader(outObsFile);
122 outObsFile.writeHeader();
123 }
124 t_rnxObsFile::t_rnxEpo* epo = 0;
125 while ( (epo = obsFile->nextEpoch()) != 0) {
126 if (_begTime.valid() && epo->tt < _begTime) {
127 continue;
128 }
129 if (_endTime.valid() && epo->tt > _endTime) {
130 break;
131 }
132
133 if (_samplingRate == 0 ||
134 fmod(round(epo->tt.gpssec()), _samplingRate) == 0) {
135 applyLLI(obsFile, epo);
136 outObsFile.writeEpoch(epo);
137 }
138 else {
139 rememberLLI(obsFile, epo);
140 }
141 }
142 }
143}
144
145// Change RINEX Header Content
146////////////////////////////////////////////////////////////////////////////
147void t_reqcEdit::editRnxObsHeader(t_rnxObsFile& obsFile) {
148
149 bncSettings settings;
150
151 QString oldMarkerName = settings.value("reqcOldMarkerName").toString();
152 QString newMarkerName = settings.value("reqcNewMarkerName").toString();
153 if (oldMarkerName.isEmpty() ||
154 QRegExp(oldMarkerName).exactMatch(obsFile.markerName())) {
155 obsFile.setMarkerName(newMarkerName);
156 }
157
158 QString oldAntennaName = settings.value("reqcOldAntennaName").toString();
159 QString newAntennaName = settings.value("reqcNewAntennaName").toString();
160 if (oldAntennaName.isEmpty() ||
161 QRegExp(oldAntennaName).exactMatch(obsFile.antennaName())) {
162 obsFile.setAntennaName(newAntennaName);
163 }
164
165 QString oldReceiverType = settings.value("reqcOldReceiverName").toString();
166 QString newReceiverType = settings.value("reqcNewReceiverName").toString();
167 if (oldReceiverType.isEmpty() ||
168 QRegExp(oldReceiverType).exactMatch(obsFile.receiverType())) {
169 obsFile.setReceiverType(newReceiverType);
170 }
171}
172
173//
174////////////////////////////////////////////////////////////////////////////
175void t_reqcEdit::rememberLLI(const t_rnxObsFile* obsFile,
176 const t_rnxObsFile::t_rnxEpo* epo) {
177
178 if (_samplingRate == 0) {
179 return;
180 }
181
182 for (unsigned iSat = 0; iSat < epo->rnxSat.size(); iSat++) {
183 const t_rnxObsFile::t_rnxSat& rnxSat = epo->rnxSat[iSat];
184 char sys = rnxSat.satSys;
185 QString prn = QString("%1%2").arg(sys).arg(rnxSat.satNum,2,10,QChar('0'));
186
187 for (int iType = 0; iType < obsFile->nTypes(sys); iType++) {
188 if (!_lli[prn].contains(iType)) {
189 _lli[prn][iType] = 0;
190 }
191 if (rnxSat.lli[iType] & 1) {
192 _lli[prn][iType] |= 1;
193 }
194 }
195 }
196}
197
198//
199////////////////////////////////////////////////////////////////////////////
200void t_reqcEdit::applyLLI(const t_rnxObsFile* obsFile,
201 t_rnxObsFile::t_rnxEpo* epo) {
202
203 if (_samplingRate == 0) {
204 return;
205 }
206
207 for (unsigned iSat = 0; iSat < epo->rnxSat.size(); iSat++) {
208 t_rnxObsFile::t_rnxSat& rnxSat = epo->rnxSat[iSat];
209 char sys = rnxSat.satSys;
210 QString prn = QString("%1%2").arg(sys).arg(rnxSat.satNum,2,10,QChar('0'));
211
212 for (int iType = 0; iType < obsFile->nTypes(sys); iType++) {
213 if (_lli[prn].contains(iType) && _lli[prn][iType] & 1) {
214 rnxSat.lli[iType] |= 1;
215 }
216 }
217 }
218
219 _lli.clear();
220}
221
222//
223////////////////////////////////////////////////////////////////////////////
224void t_reqcEdit::editEphemerides() {
225
226 // Read All Ephemerides
227 // --------------------
228 QStringListIterator it(_navFileNames);
229 while (it.hasNext()) {
230 QString fileName = it.next();
231 t_rnxNavFile rnxNavFile(fileName, t_rnxNavFile::input);
232 for (unsigned ii = 0; ii < rnxNavFile.ephs().size(); ii++) {
233 t_eph* eph = rnxNavFile.ephs()[ii];
234 t_ephGPS* ephGPS = dynamic_cast<t_ephGPS*>(eph);
235 t_ephGlo* ephGlo = dynamic_cast<t_ephGlo*>(eph);
236 t_ephGal* ephGal = dynamic_cast<t_ephGal*>(eph);
237 if (ephGPS) {
238 _ephs.append(new t_ephGPS(*ephGPS));
239 }
240 else if (ephGlo) {
241 _ephs.append(new t_ephGlo(*ephGlo));
242 }
243 else if (ephGal) {
244 _ephs.append(new t_ephGal(*ephGal));
245 }
246 }
247 }
248 qStableSort(_ephs.begin(), _ephs.end(), t_eph::earlierTime);
249
250}
Note: See TracBrowser for help on using the repository browser.