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

Last change on this file since 4000 was 4000, checked in by mervart, 12 years ago
File size: 7.8 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}
71
72//
73////////////////////////////////////////////////////////////////////////////
74void t_reqcEdit::run() {
75
76 editObservations();
77
78 editEphemerides();
79
80 bncApp* app = (bncApp*) qApp;
81 if ( app->mode() != bncApp::interactive) {
82 app->exit(0);
83 }
84 else {
85 emit finished();
86 deleteLater();
87 }
88}
89
90//
91////////////////////////////////////////////////////////////////////////////
92void t_reqcEdit::editObservations() {
93
94 // Initialize input observation files, sort them according to start time
95 // ---------------------------------------------------------------------
96 QStringListIterator it(_obsFileNames);
97 while (it.hasNext()) {
98 QString fileName = it.next();
99 t_rnxObsFile* rnxObsFile = new t_rnxObsFile(fileName, t_rnxObsFile::input);
100 _rnxObsFiles.append(rnxObsFile);
101 }
102 qStableSort(_rnxObsFiles.begin(), _rnxObsFiles.end(),
103 t_rnxObsFile::earlierStartTime);
104
105 // Initialize output observation file
106 // ----------------------------------
107 t_rnxObsFile outObsFile(_outObsFileName, t_rnxObsFile::output);
108
109 // Loop over all input observation files
110 // -------------------------------------
111 for (int ii = 0; ii < _rnxObsFiles.size(); ii++) {
112 t_rnxObsFile* obsFile = _rnxObsFiles[ii];
113 if (ii == 0) {
114 outObsFile.setHeader(obsFile->header(), _rnxVersion);
115 if (_begTime.valid() && _begTime > outObsFile.startTime()) {
116 outObsFile.setStartTime(_begTime);
117 }
118 editRnxObsHeader(outObsFile);
119 outObsFile.writeHeader();
120 }
121 t_rnxObsFile::t_rnxEpo* epo = 0;
122 while ( (epo = obsFile->nextEpoch()) != 0) {
123 if (_begTime.valid() && epo->tt < _begTime) {
124 continue;
125 }
126 if (_endTime.valid() && epo->tt > _endTime) {
127 break;
128 }
129
130 if (_samplingRate == 0 ||
131 fmod(round(epo->tt.gpssec()), _samplingRate) == 0) {
132 applyLLI(obsFile, epo);
133 outObsFile.writeEpoch(epo);
134 }
135 else {
136 rememberLLI(obsFile, epo);
137 }
138 }
139 }
140}
141
142// Change RINEX Header Content
143////////////////////////////////////////////////////////////////////////////
144void t_reqcEdit::editRnxObsHeader(t_rnxObsFile& obsFile) {
145
146 bncSettings settings;
147
148 QString oldMarkerName = settings.value("reqcOldMarkerName").toString();
149 QString newMarkerName = settings.value("reqcNewMarkerName").toString();
150 if (oldMarkerName.isEmpty() ||
151 QRegExp(oldMarkerName).exactMatch(obsFile.markerName())) {
152 obsFile.setMarkerName(newMarkerName);
153 }
154
155 QString oldAntennaName = settings.value("reqcOldAntennaName").toString();
156 QString newAntennaName = settings.value("reqcNewAntennaName").toString();
157 if (oldAntennaName.isEmpty() ||
158 QRegExp(oldAntennaName).exactMatch(obsFile.antennaName())) {
159 obsFile.setAntennaName(newAntennaName);
160 }
161
162 QString oldReceiverType = settings.value("reqcOldReceiverName").toString();
163 QString newReceiverType = settings.value("reqcNewReceiverName").toString();
164 if (oldReceiverType.isEmpty() ||
165 QRegExp(oldReceiverType).exactMatch(obsFile.receiverType())) {
166 obsFile.setReceiverType(newReceiverType);
167 }
168}
169
170//
171////////////////////////////////////////////////////////////////////////////
172void t_reqcEdit::rememberLLI(const t_rnxObsFile* obsFile,
173 const t_rnxObsFile::t_rnxEpo* epo) {
174
175 if (_samplingRate == 0) {
176 return;
177 }
178
179 for (unsigned iSat = 0; iSat < epo->rnxSat.size(); iSat++) {
180 const t_rnxObsFile::t_rnxSat& rnxSat = epo->rnxSat[iSat];
181 char sys = rnxSat.satSys;
182 QString prn = QString("%1%2").arg(sys).arg(rnxSat.satNum,2,10,QChar('0'));
183
184 for (int iType = 0; iType < obsFile->nTypes(sys); iType++) {
185 if (!_lli[prn].contains(iType)) {
186 _lli[prn][iType] = 0;
187 }
188 if (rnxSat.lli[iType] & 1) {
189 _lli[prn][iType] |= 1;
190 }
191 }
192 }
193}
194
195//
196////////////////////////////////////////////////////////////////////////////
197void t_reqcEdit::applyLLI(const t_rnxObsFile* obsFile,
198 t_rnxObsFile::t_rnxEpo* epo) {
199
200 if (_samplingRate == 0) {
201 return;
202 }
203
204 for (unsigned iSat = 0; iSat < epo->rnxSat.size(); iSat++) {
205 t_rnxObsFile::t_rnxSat& rnxSat = epo->rnxSat[iSat];
206 char sys = rnxSat.satSys;
207 QString prn = QString("%1%2").arg(sys).arg(rnxSat.satNum,2,10,QChar('0'));
208
209 for (int iType = 0; iType < obsFile->nTypes(sys); iType++) {
210 if (_lli[prn].contains(iType) && _lli[prn][iType] & 1) {
211 rnxSat.lli[iType] |= 1;
212 }
213 }
214 }
215
216 _lli.clear();
217}
218
219//
220////////////////////////////////////////////////////////////////////////////
221void t_reqcEdit::editEphemerides() {
222
223 // Read All Ephemerides
224 // --------------------
225 QStringListIterator it(_navFileNames);
226 while (it.hasNext()) {
227 QString fileName = it.next();
228 t_rnxNavFile rnxNavFile(fileName, t_rnxNavFile::input);
229 for (unsigned ii = 0; ii < rnxNavFile.ephs().size(); ii++) {
230 t_eph* eph = rnxNavFile.ephs()[ii];
231 t_ephGPS* ephGPS = dynamic_cast<t_ephGPS*>(eph);
232 t_ephGlo* ephGlo = dynamic_cast<t_ephGlo*>(eph);
233 t_ephGal* ephGal = dynamic_cast<t_ephGal*>(eph);
234 if (ephGPS) {
235 _ephs.append(new t_ephGPS(*ephGPS));
236 }
237 else if (ephGlo) {
238 _ephs.append(new t_ephGlo(*ephGlo));
239 }
240 else if (ephGal) {
241 _ephs.append(new t_ephGal(*ephGal));
242 }
243 }
244 }
245
246}
Note: See TracBrowser for help on using the repository browser.