[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 |
|
---|
| 24 | using namespace std;
|
---|
| 25 |
|
---|
| 26 | // Constructor
|
---|
| 27 | ////////////////////////////////////////////////////////////////////////////
|
---|
[3184] | 28 | bncoutf::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 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 54 | bncoutf::~bncoutf() {
|
---|
| 55 | closeFile();
|
---|
| 56 | }
|
---|
| 57 |
|
---|
| 58 | // Close the Old RINEX File
|
---|
| 59 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 60 | void bncoutf::closeFile() {
|
---|
| 61 | _out.close();
|
---|
| 62 | }
|
---|
| 63 |
|
---|
[3184] | 64 | // Epoch String
|
---|
[3174] | 65 | ////////////////////////////////////////////////////////////////////////////
|
---|
[3184] | 66 | QString 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] | 104 | QString bncoutf::resolveFileName(int GPSweek, const QDateTime& datTim) {
|
---|
[3174] | 105 |
|
---|
| 106 | int dayOfWeek = datTim.date().dayOfWeek();
|
---|
| 107 | if (dayOfWeek == 7) {
|
---|
| 108 | dayOfWeek = 0;
|
---|
| 109 | }
|
---|
[3191] | 110 | QString gpswd = QString("%1%2").arg(GPSweek).arg(dayOfWeek);
|
---|
[3184] | 111 | QString epoStr = epochStr(datTim, _intr);
|
---|
[5985] | 112 | QString baseName = _sklBaseName;
|
---|
| 113 | baseName.replace("${GPSWD}", gpswd);
|
---|
| 114 | baseName.replace("${DATE}", datTim.date().toString(Qt::ISODate));
|
---|
[3174] | 115 |
|
---|
[3184] | 116 | return _path + baseName + epoStr + _extension;
|
---|
[3174] | 117 | }
|
---|
| 118 |
|
---|
[3184] | 119 | // Re-Open Output File
|
---|
[3174] | 120 | ////////////////////////////////////////////////////////////////////////////
|
---|
[3184] | 121 | t_irc bncoutf::reopen(int GPSweek, double GPSweeks) {
|
---|
[3174] | 122 |
|
---|
| 123 | if (_sampl != 0 && fmod(GPSweeks, _sampl) != 0.0) {
|
---|
| 124 | return failure;
|
---|
| 125 | }
|
---|
| 126 |
|
---|
| 127 | QDateTime datTim = dateAndTimeFromGPSweek(GPSweek, GPSweeks);
|
---|
| 128 |
|
---|
[3184] | 129 | QString newFileName = resolveFileName(GPSweek, datTim);
|
---|
| 130 |
|
---|
[3174] | 131 | // Close the file
|
---|
| 132 | // --------------
|
---|
[3184] | 133 | if (newFileName != _fName) {
|
---|
[3174] | 134 | closeFile();
|
---|
| 135 | _headerWritten = false;
|
---|
[3184] | 136 | _fName = newFileName;
|
---|
[3174] | 137 | }
|
---|
| 138 |
|
---|
[3184] | 139 | // Re-Open File, Write Header
|
---|
| 140 | // --------------------------
|
---|
[3174] | 141 | if (!_headerWritten) {
|
---|
| 142 | _out.setf(ios::showpoint | ios::fixed);
|
---|
[3184] | 143 | if (_append && QFile::exists(_fName)) {
|
---|
| 144 | _out.open(_fName.toAscii().data(), ios::out | ios::app);
|
---|
[3174] | 145 | }
|
---|
| 146 | else {
|
---|
[3184] | 147 | _out.open(_fName.toAscii().data());
|
---|
[3174] | 148 | writeHeader(datTim);
|
---|
| 149 | }
|
---|
| 150 | _headerWritten = true;
|
---|
| 151 | }
|
---|
| 152 |
|
---|
| 153 | return success;
|
---|
| 154 | }
|
---|
[3184] | 155 |
|
---|
| 156 | // Write String
|
---|
| 157 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 158 | t_irc bncoutf::write(int GPSweek, double GPSweeks, const QString& str) {
|
---|
| 159 | reopen(GPSweek, GPSweeks);
|
---|
| 160 | _out << str.toAscii().data();
|
---|
| 161 | _out.flush();
|
---|
| 162 | return success;
|
---|
| 163 | }
|
---|