source: ntrip/trunk/BNS/bnsoutf.cpp@ 1370

Last change on this file since 1370 was 1057, checked in by mervart, 16 years ago

* empty log message *

File size: 4.4 KB
RevLine 
[850]1
2/* -------------------------------------------------------------------------
3 * BKG NTRIP Server
4 * -------------------------------------------------------------------------
5 *
6 * Class: bnsoutf
7 *
[851]8 * Purpose: Basis Class for File-Writers
[850]9 *
10 * Author: L. Mervart
11 *
12 * Created: 25-Apr-2008
13 *
14 * Changes:
15 *
16 * -----------------------------------------------------------------------*/
17
[854]18#include <math.h>
[850]19#include <iomanip>
20
21#include "bnsoutf.h"
22
23using namespace std;
24
25// Constructor
26////////////////////////////////////////////////////////////////////////////
27bnsoutf::bnsoutf(const QString& prep, const QString& ext, const QString& path,
28 const QString& intr, int sampl) {
29
30 _headerWritten = false;
31 _prep = prep;
32 _ext = ext;
33 _sampl = sampl;
34 _intr = intr;
35 _path = path;
36 expandEnvVar(_path);
37 if ( _path.length() > 0 && _path[_path.length()-1] != QDir::separator() ) {
38 _path += QDir::separator();
39 }
40}
41
42// Destructor
43////////////////////////////////////////////////////////////////////////////
44bnsoutf::~bnsoutf() {
45 closeFile();
46}
47
48// Close the Old RINEX File
49////////////////////////////////////////////////////////////////////////////
50void bnsoutf::closeFile() {
51 _out.close();
52}
53
54// Next File Epoch (static)
55////////////////////////////////////////////////////////////////////////////
56QString bnsoutf::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();
[851]69 epoStr = QString("_") + ch;
[850]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();
[851]94 epoStr = QString("_") + ch;
[850]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 {
[851]105 epoStr = "";
[850]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////////////////////////////////////////////////////////////////////////////
[851]119void bnsoutf::resolveFileName(int GPSweek, const QDateTime& datTim) {
[850]120
[851]121 QString epoStr = nextEpochStr(datTim, _intr, &_nextCloseEpoch);
[850]122
[851]123 int dayOfWeek = datTim.date().dayOfWeek();
124 if (dayOfWeek == 7) {
125 dayOfWeek = 0;
126 }
127
[1057]128 _fName = (_path + _prep
[851]129 + QString("%1").arg(GPSweek)
130 + QString("%1").arg(dayOfWeek)
131 + epoStr
[850]132 + _ext).toAscii();
133}
134
135// Write One Epoch
136////////////////////////////////////////////////////////////////////////////
[853]137t_irc bnsoutf::write(int GPSweek, double GPSweeks, const QString&,
138 const ColumnVector&) {
[850]139
[854]140 if (_sampl != 0 && fmod(GPSweeks, _sampl) != 0.0) {
141 return failure;
142 }
143
[850]144 QDateTime datTim = dateAndTimeFromGPSweek(GPSweek, GPSweeks);
145
146 // Close the file
147 // --------------
148 if (_nextCloseEpoch.isValid() && datTim >= _nextCloseEpoch) {
149 closeFile();
150 _headerWritten = false;
151 }
152
153 // Write Header
154 // ------------
155 if (!_headerWritten) {
[851]156 resolveFileName(GPSweek, datTim);
[850]157 _out.setf(ios::showpoint | ios::fixed);
[982]158 QSettings settings;
159 if (QFile::exists(_fName) &&
160 Qt::CheckState(settings.value("fileAppend").toInt()) == Qt::Checked) {
161 _out.open(_fName.data(), ios::out | ios::app);
162 }
163 else {
164 _out.open(_fName.data());
165 writeHeader(datTim);
166 }
[850]167 _headerWritten = true;
168 }
[853]169
170 return success;
[850]171}
Note: See TracBrowser for help on using the repository browser.