source: ntrip/trunk/BNC/src/bncsp3.cpp@ 6462

Last change on this file since 6462 was 6440, checked in by mervart, 10 years ago
File size: 6.2 KB
RevLine 
[3176]1
2/* -------------------------------------------------------------------------
3 * BKG NTRIP Server
4 * -------------------------------------------------------------------------
5 *
6 * Class: bncSP3
7 *
8 * Purpose: writes SP3 files
9 *
10 * Author: L. Mervart
11 *
12 * Created: 25-Apr-2008
13 *
14 * Changes:
15 *
16 * -----------------------------------------------------------------------*/
17
18#include <iomanip>
[6331]19#include <sstream>
[3176]20#include <math.h>
21
22#include "bncsp3.h"
23#include "bncutils.h"
24
25using namespace std;
26
27// Constructor
28////////////////////////////////////////////////////////////////////////////
[6331]29bncSP3::bncSP3(const QString& fileName) : bncoutf(QString(), QString(), 0) {
30 _inpOut = input;
31 _currEpoch = 0;
32 _prevEpoch = 0;
33
34 _stream.open(fileName.toAscii().data());
35 if (!_stream.good()) {
36 throw "t_sp3File: cannot open file " + fileName;
37 }
38
39 while (_stream.good()) {
40 getline(_stream, _lastLine);
41 if (_lastLine[0] == '*') {
42 break;
43 }
44 }
45}
46
47// Constructor
48////////////////////////////////////////////////////////////////////////////
[3184]49bncSP3::bncSP3(const QString& sklFileName, const QString& intr, int sampl)
50 : bncoutf(sklFileName, intr, sampl) {
[6331]51 _inpOut = output;
52 _currEpoch = 0;
53 _prevEpoch = 0;
[3176]54}
55
56// Destructor
57////////////////////////////////////////////////////////////////////////////
58bncSP3::~bncSP3() {
[6331]59 delete _currEpoch;
60 delete _prevEpoch;
[3176]61}
62
63// Write One Epoch
64////////////////////////////////////////////////////////////////////////////
65t_irc bncSP3::write(int GPSweek, double GPSweeks, const QString& prn,
[4991]66 const ColumnVector& xCoM, double sp3Clk) {
[3176]67
[3184]68 if (reopen(GPSweek, GPSweeks) == success) {
[3176]69
[4296]70 bncTime epoTime(GPSweek, GPSweeks);
71
72 if (epoTime != _lastEpoTime) {
73
74 // Check the sampling interval (print empty epochs)
75 // ------------------------------------------------
[4298]76 if (_lastEpoTime.valid() && _sampl > 0) {
[4296]77 for (bncTime ep = _lastEpoTime +_sampl; ep < epoTime; ep = ep +_sampl) {
[4297]78 _out << "* " << ep.datestr(' ') << ' ' << ep.timestr(8, ' ') << endl;
[4296]79 }
80 }
81
82 // Print the new epoch
83 // -------------------
[4297]84 _out << "* " << epoTime.datestr(' ') << ' ' << epoTime.timestr(8, ' ') << endl;
[4296]85
86 _lastEpoTime = epoTime;
[3176]87 }
[4296]88
[3176]89 _out << "P" << prn.toAscii().data()
[4991]90 << setw(14) << setprecision(6) << xCoM(1) / 1000.0
91 << setw(14) << setprecision(6) << xCoM(2) / 1000.0
92 << setw(14) << setprecision(6) << xCoM(3) / 1000.0
93 << setw(14) << setprecision(6) << sp3Clk * 1e6 << endl;
[3176]94
95 return success;
96 }
97 else {
98 return failure;
99 }
100}
101
102// Close File (write last line)
103////////////////////////////////////////////////////////////////////////////
104void bncSP3::closeFile() {
105 _out << "EOF" << endl;
106 bncoutf::closeFile();
107}
108
109// Write Header
110////////////////////////////////////////////////////////////////////////////
111void bncSP3::writeHeader(const QDateTime& datTim) {
112
113 int GPSWeek;
114 double GPSWeeks;
115 GPSweekFromDateAndTime(datTim, GPSWeek, GPSWeeks);
116
117 double sec = fmod(GPSWeeks, 60.0);
118
119 int mjd;
120 double dayfrac;
121 mjdFromDateAndTime(datTim, mjd, dayfrac);
[4381]122
[4382]123 int numEpo = _numSec;
124 if (_sampl > 0) {
125 numEpo /= _sampl;
126 }
[3176]127
128 _out << "#aP" << datTim.toString("yyyy MM dd hh mm").toAscii().data()
129 << setw(12) << setprecision(8) << sec
[4381]130 << " " << setw(7) << numEpo << " ORBIT IGS08 HLM IGS" << endl;
[3176]131
132 _out << "## "
133 << setw(4) << GPSWeek
134 << setw(16) << setprecision(8) << GPSWeeks
135 << setw(15) << setprecision(8) << double(_sampl)
136 << setw(6) << mjd
137 << setw(16) << setprecision(13) << dayfrac << endl;
138
[3714]139 _out << "+ 56 G01G02G03G04G05G06G07G08G09G10G11G12G13G14G15G16G17\n"
140 << "+ G18G19G20G21G22G23G24G25G26G27G28G29G30G31G32R01R02\n"
141 << "+ R03R04R05R06R07R08R09R10R11R12R13R14R15R16R17R18R19\n"
142 << "+ R20R21R22R23R24 0 0 0 0 0 0 0 0 0 0 0 0\n"
[3176]143 << "+ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n"
144 << "++ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n"
145 << "++ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n"
146 << "++ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n"
147 << "++ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n"
148 << "++ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n"
149 << "%c cc cc ccc ccc cccc cccc cccc cccc ccccc ccccc ccccc ccccc\n"
150 << "%c cc cc ccc ccc cccc cccc cccc cccc ccccc ccccc ccccc ccccc\n"
151 << "%f 0.0000000 0.000000000 0.00000000000 0.000000000000000\n"
152 << "%f 0.0000000 0.000000000 0.00000000000 0.000000000000000\n"
153 << "%i 0 0 0 0 0 0 0 0 0\n"
154 << "%i 0 0 0 0 0 0 0 0 0\n"
155 << "/* \n"
156 << "/* \n"
157 << "/* \n"
158 << "/* \n";
159}
160
[6331]161// Read Next Epoch
162////////////////////////////////////////////////////////////////////////////
163const bncSP3::t_sp3Epoch* bncSP3::nextEpoch() {
164
165 delete _prevEpoch; _prevEpoch = _currEpoch; _currEpoch = 0;
166
[6354]167 if (_lastLine[0] == '*') {
168 _currEpoch = new t_sp3Epoch();
169 istringstream in(_lastLine.substr(1).c_str());
170 int YY, MM, DD, hh, mm;
171 double ss;
172 in >> YY >> MM >> DD >> hh >> mm >> ss;
173 _currEpoch->_tt.set(YY, MM, DD, hh, mm, ss);
174 }
175
[6440]176 while (_stream.good()) {
[6331]177 getline(_stream, _lastLine);
178 if (_stream.eof() || _lastLine.find("EOF") == 0) {
[6440]179 _stream.close();
[6331]180 break;
181 }
182 if (_lastLine[0] == '*') {
183 break;
184 }
185
186 t_sp3Sat* sp3Sat = new t_sp3Sat();
187 istringstream in(_lastLine.substr(1).c_str());
188 in >> sp3Sat->_prn >> sp3Sat->_xyz(1) >> sp3Sat->_xyz(2) >> sp3Sat->_xyz(3) >> sp3Sat->_clk;
189
190 sp3Sat->_xyz *= 1.e3;
[6351]191 if (sp3Sat->_clk == 999999.999999) {
192 sp3Sat->_clkValid = false;
193 sp3Sat->_clk = 0.0;
194 }
195 else {
196 sp3Sat->_clkValid = true;
197 sp3Sat->_clk *= t_CST::c * 1.e-6;
198 }
[6331]199
200 _currEpoch->_sp3Sat.push_back(sp3Sat);
201 }
202
203 return _currEpoch;
204}
Note: See TracBrowser for help on using the repository browser.