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

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

* empty log message *

File size: 4.0 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
22using namespace std;
23
24// Constructor
25////////////////////////////////////////////////////////////////////////////
26bnsoutf::bnsoutf(const QString& prep, const QString& ext, const QString& path,
27 const QString& intr, int sampl) {
28
29 _headerWritten = false;
30 _prep = prep;
31 _ext = ext;
32 _sampl = sampl;
33 _intr = intr;
34 _path = path;
35 expandEnvVar(_path);
36 if ( _path.length() > 0 && _path[_path.length()-1] != QDir::separator() ) {
37 _path += QDir::separator();
38 }
39}
40
41// Destructor
42////////////////////////////////////////////////////////////////////////////
43bnsoutf::~bnsoutf() {
44 closeFile();
45}
46
47// Close the Old RINEX File
48////////////////////////////////////////////////////////////////////////////
49void bnsoutf::closeFile() {
50 _out.close();
51}
52
53// Next File Epoch (static)
54////////////////////////////////////////////////////////////////////////////
55QString bnsoutf::nextEpochStr(const QDateTime& datTim,
56 const QString& intStr, QDateTime* nextEpoch) {
57
58 QString epoStr;
59
60 QTime nextTime;
61 QDate nextDate;
62
63 int indHlp = intStr.indexOf("min");
64
65 if ( indHlp != -1) {
66 int step = intStr.left(indHlp-1).toInt();
67 char ch = 'A' + datTim.time().hour();
68 epoStr = QString("_") + ch;
69 if (datTim.time().minute() >= 60-step) {
70 epoStr += QString("%1").arg(60-step, 2, 10, QChar('0'));
71 if (datTim.time().hour() < 23) {
72 nextTime.setHMS(datTim.time().hour() + 1 , 0, 0);
73 nextDate = datTim.date();
74 }
75 else {
76 nextTime.setHMS(0, 0, 0);
77 nextDate = datTim.date().addDays(1);
78 }
79 }
80 else {
81 for (int limit = step; limit <= 60-step; limit += step) {
82 if (datTim.time().minute() < limit) {
83 epoStr += QString("%1").arg(limit-step, 2, 10, QChar('0'));
84 nextTime.setHMS(datTim.time().hour(), limit, 0);
85 nextDate = datTim.date();
86 break;
87 }
88 }
89 }
90 }
91 else if (intStr == "1 hour") {
92 char ch = 'A' + datTim.time().hour();
93 epoStr = QString("_") + ch;
94 if (datTim.time().hour() < 23) {
95 nextTime.setHMS(datTim.time().hour() + 1 , 0, 0);
96 nextDate = datTim.date();
97 }
98 else {
99 nextTime.setHMS(0, 0, 0);
100 nextDate = datTim.date().addDays(1);
101 }
102 }
103 else {
104 epoStr = "";
105 nextTime.setHMS(0, 0, 0);
106 nextDate = datTim.date().addDays(1);
107 }
108
109 if (nextEpoch) {
110 *nextEpoch = QDateTime(nextDate, nextTime);
111 }
112
113 return epoStr;
114}
115
116// File Name according to RINEX Standards
117////////////////////////////////////////////////////////////////////////////
118void bnsoutf::resolveFileName(int GPSweek, const QDateTime& datTim) {
119
120 QString epoStr = nextEpochStr(datTim, _intr, &_nextCloseEpoch);
121
122 int dayOfWeek = datTim.date().dayOfWeek();
123 if (dayOfWeek == 7) {
124 dayOfWeek = 0;
125 }
126
127 _fName = (_prep
128 + QString("%1").arg(GPSweek)
129 + QString("%1").arg(dayOfWeek)
130 + epoStr
131 + _ext).toAscii();
132}
133
134// Write One Epoch
135////////////////////////////////////////////////////////////////////////////
136t_irc bnsoutf::write(int GPSweek, double GPSweeks, const QString&,
137 const ColumnVector&) {
138
139 QDateTime datTim = dateAndTimeFromGPSweek(GPSweek, GPSweeks);
140
141 // Close the file
142 // --------------
143 if (_nextCloseEpoch.isValid() && datTim >= _nextCloseEpoch) {
144 closeFile();
145 _headerWritten = false;
146 }
147
148 // Write Header
149 // ------------
150 if (!_headerWritten) {
151 resolveFileName(GPSweek, datTim);
152 _out.open(_fName.data());
153 _out.setf(ios::showpoint | ios::fixed);
154 writeHeader(datTim);
155 _headerWritten = true;
156 }
157
158 return success;
159}
Note: See TracBrowser for help on using the repository browser.