source: ntrip/branches/BNC_2.11.0/src/bncoutf.cpp@ 10554

Last change on this file since 10554 was 4380, checked in by mervart, 12 years ago
File size: 4.0 KB
Line 
1
2/* -------------------------------------------------------------------------
3 * BKG NTRIP Server
4 * -------------------------------------------------------------------------
5 *
6 * Class: bncoutf
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 <math.h>
19#include <iomanip>
20
21#include "bncoutf.h"
22#include "bncsettings.h"
23
24using namespace std;
25
26// Constructor
27////////////////////////////////////////////////////////////////////////////
28bncoutf::bncoutf(const QString& sklFileName, const QString& intr, int sampl) {
29
30 bncSettings settings;
31
32 _headerWritten = false;
33 _sampl = sampl;
34 _intr = intr;
35 _numSec = 0;
36
37 QFileInfo fileInfo(sklFileName);
38 _path = fileInfo.absolutePath() + QDir::separator();
39 _sklBaseName = fileInfo.baseName();
40 _extension = fileInfo.completeSuffix();
41
42 expandEnvVar(_path);
43 if (!_extension.isEmpty()) {
44 _extension = "." + _extension;
45 }
46
47 _append = Qt::CheckState(settings.value("rnxAppend").toInt()) == Qt::Checked;
48}
49
50// Destructor
51////////////////////////////////////////////////////////////////////////////
52bncoutf::~bncoutf() {
53 closeFile();
54}
55
56// Close the Old RINEX File
57////////////////////////////////////////////////////////////////////////////
58void bncoutf::closeFile() {
59 _out.close();
60}
61
62// Epoch String
63////////////////////////////////////////////////////////////////////////////
64QString bncoutf::epochStr(const QDateTime& datTim, const QString& intStr) {
65
66 QString epoStr;
67
68 int indHlp = intStr.indexOf("min");
69
70 if ( indHlp != -1) {
71 int step = intStr.left(indHlp-1).toInt();
72 char ch = 'A' + datTim.time().hour();
73 epoStr = QString("_") + ch;
74 if (datTim.time().minute() >= 60-step) {
75 epoStr += QString("%1").arg(60-step, 2, 10, QChar('0'));
76 }
77 else {
78 for (int limit = step; limit <= 60-step; limit += step) {
79 if (datTim.time().minute() < limit) {
80 epoStr += QString("%1").arg(limit-step, 2, 10, QChar('0'));
81 break;
82 }
83 }
84 }
85 _numSec = 60 * step;
86 }
87 else if (intStr == "1 hour") {
88 char ch = 'A' + datTim.time().hour();
89 epoStr = QString("_") + ch;
90 _numSec = 3600;
91 }
92 else {
93 epoStr = "";
94 _numSec = 86400;
95 }
96
97 return epoStr;
98}
99
100// File Name according to RINEX Standards
101////////////////////////////////////////////////////////////////////////////
102QString bncoutf::resolveFileName(int GPSweek, const QDateTime& datTim) {
103
104 int dayOfWeek = datTim.date().dayOfWeek();
105 if (dayOfWeek == 7) {
106 dayOfWeek = 0;
107 }
108 QString gpswd = QString("%1%2").arg(GPSweek).arg(dayOfWeek);
109 QString baseName = _sklBaseName; baseName.replace("${GPSWD}", gpswd);
110 QString epoStr = epochStr(datTim, _intr);
111
112 return _path + baseName + epoStr + _extension;
113}
114
115// Re-Open Output File
116////////////////////////////////////////////////////////////////////////////
117t_irc bncoutf::reopen(int GPSweek, double GPSweeks) {
118
119 if (_sampl != 0 && fmod(GPSweeks, _sampl) != 0.0) {
120 return failure;
121 }
122
123 QDateTime datTim = dateAndTimeFromGPSweek(GPSweek, GPSweeks);
124
125 QString newFileName = resolveFileName(GPSweek, datTim);
126
127 // Close the file
128 // --------------
129 if (newFileName != _fName) {
130 closeFile();
131 _headerWritten = false;
132 _fName = newFileName;
133 }
134
135 // Re-Open File, Write Header
136 // --------------------------
137 if (!_headerWritten) {
138 _out.setf(ios::showpoint | ios::fixed);
139 if (_append && QFile::exists(_fName)) {
140 _out.open(_fName.toAscii().data(), ios::out | ios::app);
141 }
142 else {
143 _out.open(_fName.toAscii().data());
144 writeHeader(datTim);
145 }
146 _headerWritten = true;
147 }
148
149 return success;
150}
151
152// Write String
153////////////////////////////////////////////////////////////////////////////
154t_irc bncoutf::write(int GPSweek, double GPSweeks, const QString& str) {
155 reopen(GPSweek, GPSweeks);
156 _out << str.toAscii().data();
157 _out.flush();
158 return success;
159}
Note: See TracBrowser for help on using the repository browser.