source: ntrip/trunk/BNC/bncrinex.cpp@ 127

Last change on this file since 127 was 127, checked in by mervart, 18 years ago

* empty log message *

File size: 7.6 KB
Line 
1
2/* -------------------------------------------------------------------------
3 * BKG NTRIP Client
4 * -------------------------------------------------------------------------
5 *
6 * Class: bncRinex
7 *
8 * Purpose: writes RINEX files
9 *
10 * Author: L. Mervart
11 *
12 * Created: 27-Aug-2006
13 *
14 * Changes:
15 *
16 * -----------------------------------------------------------------------*/
17
18#include <QSettings>
19#include <QDir>
20#include <QDate>
21#include <QFile>
22#include <QTextStream>
23#include <iomanip>
24
25#include "bncrinex.h"
26#include "bncutils.h"
27#include "bncconst.h"
28
29using namespace std;
30
31// Constructor
32////////////////////////////////////////////////////////////////////////////
33bncRinex::bncRinex(const char* StatID) {
34 _statID = StatID;
35 _headerWritten = false;
36 readSkeleton();
37}
38
39// Destructor
40////////////////////////////////////////////////////////////////////////////
41bncRinex::~bncRinex() {
42 _out.close();
43}
44
45// Read Skeleton Header File
46////////////////////////////////////////////////////////////////////////////
47void bncRinex::readSkeleton() {
48
49 // Resolve Skeleton File Name
50 // --------------------------
51 QSettings settings;
52 QString sklName = settings.value("rnxPath").toString();
53 expandEnvVar(sklName);
54 if ( sklName[sklName.length()-1] != QDir::separator() ) {
55 sklName += QDir::separator();
56 }
57 sklName += _statID.left(4) + "." + settings.value("rnxSkel").toString();
58
59 // Read the File
60 // -------------
61 QFile skl(sklName);
62 if ( skl.exists() && skl.open(QIODevice::ReadOnly) ) {
63 QTextStream in(&skl);
64 while ( !in.atEnd() ) {
65 _headerLines.append( in.readLine() );
66 if (_headerLines.last().indexOf("END OF HEADER") != -1) {
67 break;
68 }
69 }
70 }
71}
72
73// File Name according to RINEX Standards
74////////////////////////////////////////////////////////////////////////////
75void bncRinex::resolveFileName(const QDateTime& datTim) {
76
77 QSettings settings;
78 QString path = settings.value("rnxPath").toString();
79 expandEnvVar(path);
80
81 if ( path[path.length()-1] != QDir::separator() ) {
82 path += QDir::separator();
83 }
84
85 QString intStr = settings.value("rnxIntr").toString();
86 QString hlpStr;
87 if (intStr == "15 min") {
88 char ch = 'A' + datTim.time().hour();
89 hlpStr = ch;
90 if (datTim.time().minute() < 15) {
91 hlpStr += "00";
92 }
93 else if (datTim.time().minute() < 30) {
94 hlpStr += "15";
95 }
96 else if (datTim.time().minute() < 45) {
97 hlpStr += "30";
98 }
99 else {
100 hlpStr += "45";
101 }
102 }
103 else if (intStr == "1 hour") {
104 char ch = 'A' + datTim.time().hour();
105 hlpStr = ch;
106 }
107 else {
108 hlpStr = "0";
109 }
110
111 path += _statID.left(4) +
112 QString("%1").arg(datTim.date().dayOfYear(), 3, 10, QChar('0')) +
113 hlpStr +
114 datTim.toString(".yyO");
115
116 _fName = path.toAscii();
117}
118
119// Write RINEX Header
120////////////////////////////////////////////////////////////////////////////
121void bncRinex::writeHeader(const QDateTime& datTim) {
122
123 // Open the Output File
124 // --------------------
125 resolveFileName(datTim);
126 _out.open(_fName.data());
127 _out.setf(ios::showpoint | ios::fixed);
128
129 // Copy Skeleton Header
130 // --------------------
131 if (_headerLines.size() > 0) {
132 QStringListIterator it(_headerLines);
133 while (it.hasNext()) {
134 QString line = it.next();
135 if (line.indexOf("# / TYPES OF OBSERV") != -1) {
136 _out << " 4 P1 P2 L1 L2"
137 " # / TYPES OF OBSERV" << endl;
138 }
139 else if (line.indexOf("TIME OF FIRST OBS") != -1) {
140 _out << datTim.toString(" yyyy MM dd"
141 " hh mm ss.zzz0000").toAscii().data();
142 _out << " TIME OF FIRST OBS" << endl;
143 }
144 else {
145 _out << line.toAscii().data() << endl;
146 }
147 }
148 }
149
150 // Write Dummy Header
151 // ------------------
152 else {
153 double approxPos[3]; approxPos[0] = approxPos[1] = approxPos[2] = 0.0;
154 double antennaNEU[3]; antennaNEU[0] = antennaNEU[1] = antennaNEU[2] = 0.0;
155
156 _out << " 2.10 OBSERVATION DATA G (GPS) RINEX VERSION / TYPE" << endl;
157 _out << "BNC LM 27-Aug-2006 PGM / RUN BY / DATE" << endl;
158 _out.setf(ios::left);
159 _out << setw(60) << _statID.data() << "MARKER NAME" << endl;
160 _out << setw(60) << "BKG" << "OBSERVER / AGENCY" << endl;
161 _out << setw(20) << "unknown"
162 << setw(20) << "unknown"
163 << setw(20) << "unknown" << "REC # / TYPE / VERS" << endl;
164 _out << setw(20) << "unknown"
165 << setw(20) << "unknown"
166 << setw(20) << " " << "ANT # / TYPE" << endl;
167 _out.unsetf(ios::left);
168 _out << setw(14) << setprecision(4) << approxPos[0]
169 << setw(14) << setprecision(4) << approxPos[1]
170 << setw(14) << setprecision(4) << approxPos[2]
171 << " " << "APPROX POSITION XYZ" << endl;
172 _out << setw(14) << setprecision(4) << antennaNEU[0]
173 << setw(14) << setprecision(4) << antennaNEU[1]
174 << setw(14) << setprecision(4) << antennaNEU[2]
175 << " " << "ANTENNA: DELTA H/E/N" << endl;
176 _out << " 1 1 WAVELENGTH FACT L1/2" << endl;
177 _out << " 4 P1 P2 L1 L2 # / TYPES OF OBSERV" << endl;
178 _out << datTim.toString(" yyyy MM dd"
179 " hh mm ss.zzz0000").toAscii().data();
180 _out << " " << "TIME OF FIRST OBS" << endl;
181 _out << " END OF HEADER" << endl;
182 }
183
184 _headerWritten = true;
185}
186
187// Stores Observation into Internal Array
188////////////////////////////////////////////////////////////////////////////
189void bncRinex::deepCopy(const Observation* obs) {
190 Observation* newObs = new Observation();
191 memcpy(newObs, obs, sizeof(*obs));
192 _obs.push_back(newObs);
193}
194
195// Write One Epoch into the RINEX File
196////////////////////////////////////////////////////////////////////////////
197void bncRinex::dumpEpoch() {
198
199 // Easy Return
200 // -----------
201 if (_obs.isEmpty()) {
202 return;
203 }
204
205 // Time of Epoch
206 // -------------
207 Observation* firstObs = *_obs.begin();
208
209 QDateTime datTim = dateAndTimeFromGPSweek( firstObs->GPSWeek,
210 firstObs->GPSWeeks +
211 fmod(firstObs->sec, 1.0) );
212
213 // Write RINEX Header
214 // ------------------
215 if (!_headerWritten) {
216 writeHeader(datTim);
217 }
218
219 _out << datTim.toString(" yy MM dd hh mm ss.zzz0000").toAscii().data();
220
221 QListIterator<Observation*> it(_obs); int iSat = 0;
222 while (it.hasNext()) {
223 iSat++;
224 Observation* ob = it.next();
225 _out << " " << setw(2) << int(ob->SVPRN);
226 if (iSat == 12 && it.hasNext()) {
227 _out << endl << " ";
228 iSat = 0;
229 }
230 }
231 _out << endl;
232
233 it.toFront();
234 while (it.hasNext()) {
235 Observation* ob = it.next();
236
237 char lli = ' ';
238 char snr = ' ';
239 _out << setw(14) << setprecision(3) << ob->C1 << lli << snr;
240 _out << setw(14) << setprecision(3) << ob->P2 << lli << snr;
241 _out << setw(14) << setprecision(3) << ob->L1 / t_CST::lambda1 << lli << snr;
242 _out << setw(14) << setprecision(3) << ob->L2 / t_CST::lambda2 << lli << snr;
243 _out << endl;
244
245 delete ob;
246 }
247
248 _out.flush();
249 _obs.clear();
250}
251
Note: See TracBrowser for help on using the repository browser.