source: ntrip/trunk/BNC/src/bncoutf.cpp@ 6813

Last change on this file since 6813 was 6607, checked in by stuerze, 10 years ago

some gui preparation for sinex_tro file output

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