source: ntrip/branches/BNC_LM/bncoutf.cpp@ 6462

Last change on this file since 6462 was 3261, checked in by mervart, 14 years ago
File size: 3.9 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
36 QFileInfo fileInfo(sklFileName);
37 _path = fileInfo.absolutePath() + QDir::separator();
38 _sklBaseName = fileInfo.baseName();
39 _extension = fileInfo.completeSuffix();
40
41 expandEnvVar(_path);
42 if (!_extension.isEmpty()) {
43 _extension = "." + _extension;
44 }
45
46 _append = Qt::CheckState(settings.value("rnxAppend").toInt()) == Qt::Checked;
47}
48
49// Destructor
50////////////////////////////////////////////////////////////////////////////
51bncoutf::~bncoutf() {
52 closeFile();
53}
54
55// Close the Old RINEX File
56////////////////////////////////////////////////////////////////////////////
57void bncoutf::closeFile() {
58 _out.close();
59}
60
61// Epoch String
62////////////////////////////////////////////////////////////////////////////
63QString bncoutf::epochStr(const QDateTime& datTim, const QString& intStr) {
64
65 QString epoStr;
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 }
76 else {
77 for (int limit = step; limit <= 60-step; limit += step) {
78 if (datTim.time().minute() < limit) {
79 epoStr += QString("%1").arg(limit-step, 2, 10, QChar('0'));
80 break;
81 }
82 }
83 }
84 }
85 else if (intStr == "1 hour") {
86 char ch = 'A' + datTim.time().hour();
87 epoStr = QString("_") + ch;
88 }
89 else {
90 epoStr = "";
91 }
92
93 return epoStr;
94}
95
96// File Name according to RINEX Standards
97////////////////////////////////////////////////////////////////////////////
98QString bncoutf::resolveFileName(int GPSweek, const QDateTime& datTim) {
99
100 int dayOfWeek = datTim.date().dayOfWeek();
101 if (dayOfWeek == 7) {
102 dayOfWeek = 0;
103 }
104 QString gpswd = QString("%1%2").arg(GPSweek).arg(dayOfWeek);
105 QString baseName = _sklBaseName; baseName.replace("${GPSWD}", gpswd);
106 QString epoStr = epochStr(datTim, _intr);
107
108 return _path + baseName + epoStr + _extension;
109}
110
111// Re-Open Output File
112////////////////////////////////////////////////////////////////////////////
113t_irc bncoutf::reopen(int GPSweek, double GPSweeks) {
114
115 if (_sampl != 0 && fmod(GPSweeks, _sampl) != 0.0) {
116 return failure;
117 }
118
119 QDateTime datTim = dateAndTimeFromGPSweek(GPSweek, GPSweeks);
120
121 QString newFileName = resolveFileName(GPSweek, datTim);
122
123 // Close the file
124 // --------------
125 if (newFileName != _fName) {
126 closeFile();
127 _headerWritten = false;
128 _fName = newFileName;
129 }
130
131 // Re-Open File, Write Header
132 // --------------------------
133 if (!_headerWritten) {
134 _out.setf(ios::showpoint | ios::fixed);
135 if (_append && QFile::exists(_fName)) {
136 _out.open(_fName.toAscii().data(), ios::out | ios::app);
137 }
138 else {
139 _out.open(_fName.toAscii().data());
140 writeHeader(datTim);
141 }
142 _headerWritten = true;
143 }
144
145 return success;
146}
147
148// Write String
149////////////////////////////////////////////////////////////////////////////
150t_irc bncoutf::write(int GPSweek, double GPSweeks, const QString& str) {
151 reopen(GPSweek, GPSweeks);
152 _out << str.toAscii().data();
153 _out.flush();
154 return success;
155}
Note: See TracBrowser for help on using the repository browser.