source: ntrip/trunk/BNS/bnssp3.cpp@ 849

Last change on this file since 849 was 849, checked in by mervart, 14 years ago

* empty log message *

File size: 4.6 KB
Line 
1
2/* -------------------------------------------------------------------------
3 * BKG NTRIP Server
4 * -------------------------------------------------------------------------
5 *
6 * Class: bnsSP3
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>
19
20#include "bnssp3.h"
21#include "bnsutils.h"
22
23using namespace std;
24
25// Constructor
26////////////////////////////////////////////////////////////////////////////
27bnsSP3::bnsSP3() {
28 QSettings settings;
29
30 _headerWritten = false;
31 _ID4 = "BNS_";
32 _ext = ".SP3";
33 _samplingRate = settings.value("sp3Sampl").toInt();
34 _intr = settings.value("rnxIntr").toString();
35 _path = settings.value("rnxPath").toString();
36 expandEnvVar(_path);
37 if ( _path.length() > 0 && _path[_path.length()-1] != QDir::separator() ) {
38 _path += QDir::separator();
39 }
40}
41
42// Destructor
43////////////////////////////////////////////////////////////////////////////
44bnsSP3::~bnsSP3() {
45 _out.close();
46}
47
48// Close the Old RINEX File
49////////////////////////////////////////////////////////////////////////////
50void bnsSP3::closeFile() {
51 _out.close();
52}
53
54// Next File Epoch (static)
55////////////////////////////////////////////////////////////////////////////
56QString bnsSP3::nextEpochStr(const QDateTime& datTim,
57 const QString& intStr, QDateTime* nextEpoch) {
58
59 QString epoStr;
60
61 QTime nextTime;
62 QDate nextDate;
63
64 int indHlp = intStr.indexOf("min");
65
66 if ( indHlp != -1) {
67 int step = intStr.left(indHlp-1).toInt();
68 char ch = 'A' + datTim.time().hour();
69 epoStr = ch;
70 if (datTim.time().minute() >= 60-step) {
71 epoStr += QString("%1").arg(60-step, 2, 10, QChar('0'));
72 if (datTim.time().hour() < 23) {
73 nextTime.setHMS(datTim.time().hour() + 1 , 0, 0);
74 nextDate = datTim.date();
75 }
76 else {
77 nextTime.setHMS(0, 0, 0);
78 nextDate = datTim.date().addDays(1);
79 }
80 }
81 else {
82 for (int limit = step; limit <= 60-step; limit += step) {
83 if (datTim.time().minute() < limit) {
84 epoStr += QString("%1").arg(limit-step, 2, 10, QChar('0'));
85 nextTime.setHMS(datTim.time().hour(), limit, 0);
86 nextDate = datTim.date();
87 break;
88 }
89 }
90 }
91 }
92 else if (intStr == "1 hour") {
93 char ch = 'A' + datTim.time().hour();
94 epoStr = ch;
95 if (datTim.time().hour() < 23) {
96 nextTime.setHMS(datTim.time().hour() + 1 , 0, 0);
97 nextDate = datTim.date();
98 }
99 else {
100 nextTime.setHMS(0, 0, 0);
101 nextDate = datTim.date().addDays(1);
102 }
103 }
104 else {
105 epoStr = "0";
106 nextTime.setHMS(0, 0, 0);
107 nextDate = datTim.date().addDays(1);
108 }
109
110 if (nextEpoch) {
111 *nextEpoch = QDateTime(nextDate, nextTime);
112 }
113
114 return epoStr;
115}
116
117// File Name according to RINEX Standards
118////////////////////////////////////////////////////////////////////////////
119void bnsSP3::resolveFileName(const QDateTime& datTim) {
120
121 QString hlpStr = nextEpochStr(datTim, _intr, &_nextCloseEpoch);
122
123 _fName = (_ID4
124 + QString("%1").arg(datTim.date().dayOfYear(), 3, 10, QChar('0'))
125 + hlpStr
126 + _ext).toAscii();
127}
128
129// Write Header
130////////////////////////////////////////////////////////////////////////////
131void bnsSP3::writeHeader(const QDateTime& datTim) {
132
133 // Open the Output File
134 // --------------------
135 resolveFileName(datTim);
136
137 _out.open(_fName.data());
138 _out.setf(ios::showpoint | ios::fixed);
139
140 _out << "THIS IS A DUMMY HEADER" << endl;
141
142 _headerWritten = true;
143}
144
145// Write One Epoch
146////////////////////////////////////////////////////////////////////////////
147void bnsSP3::write(int GPSweek, double GPSweeks, const QString& prn,
148 const ColumnVector& xx) {
149
150 QDateTime datTim = dateAndTimeFromGPSweek(GPSweek, GPSweeks);
151
152 // Close the file
153 // --------------
154 if (_nextCloseEpoch.isValid() && datTim >= _nextCloseEpoch) {
155 closeFile();
156 _headerWritten = false;
157 }
158
159 // Write Header
160 // ------------
161 if (!_headerWritten) {
162 writeHeader(datTim);
163 }
164
165 int year, month, day, hour, min;
166 double sec;
167
168 _out << "* " << setw(4) << year
169 << setw(3) << month
170 << setw(3) << day
171 << setw(3) << hour
172 << setw(3) << min
173 << setw(12) << setprecision(8) << sec << endl;
174 _out << "P" << prn.toAscii().data()
175 << setw(14) << setprecision(6) << xx(1) / 1000.0
176 << setw(14) << setprecision(6) << xx(2) / 1000.0
177 << setw(14) << setprecision(6) << xx(3) / 1000.0
178 << " 999999.999999" << endl;
179}
Note: See TracBrowser for help on using the repository browser.