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

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

* empty log message *

File size: 7.8 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 "RTCM3/rtcm3torinex.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(struct converttimeinfo& cti) {
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 QDate date(cti.year, cti.month, cti.day);
86
87 QChar ch = '0';
88
89 path += _statID.left(4) +
90 QString("%1%2.%3O").arg(date.dayOfYear(), 3, 10, QChar('0'))
91 .arg(ch)
92 .arg(date.year() % 100, 2, 10, QChar('0'));
93
94 _fName = path.toAscii();
95}
96
97// Write RINEX Header
98////////////////////////////////////////////////////////////////////////////
99void bncRinex::writeHeader(struct converttimeinfo& cti, double second) {
100
101 // Open the Output File
102 // --------------------
103 resolveFileName(cti);
104 _out.open(_fName.data());
105 _out.setf(ios::showpoint | ios::fixed);
106
107 // Copy Skeleton Header
108 // --------------------
109 if (_headerLines.size() > 0) {
110 QStringListIterator it(_headerLines);
111 while (it.hasNext()) {
112 QString line = it.next();
113 if (line.indexOf("# / TYPES OF OBSERV") != -1) {
114 _out << " 4 P1 P2 L1 L2"
115 " # / TYPES OF OBSERV" << endl;
116 }
117 else if (line.indexOf("TIME OF FIRST OBS") != -1) {
118 _out << setw(6) << cti.year
119 << setw(6) << cti.month
120 << setw(6) << cti.day
121 << setw(6) << cti.hour
122 << setw(6) << cti.minute
123 << setw(13) << setprecision(7) << second
124 << " TIME OF FIRST OBS" << endl;
125 }
126 else {
127 _out << line.toAscii().data() << endl;
128 }
129 }
130 }
131
132 // Write Dummy Header
133 // ------------------
134 else {
135 double approxPos[3]; approxPos[0] = approxPos[1] = approxPos[2] = 0.0;
136 double antennaNEU[3]; antennaNEU[0] = antennaNEU[1] = antennaNEU[2] = 0.0;
137
138 _out << " 2.10 OBSERVATION DATA G (GPS) RINEX VERSION / TYPE" << endl;
139 _out << "BNC LM 27-Aug-2006 PGM / RUN BY / DATE" << endl;
140 _out.setf(ios::left);
141 _out << setw(60) << _statID.data() << "MARKER NAME" << endl;
142 _out << setw(60) << "BKG" << "OBSERVER / AGENCY" << endl;
143 _out << setw(20) << "unknown"
144 << setw(20) << "unknown"
145 << setw(20) << "unknown" << "REC # / TYPE / VERS" << endl;
146 _out << setw(20) << "unknown"
147 << setw(20) << "unknown"
148 << setw(20) << " " << "ANT # / TYPE" << endl;
149 _out.unsetf(ios::left);
150 _out << setw(14) << setprecision(4) << approxPos[0]
151 << setw(14) << setprecision(4) << approxPos[1]
152 << setw(14) << setprecision(4) << approxPos[2]
153 << " " << "APPROX POSITION XYZ" << endl;
154 _out << setw(14) << setprecision(4) << antennaNEU[0]
155 << setw(14) << setprecision(4) << antennaNEU[1]
156 << setw(14) << setprecision(4) << antennaNEU[2]
157 << " " << "ANTENNA: DELTA H/E/N" << endl;
158 _out << " 1 1 WAVELENGTH FACT L1/2" << endl;
159 _out << " 4 P1 P2 L1 L2 # / TYPES OF OBSERV" << endl;
160 _out << setw(6) << cti.year
161 << setw(6) << cti.month
162 << setw(6) << cti.day
163 << setw(6) << cti.hour
164 << setw(6) << cti.minute
165 << setw(13) << setprecision(7) << second
166 << " " << "TIME OF FIRST OBS" << endl;
167 _out << " END OF HEADER" << endl;
168 }
169
170 _headerWritten = true;
171}
172
173// Stores Observation into Internal Array
174////////////////////////////////////////////////////////////////////////////
175void bncRinex::deepCopy(const Observation* obs) {
176 Observation* newObs = new Observation();
177 memcpy(newObs, obs, sizeof(*obs));
178 _obs.push_back(newObs);
179}
180
181// Write One Epoch into the RINEX File
182////////////////////////////////////////////////////////////////////////////
183void bncRinex::dumpEpoch() {
184
185 // Easy Return
186 // -----------
187 if (_obs.isEmpty()) {
188 return;
189 }
190
191 // Time of Epoch
192 // -------------
193 struct converttimeinfo cti;
194 Observation* firstObs = *_obs.begin();
195 converttime(&cti, firstObs->GPSWeek, firstObs->GPSWeeks);
196
197 // Write RINEX Header
198 // ------------------
199 if (!_headerWritten) {
200 writeHeader(cti, cti.second + fmod(firstObs->sec, 1.0));
201 }
202
203 _out << setw(3) << cti.year%100
204 << setw(3) << cti.month
205 << setw(3) << cti.day
206 << setw(3) << cti.hour
207 << setw(3) << cti.minute
208 << setw(11) << setprecision(7)
209 << cti.second + fmod(firstObs->sec, 1.0)
210 << " " << 0 << setw(3) << _obs.size();
211
212 QListIterator<Observation*> it(_obs); int iSat = 0;
213 while (it.hasNext()) {
214 iSat++;
215 Observation* ob = it.next();
216 _out << " " << setw(2) << int(ob->SVPRN);
217 if (iSat == 12 && it.hasNext()) {
218 _out << endl << " ";
219 iSat = 0;
220 }
221 }
222 _out << endl;
223
224 static const double const_c = 299792458.0;
225 static const double const_freq1 = 1575420000.0;
226 static const double const_freq2 = 1227600000.0;
227 static const double const_lambda1 = const_c / const_freq1;
228 static const double const_lambda2 = const_c / const_freq2;
229
230 it.toFront();
231 while (it.hasNext()) {
232 Observation* ob = it.next();
233
234 char lli = ' ';
235 char snr = ' ';
236 _out << setw(14) << setprecision(3) << ob->C1 << lli << snr;
237 _out << setw(14) << setprecision(3) << ob->P2 << lli << snr;
238 _out << setw(14) << setprecision(3) << ob->L1 / const_lambda1 << lli << snr;
239 _out << setw(14) << setprecision(3) << ob->L2 / const_lambda2 << lli << snr;
240 _out << endl;
241
242 delete ob;
243 }
244
245 _out.flush();
246 _obs.clear();
247}
248
Note: See TracBrowser for help on using the repository browser.