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

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

* empty log message *

File size: 4.1 KB
Line 
1
2/* -------------------------------------------------------------------------
3 * BKG NTRIP Server
4 * -------------------------------------------------------------------------
5 *
6 * Class: bnsoutf
7 *
8 * Purpose: Basis Class for File-Writers
9 *
10 * Author: L. Mervart
11 *
12 * Created: 25-Apr-2008
13 *
14 * Changes:
15 *
16 * -----------------------------------------------------------------------*/
17
18#include <iomanip>
19
20#include "bnsoutf.h"
21#include "bnsutils.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 _lastGPSweek = 0;
42 _lastGPSweeks = 0.0;
43}
44
45// Destructor
46////////////////////////////////////////////////////////////////////////////
47bnsoutf::~bnsoutf() {
48 closeFile();
49}
50
51// Close the Old RINEX File
52////////////////////////////////////////////////////////////////////////////
53void bnsoutf::closeFile() {
54 _out.close();
55}
56
57// Next File Epoch (static)
58////////////////////////////////////////////////////////////////////////////
59QString bnsoutf::nextEpochStr(const QDateTime& datTim,
60 const QString& intStr, QDateTime* nextEpoch) {
61
62 QString epoStr;
63
64 QTime nextTime;
65 QDate nextDate;
66
67 int indHlp = intStr.indexOf("min");
68
69 if ( indHlp != -1) {
70 int step = intStr.left(indHlp-1).toInt();
71 char ch = 'A' + datTim.time().hour();
72 epoStr = QString("_") + ch;
73 if (datTim.time().minute() >= 60-step) {
74 epoStr += QString("%1").arg(60-step, 2, 10, QChar('0'));
75 if (datTim.time().hour() < 23) {
76 nextTime.setHMS(datTim.time().hour() + 1 , 0, 0);
77 nextDate = datTim.date();
78 }
79 else {
80 nextTime.setHMS(0, 0, 0);
81 nextDate = datTim.date().addDays(1);
82 }
83 }
84 else {
85 for (int limit = step; limit <= 60-step; limit += step) {
86 if (datTim.time().minute() < limit) {
87 epoStr += QString("%1").arg(limit-step, 2, 10, QChar('0'));
88 nextTime.setHMS(datTim.time().hour(), limit, 0);
89 nextDate = datTim.date();
90 break;
91 }
92 }
93 }
94 }
95 else if (intStr == "1 hour") {
96 char ch = 'A' + datTim.time().hour();
97 epoStr = QString("_") + ch;
98 if (datTim.time().hour() < 23) {
99 nextTime.setHMS(datTim.time().hour() + 1 , 0, 0);
100 nextDate = datTim.date();
101 }
102 else {
103 nextTime.setHMS(0, 0, 0);
104 nextDate = datTim.date().addDays(1);
105 }
106 }
107 else {
108 epoStr = "";
109 nextTime.setHMS(0, 0, 0);
110 nextDate = datTim.date().addDays(1);
111 }
112
113 if (nextEpoch) {
114 *nextEpoch = QDateTime(nextDate, nextTime);
115 }
116
117 return epoStr;
118}
119
120// File Name according to RINEX Standards
121////////////////////////////////////////////////////////////////////////////
122void bnsoutf::resolveFileName(int GPSweek, const QDateTime& datTim) {
123
124 QString epoStr = nextEpochStr(datTim, _intr, &_nextCloseEpoch);
125
126 int dayOfWeek = datTim.date().dayOfWeek();
127 if (dayOfWeek == 7) {
128 dayOfWeek = 0;
129 }
130
131 _fName = (_prep
132 + QString("%1").arg(GPSweek)
133 + QString("%1").arg(dayOfWeek)
134 + epoStr
135 + _ext).toAscii();
136}
137
138// Write One Epoch
139////////////////////////////////////////////////////////////////////////////
140void bnsoutf::write(int GPSweek, double GPSweeks, const QString&,
141 const ColumnVector&) {
142
143 QDateTime datTim = dateAndTimeFromGPSweek(GPSweek, GPSweeks);
144
145 // Close the file
146 // --------------
147 if (_nextCloseEpoch.isValid() && datTim >= _nextCloseEpoch) {
148 closeFile();
149 _headerWritten = false;
150 }
151
152 // Write Header
153 // ------------
154 if (!_headerWritten) {
155 resolveFileName(GPSweek, datTim);
156 _out.open(_fName.data());
157 _out.setf(ios::showpoint | ios::fixed);
158 writeHeader(datTim);
159 _headerWritten = true;
160 }
161}
Note: See TracBrowser for help on using the repository browser.