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

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

* empty log message *

File size: 7.8 KB
RevLine 
[73]1
2/* -------------------------------------------------------------------------
3 * Bernese 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
[82]18#include <QSettings>
19#include <QDir>
20#include <QDate>
21#include <QFile>
22#include <QTextStream>
[75]23#include <iomanip>
24
[73]25#include "bncrinex.h"
[82]26#include "bncutils.h"
[75]27#include "RTCM3/rtcm3torinex.h"
28
29using namespace std;
30
[73]31// Constructor
32////////////////////////////////////////////////////////////////////////////
33bncRinex::bncRinex(const char* StatID) {
[77]34 _statID = StatID;
35 _headerWritten = false;
[82]36 readSkeleton();
[73]37}
38
39// Destructor
40////////////////////////////////////////////////////////////////////////////
41bncRinex::~bncRinex() {
[77]42 _out.close();
[73]43}
44
[82]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
[77]97// Write RINEX Header
98////////////////////////////////////////////////////////////////////////////
[78]99void bncRinex::writeHeader(struct converttimeinfo& cti, double second) {
[77]100
101 // Open the Output File
102 // --------------------
[82]103 resolveFileName(cti);
104 _out.open(_fName.data());
[85]105 _out.setf(ios::showpoint | ios::fixed);
[77]106
[82]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 }
[78]131
[82]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;
[86]140 _out.setf(ios::left);
[82]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;
[86]149 _out.unsetf(ios::left);
[82]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 }
[78]169
[77]170 _headerWritten = true;
171}
172
[73]173// Stores Observation into Internal Array
174////////////////////////////////////////////////////////////////////////////
175void bncRinex::deepCopy(const Observation* obs) {
[74]176 Observation* newObs = new Observation();
177 memcpy(newObs, obs, sizeof(*obs));
178 _obs.push_back(newObs);
[73]179}
180
181// Write One Epoch into the RINEX File
182////////////////////////////////////////////////////////////////////////////
183void bncRinex::dumpEpoch() {
184
[75]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
[78]197 // Write RINEX Header
198 // ------------------
199 if (!_headerWritten) {
200 writeHeader(cti, cti.second + fmod(firstObs->sec, 1.0));
201 }
202
[77]203 _out << setw(3) << cti.year%100
[75]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;
[74]213 while (it.hasNext()) {
[75]214 iSat++;
215 Observation* ob = it.next();
[77]216 _out << " " << setw(2) << int(ob->SVPRN);
[75]217 if (iSat == 12 && it.hasNext()) {
[77]218 _out << endl << " ";
[75]219 iSat = 0;
220 }
[74]221 }
[77]222 _out << endl;
[75]223
[79]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
[75]230 it.toFront();
231 while (it.hasNext()) {
232 Observation* ob = it.next();
[77]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;
[79]238 _out << setw(14) << setprecision(3) << ob->L1 / const_lambda1 << lli << snr;
239 _out << setw(14) << setprecision(3) << ob->L2 / const_lambda2 << lli << snr;
[77]240 _out << endl;
241
[75]242 delete ob;
243 }
244
[77]245 _out.flush();
[74]246 _obs.clear();
[73]247}
248
Note: See TracBrowser for help on using the repository browser.