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

Last change on this file since 4038 was 4038, checked in by mervart, 12 years ago
File size: 8.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 int version = settings.value("reqcRnxVersion").toInt();
59 if (version < 3) {
60 _rnxVersion = 2.11;
61 }
62 else {
63 _rnxVersion = 3.01;
64 }
65 _samplingRate = settings.value("reqcSampling").toInt();
66 _begTime = bncTime(settings.value("reqcStartDateTime").toString().toAscii().data());
67 _endTime = bncTime(settings.value("reqcEndDateTime").toString().toAscii().data());
68}
69
70// Destructor
71////////////////////////////////////////////////////////////////////////////
72t_reqcEdit::~t_reqcEdit() {
73 for (int ii = 0; ii < _rnxObsFiles.size(); ii++) {
74 delete _rnxObsFiles[ii];
75 }
76 for (int ii = 0; ii < _ephs.size(); ii++) {
77 delete _ephs[ii];
78 }
79}
80
81//
82////////////////////////////////////////////////////////////////////////////
83void t_reqcEdit::run() {
84
85 editObservations();
86
87 editEphemerides();
88
89 bncApp* app = (bncApp*) qApp;
90 if ( app->mode() != bncApp::interactive) {
91 app->exit(0);
92 }
93 else {
94 emit finished();
95 deleteLater();
96 }
97}
98
99//
100////////////////////////////////////////////////////////////////////////////
101void t_reqcEdit::editObservations() {
102
103 // Easy Exit
104 // ---------
105 if (_obsFileNames.isEmpty() || _outObsFileName.isEmpty()) {
106 return;
107 }
108
109 // Initialize input observation files, sort them according to start time
110 // ---------------------------------------------------------------------
111 QStringListIterator it(_obsFileNames);
112 while (it.hasNext()) {
113 QString fileName = it.next();
114 t_rnxObsFile* rnxObsFile = new t_rnxObsFile(fileName, t_rnxObsFile::input);
115 _rnxObsFiles.append(rnxObsFile);
116 }
117 qStableSort(_rnxObsFiles.begin(), _rnxObsFiles.end(),
118 t_rnxObsFile::earlierStartTime);
119
120 // Initialize output observation file
121 // ----------------------------------
122 t_rnxObsFile outObsFile(_outObsFileName, t_rnxObsFile::output);
123
124 // Loop over all input observation files
125 // -------------------------------------
126 for (int ii = 0; ii < _rnxObsFiles.size(); ii++) {
127 t_rnxObsFile* obsFile = _rnxObsFiles[ii];
128 if (ii == 0) {
129 outObsFile.setHeader(obsFile->header(), _rnxVersion);
130 if (_begTime.valid() && _begTime > outObsFile.startTime()) {
131 outObsFile.setStartTime(_begTime);
132 }
133 editRnxObsHeader(outObsFile);
134 outObsFile.writeHeader();
135 }
136 t_rnxObsFile::t_rnxEpo* epo = 0;
137 while ( (epo = obsFile->nextEpoch()) != 0) {
138 if (_begTime.valid() && epo->tt < _begTime) {
139 continue;
140 }
141 if (_endTime.valid() && epo->tt > _endTime) {
142 break;
143 }
144
145 if (_samplingRate == 0 ||
146 fmod(round(epo->tt.gpssec()), _samplingRate) == 0) {
147 applyLLI(obsFile, epo);
148 outObsFile.writeEpoch(epo);
149 }
150 else {
151 rememberLLI(obsFile, epo);
152 }
153 }
154 }
155}
156
157// Change RINEX Header Content
158////////////////////////////////////////////////////////////////////////////
159void t_reqcEdit::editRnxObsHeader(t_rnxObsFile& obsFile) {
160
161 bncSettings settings;
162
163 QString oldMarkerName = settings.value("reqcOldMarkerName").toString();
164 QString newMarkerName = settings.value("reqcNewMarkerName").toString();
165 if (oldMarkerName.isEmpty() ||
166 QRegExp(oldMarkerName).exactMatch(obsFile.markerName())) {
167 obsFile.setMarkerName(newMarkerName);
168 }
169
170 QString oldAntennaName = settings.value("reqcOldAntennaName").toString();
171 QString newAntennaName = settings.value("reqcNewAntennaName").toString();
172 if (oldAntennaName.isEmpty() ||
173 QRegExp(oldAntennaName).exactMatch(obsFile.antennaName())) {
174 obsFile.setAntennaName(newAntennaName);
175 }
176
177 QString oldReceiverType = settings.value("reqcOldReceiverName").toString();
178 QString newReceiverType = settings.value("reqcNewReceiverName").toString();
179 if (oldReceiverType.isEmpty() ||
180 QRegExp(oldReceiverType).exactMatch(obsFile.receiverType())) {
181 obsFile.setReceiverType(newReceiverType);
182 }
183}
184
185//
186////////////////////////////////////////////////////////////////////////////
187void t_reqcEdit::rememberLLI(const t_rnxObsFile* obsFile,
188 const t_rnxObsFile::t_rnxEpo* epo) {
189
190 if (_samplingRate == 0) {
191 return;
192 }
193
194 for (unsigned iSat = 0; iSat < epo->rnxSat.size(); iSat++) {
195 const t_rnxObsFile::t_rnxSat& rnxSat = epo->rnxSat[iSat];
196 char sys = rnxSat.satSys;
197 QString prn = QString("%1%2").arg(sys).arg(rnxSat.satNum,2,10,QChar('0'));
198
199 for (int iType = 0; iType < obsFile->nTypes(sys); iType++) {
200 if (!_lli[prn].contains(iType)) {
201 _lli[prn][iType] = 0;
202 }
203 if (rnxSat.lli[iType] & 1) {
204 _lli[prn][iType] |= 1;
205 }
206 }
207 }
208}
209
210//
211////////////////////////////////////////////////////////////////////////////
212void t_reqcEdit::applyLLI(const t_rnxObsFile* obsFile,
213 t_rnxObsFile::t_rnxEpo* epo) {
214
215 if (_samplingRate == 0) {
216 return;
217 }
218
219 for (unsigned iSat = 0; iSat < epo->rnxSat.size(); iSat++) {
220 t_rnxObsFile::t_rnxSat& rnxSat = epo->rnxSat[iSat];
221 char sys = rnxSat.satSys;
222 QString prn = QString("%1%2").arg(sys).arg(rnxSat.satNum,2,10,QChar('0'));
223
224 for (int iType = 0; iType < obsFile->nTypes(sys); iType++) {
225 if (_lli[prn].contains(iType) && _lli[prn][iType] & 1) {
226 rnxSat.lli[iType] |= 1;
227 }
228 }
229 }
230
231 _lli.clear();
232}
233
234//
235////////////////////////////////////////////////////////////////////////////
236void t_reqcEdit::editEphemerides() {
237
238 // Easy Exit
239 // ---------
240 if (_navFileNames.isEmpty() || _outNavFileName.isEmpty()) {
241 return;
242 }
243
244 // Read All Ephemerides
245 // --------------------
246 QStringListIterator it(_navFileNames);
247 while (it.hasNext()) {
248 QString fileName = it.next();
249 t_rnxNavFile rnxNavFile(fileName, t_rnxNavFile::input);
250 for (unsigned ii = 0; ii < rnxNavFile.ephs().size(); ii++) {
251 t_eph* eph = rnxNavFile.ephs()[ii];
252 bool isNew = true;
253 for (int iOld = 0; iOld < _ephs.size(); iOld++) {
254 const t_eph* ephOld = _ephs[iOld];
255 if (ephOld->prn() == eph->prn() && ephOld->IOD() == eph->IOD()) {
256 isNew = false;
257 break;
258 }
259 }
260 if (isNew) {
261 if (eph->type() == t_eph::GPS) {
262 _ephs.append(new t_ephGPS(*dynamic_cast<t_ephGPS*>(eph)));
263 }
264 else if (eph->type() == t_eph::GLONASS) {
265 _ephs.append(new t_ephGlo(*dynamic_cast<t_ephGlo*>(eph)));
266 }
267 else if (eph->type() == t_eph::Galileo) {
268 _ephs.append(new t_ephGal(*dynamic_cast<t_ephGal*>(eph)));
269 }
270 }
271 }
272 }
273 qStableSort(_ephs.begin(), _ephs.end(), t_eph::earlierTime);
274
275 // Initialize output navigation file
276 // ---------------------------------
277 t_rnxNavFile outNavFile(_outNavFileName, t_rnxNavFile::output);
278 outNavFile.setVersion(_rnxVersion);
279 outNavFile.writeHeader();
280
281 // Loop over all ephemerides
282 // -------------------------
283 for (int ii = 0; ii < _ephs.size(); ii++) {
284 const t_eph* eph = _ephs[ii];
285 if (eph->type() == t_eph::GPS || _rnxVersion >= 3.0) {
286 outNavFile.writeEph(eph);
287 }
288 }
289}
Note: See TracBrowser for help on using the repository browser.