[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 |
|
---|
| 37 | QFileInfo fileInfo(sklFileName);
|
---|
| 38 | _path = fileInfo.absolutePath() + QDir::separator();
|
---|
| 39 | _sklBaseName = fileInfo.baseName();
|
---|
| 40 | _extension = fileInfo.completeSuffix();
|
---|
| 41 |
|
---|
[3174] | 42 | expandEnvVar(_path);
|
---|
[3184] | 43 | if (!_extension.isEmpty()) {
|
---|
| 44 | _extension = "." + _extension;
|
---|
[3174] | 45 | }
|
---|
[3184] | 46 |
|
---|
| 47 | _append = Qt::CheckState(settings.value("rnxAppend").toInt()) == Qt::Checked;
|
---|
[3174] | 48 | }
|
---|
| 49 |
|
---|
| 50 | // Destructor
|
---|
| 51 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 52 | bncoutf::~bncoutf() {
|
---|
| 53 | closeFile();
|
---|
| 54 | }
|
---|
| 55 |
|
---|
| 56 | // Close the Old RINEX File
|
---|
| 57 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 58 | void bncoutf::closeFile() {
|
---|
| 59 | _out.close();
|
---|
| 60 | }
|
---|
| 61 |
|
---|
[3184] | 62 | // Epoch String
|
---|
[3174] | 63 | ////////////////////////////////////////////////////////////////////////////
|
---|
[3184] | 64 | QString bncoutf::epochStr(const QDateTime& datTim, const QString& intStr) {
|
---|
[3174] | 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 | }
|
---|
[4380] | 85 | _numSec = 60 * step;
|
---|
[3174] | 86 | }
|
---|
| 87 | else if (intStr == "1 hour") {
|
---|
| 88 | char ch = 'A' + datTim.time().hour();
|
---|
| 89 | epoStr = QString("_") + ch;
|
---|
[4380] | 90 | _numSec = 3600;
|
---|
[3174] | 91 | }
|
---|
| 92 | else {
|
---|
| 93 | epoStr = "";
|
---|
[4380] | 94 | _numSec = 86400;
|
---|
[3174] | 95 | }
|
---|
| 96 |
|
---|
| 97 | return epoStr;
|
---|
| 98 | }
|
---|
| 99 |
|
---|
| 100 | // File Name according to RINEX Standards
|
---|
| 101 | ////////////////////////////////////////////////////////////////////////////
|
---|
[3184] | 102 | QString bncoutf::resolveFileName(int GPSweek, const QDateTime& datTim) {
|
---|
[3174] | 103 |
|
---|
| 104 | int dayOfWeek = datTim.date().dayOfWeek();
|
---|
| 105 | if (dayOfWeek == 7) {
|
---|
| 106 | dayOfWeek = 0;
|
---|
| 107 | }
|
---|
[3191] | 108 | QString gpswd = QString("%1%2").arg(GPSweek).arg(dayOfWeek);
|
---|
[3184] | 109 | QString epoStr = epochStr(datTim, _intr);
|
---|
[5985] | 110 | QString baseName = _sklBaseName;
|
---|
| 111 | baseName.replace("${GPSWD}", gpswd);
|
---|
| 112 | baseName.replace("${DATE}", datTim.date().toString(Qt::ISODate));
|
---|
[3174] | 113 |
|
---|
[3184] | 114 | return _path + baseName + epoStr + _extension;
|
---|
[3174] | 115 | }
|
---|
| 116 |
|
---|
[3184] | 117 | // Re-Open Output File
|
---|
[3174] | 118 | ////////////////////////////////////////////////////////////////////////////
|
---|
[3184] | 119 | t_irc bncoutf::reopen(int GPSweek, double GPSweeks) {
|
---|
[3174] | 120 |
|
---|
| 121 | if (_sampl != 0 && fmod(GPSweeks, _sampl) != 0.0) {
|
---|
| 122 | return failure;
|
---|
| 123 | }
|
---|
| 124 |
|
---|
| 125 | QDateTime datTim = dateAndTimeFromGPSweek(GPSweek, GPSweeks);
|
---|
| 126 |
|
---|
[3184] | 127 | QString newFileName = resolveFileName(GPSweek, datTim);
|
---|
| 128 |
|
---|
[3174] | 129 | // Close the file
|
---|
| 130 | // --------------
|
---|
[3184] | 131 | if (newFileName != _fName) {
|
---|
[3174] | 132 | closeFile();
|
---|
| 133 | _headerWritten = false;
|
---|
[3184] | 134 | _fName = newFileName;
|
---|
[3174] | 135 | }
|
---|
| 136 |
|
---|
[3184] | 137 | // Re-Open File, Write Header
|
---|
| 138 | // --------------------------
|
---|
[3174] | 139 | if (!_headerWritten) {
|
---|
| 140 | _out.setf(ios::showpoint | ios::fixed);
|
---|
[3184] | 141 | if (_append && QFile::exists(_fName)) {
|
---|
| 142 | _out.open(_fName.toAscii().data(), ios::out | ios::app);
|
---|
[3174] | 143 | }
|
---|
| 144 | else {
|
---|
[3184] | 145 | _out.open(_fName.toAscii().data());
|
---|
[3174] | 146 | writeHeader(datTim);
|
---|
| 147 | }
|
---|
| 148 | _headerWritten = true;
|
---|
| 149 | }
|
---|
| 150 |
|
---|
| 151 | return success;
|
---|
| 152 | }
|
---|
[3184] | 153 |
|
---|
| 154 | // Write String
|
---|
| 155 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 156 | t_irc bncoutf::write(int GPSweek, double GPSweeks, const QString& str) {
|
---|
| 157 | reopen(GPSweek, GPSweeks);
|
---|
| 158 | _out << str.toAscii().data();
|
---|
| 159 | _out.flush();
|
---|
| 160 | return success;
|
---|
| 161 | }
|
---|