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

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