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

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